Solved

What am I missing?

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

744 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

13 Experts available now in Live!

Get 1:1 Help Now