• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 157
  • Last Modified:

What am I missing?

What am I missing here?

The idea is to get it to output a particular message depending on the type of letter it is.  So far if I type 'bill' it tells me to pay it but anything else and it goes straight to the last else and types it can't be recognised, even if I type personal, circular or postcard

Thanks

Flo
// Post
 
import java.util.*;
 
public class Post
 
{
 
  public static void main (String[]args)
 
  {
    //create scanner from keyboard
    
    Scanner myKeyboard = new Scanner (System.in);
    
    //prompt for letter type
    
    System.out.print("Please enter the type of letter you have recieved ");
    String type = myKeyboard.nextLine();
    
    //Determine and display what is to be done with the item
    
    if (type.equals("bill"))
    
    {
      System.out.print("This needs to be paid");
    }
    else if (type.equals("circular"))
    {
      System.out.print("This should be thrown away");
    }
    else if (type.equals("postcard"))
    {
      System.out.print("Put this on the wall");
    }
    else if (type.equals("personal"))
    {
      System.out.print("You need to read and reply to this letter");
    }
    else
    {
      System.out.print("I don't recognise that type of letter");
    }
   }
  }

Open in new window

0
flo_the_lil_minx
Asked:
flo_the_lil_minx
1 Solution
 
marchentCommented:
Your code is working perfectly. May be you are mixing with upper/lower cases letter. You can use equalsIgnoreCase() instead of equals() with variable type to overcome the case sensitivity.
0
 
flo_the_lil_minxAuthor Commented:
Or maybe I need my eyes testing, I could swear it wasn't working but you're right, it is!

Thanks for looking though, Flo
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now