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
Hello, I am working in java and wondering why my
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;
}
}
Trending now
This is a popular solution!
Step by step
Solved in 6 steps with 6 images