Tuesday, February 18, 2014

Write a program to input the type of letter received as a string (either "bill", "circular", "postcard" or "letter") and output what to do with it as follows:

Java Program

Write a program to input the type of letter received as a string (either "bill", "circular", 
"postcard" or "letter") and output what to do with it as follows: 
? bills must be paid 
? circulars are thrown away 
? postcards are put on the wall 
? personal letters are read and have replies written for them 
 
The program should also output an error message if the letter type is not recognized. 

=====================================================

import java.util.*; public class LetterHandler public static void main(String[]args) Scanner s = new Scanner(System.in); System.out.print ("Enter the letter type: "); String type = s.nextLine(); processLetter(type); private void processLetter(String input) if (input.equalsIgnoreCase("bill")) System.out.println("Bills must be paid."); else if (input.equalsIgnoreCase("circular")) System.out.println("Circulars are thrown away."); else if (input.equalsIgnoreCase("postcard")) System.out.println("Postcards are put on the wall."); else if (input.equalsIgnoreCase("letter")) System.out.println("Personal letters are read and have replies written for them."); else System.out.println ("Not recognized."); }

Please contact for tutoring on InstaEDU.

No comments:

Post a Comment