/* *This program simulates a supplies office and prompts the user to enter data for *item code, description, weight and cost of that item and then *stores the information in arrays.Once the user is finished typing in the data, *they are then prompted to place an order by entering the item codes for the *items they want. If the user has entered the correct code, they would be *allowed to enter a quantity for the item ordered. When the user is finished *with the order, a summary is printed for the items ordered with the total cost * and weight. The program then terminates. * */
import java.text.*;
import java.util.*;
import java.io.*;
public class ExpeditionSuppliesOfficePart2 {
public static void main(String args[]) throws IOException{
BufferedReader in = new BufferedReader(new InputStreamReader (System.in));
/****************************************************************************** Section 1 Declaring arrays and variables with name and types. *****************************************************************************/
final int max = 1000; String code[] = new String[max];//Declares array for item code String description[] = new String[max];//Declares array for item description int grams[] = new int[max];//Declares array for weight in grams of item double price[] = new double[max];//Declares array for cost of the item
String itemCode = ""; int quantity = 0; int locAt = 0; String summary = ""; String orderSummary = ""; double totalWeight = 0;//total weight for one item double totalPrice = 0;//total price for one item double grandTotalWeight = 0;//overall weight in Kg double grandTotalCost = 0;//overall cost boolean userIsDone = false;//boolean logic
printStars(); System.out.println("\n\n"); System.out.println("PLEASE ENTER ITEM DETAILS\n");
/****************************************************************************** Section 2 This is the start of the for loop, and prompts the user for the item code and description. *****************************************************************************/
/****************************************************************************** Section 3 This loop allows the user to enter the weight only using numbers, anything else would not be accepted because of the try and catch exceptions *****************************************************************************/
for (int i = 0; i < max; i++) { try{ System.out.print("\nENTER ITEM WEIGHT IN GRAMS: "); grams[loc] = Integer.parseInt(in.readLine()); break;//this command exits the loop }//end of try
catch(NumberFormatException ne){ System.out.println("\nINVALID WEIGHT"); }//end of catch }//end of for
/****************************************************************************** Section 4 This loop prompts the user to enter the unit price for the item, again allowing the user to enter only number format. *****************************************************************************/
for (int i = 0; i < max; i++) { try{ System.out.print("\nENTER ITEM UNIT PRICE ($): "); price[loc] = Double.parseDouble(in.readLine()); break;//this command exits the loop }//end of try
catch(NumberFormatException ne){ System.out.println("\nPLEASE ENTER CORRECT PRICE"); }//end of catch }//end of for
/****************************************************************************** Section 5 Prompts the user to enter another item. *****************************************************************************/
printStars(); System.out.println("\n"); System.out.print("\nWOULD YOU LIKE TO ENTER ANOTHER ITEM?(Y/N):"); String choice = in.readLine(); System.out.print("\n"); printStars(); System.out.print("\n");
if ( choice.equalsIgnoreCase("N") ){
userIsDone = true; break;//this command exits the loop }//end of if
}//end of for loop
/****************************************************************************** Section 6 This loop searches the array for the item code and prints out the location once it is found. If it is not found it prompts the user to enter another item code. *****************************************************************************/
System.out.println("ITEM IS " +description[locAt]+ ", WEIGHT IN GRAMS: "+grams[locAt]+ " UNIT PRICE: $"+price[locAt]);
for (int j = 0; j < max; j++) { try{ System.out.print("ENTER QUANTITY: "); quantity = Integer.parseInt(in.readLine()); break;//this command exits the loop }//end of try
catch(NumberFormatException ne){ System.out.println("\nPLEASE ENTER VALID QUANTITY"); }//end of catch }//end of for
/****************************************************************************** This allows for the calculation of total price and the overall cost and weight. *****************************************************************************/
/****************************************************************************** Prompts the user to enter another item. *****************************************************************************/
System.out.print("\nWOULD YOU LIKE TO ENTER ANOTHER ITEM?(Y/N):"); String choice = in.readLine(); System.out.print("\n");
if ( choice.equalsIgnoreCase("N") ){
userIsDone = true; break;//this command exits the loop
}//end of if
}//end of for
/****************************************************************************** Section 7 Prints out a summary of the items ordered. *****************************************************************************/
printStars(); System.out.println("\n\nSUMMARY:"); System.out.println("YOU HAVE ORDERED"); System.out.println(orderSummary); System.out.println("GRAND TOTAL WEIGHT: " +grandTotalWeight/1000+"Kg"); System.out.println("GRAND TOTAL COST: $" +grandTotalCost); System.out.print("\n"); printThankYouScreen();
}//end of main method
/****************************************************************************** Section 8 This method prints out a row of lines *****************************************************************************/
public static void printStars(){
for (int i = 0;i<=60;i++){ System.out.print('='); }//end of for
}//end of printStars
/****************************************************************************** This method prints out a thank you note at the end of the program. *****************************************************************************/
public static void printThankYou(){ System.out.println("THANK YOU AND HAVE A NICE DAY"); }//end of printThankYou()
public static void printThankYouScreen(){ printStars(); System.out.println("\n\n"); printThankYou(); printStars(); System.out.println("\n\n");
}//end of printThankYouScreen()
}//end of class
Take this program and modify it in the following way:take the part that records each item so that after the use enters the item information, this information is saved to an external file. Make the program which allows the user to place an order a second, separate, program. This second program should open the file created by the first program, and use the information in it to process an order.