How many types of products were sold? 4 Exception in thread "main" java.util.NoSuchElement Exception at java.base/j ava.util.Scanner. throwFor (Scanner.java: 937) at java.base/j ava . uti l. Scanner .next (Scanner.java:1594) at java.base/java.util.Scanner.nextInt (Scanner.java:2258) at java.base /j ava . util. Scanner.nextInt (Scanner.java:2212) at inventoryUpdate.mOrganize (inventoryUpdate.java:39) at inventoryUpdate. main (inventoryUpdate.java:14) Process finished with exit code 1

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
icon
Related questions
Question

Hello, I am working in java and wondering why my program isn't working. I will attach the criteria and code below. I have attached my error.

 

Criteria

------------

Inventory Update program.

The first set of records is the master file which reflects an item inventory at the start of the business day. Each master file record contains a part number and a corresponding item stock quantity. Let us assume that the master file contains no more than 5 records.

The second set of records reflects the transactions for each of various items during that day. Transaction records contain have the same format as the master file records: they contain the item number and the corresponding total number of items sold that day. There is unknown number of such transaction records in the input file.

Write a program to update the master file against the transaction file to produce the new master file at the end of the day. A record notice should accompany any item number for which fewer than 10 items remain in the stock.

 

                       Current Inventory

Item No.                              Quantity

444                                        40

111                                        30

222                                        15

134                                        20

353                                          5

Sold in a day.

134                                        03

111                                        29

353                                        02

222                                        10

Final output should be

Item No.                            Quantity

444                                        40

111                                          1   reorder

222                                          5   reorder

134                                        17

353                                         3    reorder

-----------------------

I do not understand why my code does not work.

My Code

----------------------

import java.io.*;
import java.util.*;

public class inventoryUpdate {
//Exception included due to mOrganize, sOrganize, and PrintWriter
public static void main(String[] args) throws Exception {

Scanner inKey = new Scanner(System.in);

//Preparing the document based on how many item types were sold.
System.out.println("How many types of products were sold?");
int sold = inKey.nextInt();

int[][] inMaster = fileCheck(mOrganize(), sOrganize(sold), sold);

PrintWriter printFile = new PrintWriter("Master.txt");
printFile.println("Item No. \tQuantity");

for (int i = 0; i<5;i++){
if (inMaster[i][1] < 10){
printFile.printf("%-5s %17s You are low in inventory on this item. Please order more.\n", inMaster[i][0], inMaster[i][1]);
}
else{
printFile.printf("%-5s %17s\n", inMaster[i][0], inMaster[i][1]);
}
}
printFile.close();
System.out.println(Arrays.deepToString(inMaster));
}

private static int[][] mOrganize() throws Exception {
File fileRip = new File("Master.txt");
Scanner masterRead = new Scanner(fileRip);
masterRead.nextLine();

int[][] masterData = new int [5][2];
for (int i = 0; i < 5; i++){
for (int i2 = 0; i2 < 2; i2++){
masterData[i][i2] = masterRead.nextInt();
if (masterData[i][i2] < 10){
masterRead.nextLine();
}
}
}
masterRead.close();
return masterData;
}

private static int[][] sOrganize(int sold) throws Exception{
File fileRip = new File ("Sales.txt");
Scanner saleRead = new Scanner(fileRip);
saleRead.nextLine();

int [][] salesData = new int [sold][2];
for (int i = 0; i < sold; i++){
for (int i2 = 0; i2 < 2; i2++){
salesData[i][i2] = saleRead.nextInt();
}
}

saleRead.close();
return salesData;
}

private static int[][] fileCheck(int[][] master, int[][] sales, int sold){
int columnBase = 0;
for(int i = 0; i < 5; i++){
for(int i2 = 0; i2 < sold; i2++){
if (master[i][columnBase] == sales[i2][columnBase]){
master[i][columnBase + 1] -= sales[i2][columnBase + 1];
}
}
}
return master;
}
}

 

How many types of products were sold?
4
Exception in thread "main" java.util.NoSuchElement Exception
at java.base/j ava.util.Scanner. throwFor (Scanner.java: 937)
at java.base/j ava . uti l. Scanner .next (Scanner.java:1594)
at java.base/java.util.Scanner.nextInt (Scanner.java:2258)
at java.base /j ava . util. Scanner.nextInt (Scanner.java:2212)
at inventoryUpdate.mOrganize (inventoryUpdate.java:39)
at inventoryUpdate. main (inventoryUpdate.java:14)
Process finished with exit code 1
Transcribed Image Text:How many types of products were sold? 4 Exception in thread "main" java.util.NoSuchElement Exception at java.base/j ava.util.Scanner. throwFor (Scanner.java: 937) at java.base/j ava . uti l. Scanner .next (Scanner.java:1594) at java.base/java.util.Scanner.nextInt (Scanner.java:2258) at java.base /j ava . util. Scanner.nextInt (Scanner.java:2212) at inventoryUpdate.mOrganize (inventoryUpdate.java:39) at inventoryUpdate. main (inventoryUpdate.java:14) Process finished with exit code 1
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 6 steps with 6 images

Blurred answer
Knowledge Booster
File Input and Output Operations
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.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
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)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education