First three pictures are the question the 4rth picture is the \"SHOPPING.LIST.TX
ID: 3780307 • Letter: F
Question
First three pictures are the question the 4rth picture is the "SHOPPING.LIST.TXT" the 5th picture is the "INVENTORY.TXT". 1.c) Modify your program from part b to read in the shopping list information and update the following after all the items on the shopping listare purchased. The shoppinglist file has the format on each line: quantity category subcategory item name OR quantit category subcategory OR quantity category Therefore, the file could have any or all of the following three lines: 3 vegetable canned peas Del Monte Sweet Peas 1 vegetable 1 vegetable canned peas Your program should read in the quantity and category and then read subcategory ifit is there and read item name if it is there. Print the information that is read in with a sentence something like "The current entry on the shopping list is3 of Del Monte Sweet Pea canned pea vegetable. "OR "The current entry on the shopping list is 1 of vegetable." Once the information has been read in, your program should 'sell' the item(s to the shopper. Every item on the shopping list should be handled by the algorithm below that checks theExplanation / Answer
package readfile_inventorycheck;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
/**
*
* @author Kiran
*/
public class Readfile_Inventorycheck {
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws FileNotFoundException {
// TODO code application logic here
//creating File instance to reference text file in Java
File sList = new File("shopinglist.txt");
File iList = new File("inventorylist.txt");
//Creating Scanner instnace to read File in Java
Scanner scnr = new Scanner(sList);
Scanner scnr1=new Scanner(iList);
String subcate=" ";
String itemName=" ";
int quan;
//Reading each line of file using Scanner class
int lineNumber = 1;
while(scnr.hasNext()){
quan = scnr.nextInt();
String cate=scnr.next();
if(scnr.next()!=" "){
subcate=scnr.next();
}
if(scnr.next()!=" "){
itemName=scnr.next();
}
}
System.out.println("The current entry on Shooping list is "+quan+"of "+cate+subcate+itemName);
while(scnr1.hasNext()){
if(itemName==scnr1.next()){
while(scnr1.hasNext()){
if(quan<=scnr1.nextInt())
{
int iQuan=scnr1.nextInt();
System.out.println("you are buying the specified quantity item");
scnr1.nextInt()=iQuan-quan;
}
}
}
}
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.