Solved

What am I missing?

Posted on 2008-10-15
2
148 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 51
Java Restore security prompts not working 10 53
SequenceInputStream example 3 19
printf performancy 11 67
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

809 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