Solved

What am I missing?

Posted on 2008-10-15
2
145 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
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Passing list of object to Oracle Database Procedure 3 60
Systems talking to each other 5 125
print map entry 34 55
eclipse apache tomcat admin console 39 46
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

910 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now