Solved

What am I missing?

Posted on 2008-10-15
2
151 Views
Last Modified: 2013-11-23
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
Comment
Question by:flo_the_lil_minx
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 13

Accepted Solution

by:
marchent earned 500 total points
ID: 22722346
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
 
LVL 1

Author Closing Comment

by:flo_the_lil_minx
ID: 31506345
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
This video teaches viewers about errors in exception handling.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question