In this assignment, you will decide how to keep the inventory in the text file. Then your program must read the inventory from the file into the array. Each product must have a record in the file with the name, regular price, and type. There are several options for storing records in the file. For example, • each value takes one line in the file (i.e., three lines for one product). Then you must take care of correct handling of the ends of the lines; • all values are in one line that can be read as a string. Then you must handle the parsing of the string; • all values are in one line separated by a delimiter. Then you must handle a line with delimiters. Assume that the inventory does not have more than 100 products. But the actual number is known only after the reading of the file. Once you can read data from the file into the array, you must add a new property to the product class – a static variable that holds the number of products in the inventory. Its value must grow as reading from the file progresses. There is an example of an output and here is my current code, which isn't working: import java.util.Scanner; public class Inventory { /** This class demonstrates the inventory */ publicstaticvoidmain(String[]args) { //Scanner Object Scannerkeyboard=newScanner(System.in);   //Variables  doublemonth;  doubleday; doubleyear;  doubleunits;  @SuppressWarnings("unused") doublecost;    //Declarations inttotal;   //Declarations Of inventory intLightBulb60W=1; intLightBulb100W=2; intBoltM5=3;  intBoltM8=4; intHose25=5; intHose50=6;   //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.nextDouble();  } { System.out.print("Day of purchase (dd): "); day=keyboard.nextDouble();  } { System.out.print("Year of purchase (yy): "); year=keyboard.nextDouble();  } { System.out.print("Date: " + month + day + year + "\n"); } {         //Switch Statement         switch(total){         case(1):         cost=3.00;         break;         case(2):         cost=5.99;         break;         case(3):         cost=0.15;         break;         case(4):         cost=0.25;         break;         case(5):         cost=10;         break;         case(6):         cost=15;         break;         }         System.out.println(total);         }   { System.out.print("Your total is: " + "$" + total * units); } }}

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
100%

In this assignment, you will decide how to keep the inventory in the text file. Then your program must read the inventory from the file into the array.

Each product must have a record in the file with the name, regular price, and type. There are several options for storing records in the file. For example,

• each value takes one line in the file (i.e., three lines for one product). Then you must take care of correct handling of the ends of the lines;

• all values are in one line that can be read as a string. Then you must handle the parsing of the string;

• all values are in one line separated by a delimiter. Then you must handle a line with delimiters.

Assume that the inventory does not have more than 100 products. But the actual number is known only after the reading of the file. Once you can read data from the file into the array, you must add a new property to the product class – a static variable that holds the number of products in the inventory. Its value must grow as reading from the file progresses.

There is an example of an output and here is my current code, which isn't working:

import java.util.Scanner;

public class Inventory {

/**

This class demonstrates the inventory

*/

publicstaticvoidmain(String[]args)

{

//Scanner Object

Scannerkeyboard=newScanner(System.in);

 

//Variables 

doublemonth; 

doubleday;

doubleyear; 

doubleunits; 

@SuppressWarnings("unused")

doublecost; 

 

//Declarations

inttotal;

 

//Declarations Of inventory

intLightBulb60W=1;

intLightBulb100W=2;

intBoltM5=3; 

intBoltM8=4;

intHose25=5;

intHose50=6;

 

//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.nextDouble(); 

}

{

System.out.print("Day of purchase (dd): ");

day=keyboard.nextDouble(); 

}

{

System.out.print("Year of purchase (yy): ");

year=keyboard.nextDouble(); 

}

{

System.out.print("Date: " + month + day + year + "\n");

}

{

       

//Switch Statement

        switch(total){

        case(1):

        cost=3.00;

        break;

        case(2):

        cost=5.99;

        break;

        case(3):

        cost=0.15;

        break;

        case(4):

        cost=0.25;

        break;

        case(5):

        cost=10;

        break;

        case(6):

        cost=15;

        break;

        }

        System.out.println(total);

        }

 

{

System.out.print("Your total is: " + "$" + total * units);

}

}}

The inventory:
1 Light Bulb 60W
2 Light Bulb 100W
3 dollars 0 cents
5 dollars 99 cents
0 dollars 15 cents
0 dollars 25 cents
3 Bolt M5
Y
4 Bolt M8
Y
5 Hose 25 feet
10 dollars 0 cents
6 Hose 50 feet
Your choice: 6
Number of units: 2
When do you plan your purchase?
Month of purchase (mm): 12
Day of purchase (dd): 12
Year of purchase (yyyy): 2022
Your total for Hose 50 feet is $30.00.
15 dollars 0 cents
Z
Continue? (Y/N): N
Transcribed Image Text:The inventory: 1 Light Bulb 60W 2 Light Bulb 100W 3 dollars 0 cents 5 dollars 99 cents 0 dollars 15 cents 0 dollars 25 cents 3 Bolt M5 Y 4 Bolt M8 Y 5 Hose 25 feet 10 dollars 0 cents 6 Hose 50 feet Your choice: 6 Number of units: 2 When do you plan your purchase? Month of purchase (mm): 12 Day of purchase (dd): 12 Year of purchase (yyyy): 2022 Your total for Hose 50 feet is $30.00. 15 dollars 0 cents Z Continue? (Y/N): N
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 3 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY