Here is my code in Java: import java.util.Scanner; import java.util.HashMap; public class Inventory { /** This class demonstrates the inventory */ //Declarations Of inventory static final int LightBulb60W = 1; static final int LightBulb100W = 2; static final int BoltM5 = 3; static final int BoltM8 = 4; static final int Hose25 = 5; static final int Hose50 = 6; public static void main (String [] args) { //Scanner Object @SuppressWarnings("resource") Scanner keyboard = new Scanner(System.in); //Variables int month; int day; int year; double units; double cost = 0; //Declarations int total; HashMap productMap = new HashMap<>(); productMap.put(1,"Light Bulb 60W"); productMap.put(2,"Light Bulb 100W"); productMap.put(3,"Bolt M5"); productMap.put(4,"Bolt M8"); productMap.put(5,"Hose 25 feet"); productMap.put(6,"Hose 50 feet 60W"); while(true){ //Prints out inventory System.out.println("The Inventory: "); System.out.println("1 Light Bulb 60W 3 dollars 0 cents X"); System.out.println("2 Light Bulb 100W 5 dollars 99 cents X"); System.out.println("3 Bolt M5 0 dollars 15 cents Y"); System.out.println("4 Bolt M8 0 dollars 25 cents Y"); System.out.println("5 Hose 25 feet 10 dollars 0 cents Z"); System.out.println("6 Hose 50 feet 15 dollars 0 cents Z\n"); //Prints out desirable item number System.out.print("Which item number from the list do you desire?\n"); System.out.print("1, 2, 3, 4, 5 or 6?\n"); total = keyboard.nextInt(); System.out.print("Your choice: " + total + "\n"); // Units System.out.print("How many units do you desire?\n"); units = keyboard.nextInt(); System.out.print("Number of units: "); System.out.print("When do you plan your purchase?\n"); System.out.print("Month of purchase (mm): "); month = keyboard.nextInt(); System.out.print("Day of purchase (dd): "); day = keyboard.nextInt(); System.out.print("Year of purchase (yyyy): "); year = keyboard.nextInt(); System.out.print("Date: " + month + day + year + "\n"); // Switch Statement switch(total) { case(LightBulb60W): cost = 3.00; break; case(LightBulb100W): cost = 5.99; break; case(BoltM5): cost = 0.15; break; case(BoltM8): cost = 0.25; break; case(Hose25): cost = 10; break; case(Hose50): cost = 15; break; } System.out.println(total); System.out.print("Your total for " + productMap.get(new Integer(total)) + " is: " + "$" + cost * units + "\n"); // While Loop @SuppressWarnings("resource") Scanner scan = new Scanner(System.in); System.out.println("Do you want to continue to loop? (y/n)"); String s = scan.next(); while ( ! s.equals("n") ) { System.out.println("Do you want to continue to loop? (y/n)"); s = scan.next(); if (s == "n") break; } } } }
Here is my code in Java: import java.util.Scanner; import java.util.HashMap; public class Inventory { /** This class demonstrates the inventory */ //Declarations Of inventory static final int LightBulb60W = 1; static final int LightBulb100W = 2; static final int BoltM5 = 3; static final int BoltM8 = 4; static final int Hose25 = 5; static final int Hose50 = 6; public static void main (String [] args) { //Scanner Object @SuppressWarnings("resource") Scanner keyboard = new Scanner(System.in); //Variables int month; int day; int year; double units; double cost = 0; //Declarations int total; HashMap productMap = new HashMap<>(); productMap.put(1,"Light Bulb 60W"); productMap.put(2,"Light Bulb 100W"); productMap.put(3,"Bolt M5"); productMap.put(4,"Bolt M8"); productMap.put(5,"Hose 25 feet"); productMap.put(6,"Hose 50 feet 60W"); while(true){ //Prints out inventory System.out.println("The Inventory: "); System.out.println("1 Light Bulb 60W 3 dollars 0 cents X"); System.out.println("2 Light Bulb 100W 5 dollars 99 cents X"); System.out.println("3 Bolt M5 0 dollars 15 cents Y"); System.out.println("4 Bolt M8 0 dollars 25 cents Y"); System.out.println("5 Hose 25 feet 10 dollars 0 cents Z"); System.out.println("6 Hose 50 feet 15 dollars 0 cents Z\n"); //Prints out desirable item number System.out.print("Which item number from the list do you desire?\n"); System.out.print("1, 2, 3, 4, 5 or 6?\n"); total = keyboard.nextInt(); System.out.print("Your choice: " + total + "\n"); // Units System.out.print("How many units do you desire?\n"); units = keyboard.nextInt(); System.out.print("Number of units: "); System.out.print("When do you plan your purchase?\n"); System.out.print("Month of purchase (mm): "); month = keyboard.nextInt(); System.out.print("Day of purchase (dd): "); day = keyboard.nextInt(); System.out.print("Year of purchase (yyyy): "); year = keyboard.nextInt(); System.out.print("Date: " + month + day + year + "\n"); // Switch Statement switch(total) { case(LightBulb60W): cost = 3.00; break; case(LightBulb100W): cost = 5.99; break; case(BoltM5): cost = 0.15; break; case(BoltM8): cost = 0.25; break; case(Hose25): cost = 10; break; case(Hose50): cost = 15; break; } System.out.println(total); System.out.print("Your total for " + productMap.get(new Integer(total)) + " is: " + "$" + cost * units + "\n"); // While Loop @SuppressWarnings("resource") Scanner scan = new Scanner(System.in); System.out.println("Do you want to continue to loop? (y/n)"); String s = scan.next(); while ( ! s.equals("n") ) { System.out.println("Do you want to continue to loop? (y/n)"); s = scan.next(); if (s == "n") break; } } } }
Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
Related questions
Question
Here is my code in Java:
import java.util.Scanner;
import java.util.HashMap;
public class Inventory {
/**
This class demonstrates the inventory
*/
//Declarations Of inventory
static final int LightBulb60W = 1;
static final int LightBulb100W = 2;
static final int BoltM5 = 3;
static final int BoltM8 = 4;
static final int Hose25 = 5;
static final int Hose50 = 6;
public static void main (String [] args)
{
//Scanner Object
@SuppressWarnings("resource")
Scanner keyboard = new Scanner(System.in);
//Variables
int month;
int day;
int year;
double units;
double cost = 0;
//Declarations
int total;
HashMap<Integer, String> productMap = new HashMap<>();
productMap.put(1,"Light Bulb 60W");
productMap.put(2,"Light Bulb 100W");
productMap.put(3,"Bolt M5");
productMap.put(4,"Bolt M8");
productMap.put(5,"Hose 25 feet");
productMap.put(6,"Hose 50 feet 60W");
while(true){
//Prints out inventory
System.out.println("The Inventory: ");
System.out.println("1 Light Bulb 60W 3 dollars 0 cents X");
System.out.println("2 Light Bulb 100W 5 dollars 99 cents X");
System.out.println("3 Bolt M5 0 dollars 15 cents Y");
System.out.println("4 Bolt M8 0 dollars 25 cents Y");
System.out.println("5 Hose 25 feet 10 dollars 0 cents Z");
System.out.println("6 Hose 50 feet 15 dollars 0 cents Z\n");
//Prints out desirable item number
System.out.print("Which item number from the list do you desire?\n");
System.out.print("1, 2, 3, 4, 5 or 6?\n");
total = keyboard.nextInt();
System.out.print("Your choice: " + total + "\n");
// Units
System.out.print("How many units do you desire?\n");
units = keyboard.nextInt();
System.out.print("Number of units: ");
System.out.print("When do you plan your purchase?\n");
System.out.print("Month of purchase (mm): ");
month = keyboard.nextInt();
System.out.print("Day of purchase (dd): ");
day = keyboard.nextInt();
System.out.print("Year of purchase (yyyy): ");
year = keyboard.nextInt();
System.out.print("Date: " + month + day + year + "\n");
// Switch Statement
switch(total) {
case(LightBulb60W):
cost = 3.00;
break;
case(LightBulb100W):
cost = 5.99;
break;
case(BoltM5):
cost = 0.15;
break;
case(BoltM8):
cost = 0.25;
break;
case(Hose25):
cost = 10;
break;
case(Hose50):
cost = 15;
break;
}
System.out.println(total);
System.out.print("Your total for " + productMap.get(new Integer(total)) + " is: " + "$" + cost * units + "\n");
// While Loop
@SuppressWarnings("resource")
Scanner scan = new Scanner(System.in);
System.out.println("Do you want to continue to loop? (y/n)");
String s = scan.next();
while ( ! s.equals("n") )
{
System.out.println("Do you want to continue to loop? (y/n)");
s = scan.next();
if (s == "n")
break;
}
}
}
}
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 1 images
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Recommended textbooks for you
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education