Homework 3 Solution 2 - Homework 3 Solution 2

Homework 3 solution 2

This preview shows page 1 out of 12 pages.

Unformatted text preview: Raymundo Mejia Homework #3 1). Sales.java The program was succesfully compiled and run. import java.util.Scanner; public class Sales { //calculate sales for 5 products public static void main(String args){ //create scanner for input Scanner input = new Scanner(System.in); //initialize variable for products sold double product1 = 0; double product2 = 0; double product3 = 0; double product4 = 0; double product5 = 0; int quantity; //to hold quantity of product sold //prices for each product double prodprice1 = 10.50; double prodprice2 = 11.50; double prodprice3 = 12.50; double prodprice4 = 14.00; double prodprice5 = 16.00; boolean more = true; //while loop while(more){ //ask user to input product number System.out.print("\nProduct1\nProduct2\nProduct3\nProduct4\n" + "Product5\n\nEnter the product # u wish to Calculate.(1­5) . Enter (0) to finish."); int prodNum = input.nextInt(); while (prodNum < 0 || prodNum > 5) System.out.println("Error . Please enter a valid option. (1­5).(0) to finish \n"); //boolean to get out of while loop if(prodNum == 0) more = false; else{ //prompt user for number of quantity System.out.println("What quantity of product was sold? "); quantity = input.nextInt(); //swtich to calculate each result switch(prodNum) { case 1: product1 += (quantity * prodprice1); break; case...
View Full Document

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture