CIS 160 - Selection Assignment

Objectives

  • Use Java selection statments to implement solutions to programmming problems
  • Format output to match requirements
  • Get user input from the command line

Overview

Note: Write a Java program for each of the programming projects listed below. The source code listings for these programs, and all others in this course, must include comments at the beginning of the source code which contain your name, the course, the date, and the assignment number. Submit your .java source files in Desire2Learn when you are done. It is considered cheating to copy work. Problems may be discussed, but not copied.

Program #1

Write a program that will calculate discounts. The program should ask the user for three bits of information: item ID, price, and quantity. The program should then print out a bill. The first line should be a subtotal (quantity multiplied by price), the second line should be the discount (no discount if quantity is less than 144, 10% of subtotal if quantity is 144 to 999, and 20% of subtotal if quantity is 1000 or more. Use the printf method to format the output. Formatting output will be discussed in class and will appear in at least one demonstration program.

Note: Errors are often made at the boundaries, such as having no discount for exactly 144 or exactly 999 items. Test your program.

Sample runs for program #1

Sample run #1

This program will calculate volume discounts Enter the item ID: 56RT Enter the price: 34.57 Enter the quantity: 3 Subtotal: 103.71 Discount: 0.00 ------- Total: 103.71

Sample run #2

This program will calculate volume discounts Enter the item ID: gtr4 Enter the price: 67.54 Enter the quantity: 144 Subtotal: 9725.76 Discount: 972.58 ------- Total: 8753.18

Sample run #3

This program will calculate volume discounts Enter the item ID: TM75X Enter the price: .57 Enter the quantity: 1500 Subtotal: 855.00 Discount: 171.00 ------- Total: 684.00

Program #2

Your job is to create a menu for a computerized terminal in a new "cyber-vegetarian" restaurant. Your program should display a menu of mouth-watering choices. When the user selects a choice, a custom message should be printed depending upon which choice the user made. Use a switch statement to choose which message should be displayed. The listing below shows one sample run of the program. After the sample run is a listing of all six custom messages.

Sample run for program #2

Please choose the item you would like for lunch 1. Cheese Pizza 2. Gardenburger 3. Vegetable Fajitas 4. Provolone, Lettuce, and Tomato Sandwich 5. Spaghetti Your choice (1-5): 1 The pizza is an excellent choice. All six custom messages: The pizza is an excellent choice. Fries are available for just $2.00! The fajitas will be served sizzling hot. Our PLT is the ultimate summer snack. Our spaghetti bowl is bottomless (all you can eat). You chose an invalid number

Rubric

  • Program #1 is worth 20 points:
    • 15 points for correct operation and I/O that matches the sample
    • 5 points for proper documentation comments and correctly following coding conventions (indentation, naming rules, NO tabs, etc.)
  • Program #2 is worth 20 points:
    • 15 points for having a correctly working program
    • 5 points for proper documentation comments and for correctly following coding conventions (indentation, naming rules, NO tabs, etc.)