Solved

What am I missing?

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

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

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
servlet example 17 58
jboss 7.1 start up error 1 58
going to wrong jsp page 2 46
Fast way to search item into Java Array (Rhino compatible) 2 36
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
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…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

680 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