Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //PARTIALLY DONE CODE FOR FINAL PROJECT. JUST NEED TO MAKE IT LOOK GOOD, COMPLETE ALL ITEMS, ADD TRY CATCH, ETC
- package HomePrac;
- import java.io.FileNotFoundException;
- import java.io.FileReader;
- import java.io.PrintWriter;
- import java.util.*;
- import javax.swing.JOptionPane;
- public class FilePrinter {
- public static void main(String[] args) throws FileNotFoundException {
- PrintWriter outfile = new PrintWriter ("total.txt");
- JOptionPane.showMessageDialog(null, "Welcome to the tech store!", "Tech Store", 1);
- String fitems = "", str = "" , fitem="";
- int exit = 0;
- double total = 0;
- double totalall = 0;
- do
- {
- String items [] = {"Monitors", "Processors", "Keyboards", "Mice", "Laptops"};
- String monimodel, procemodel, kbmodel, micemodel, lapmodel;
- // Models:
- String[] monitorsm = {"BenQ EX3501R", "Alienware AW3418DW", "Asus ROG Swift PG27UQ"};
- String[] processorsm = {"AMD Ryzen Threadripper 1950X" , "AMD Ryzen 5 1600X" , "Intel Core i5-7600K"};
- String[] keyboardsm = {"Corsair K70 RGB Mk.2", "Das Keyboard 4 Professional", "Razer BlackWidow Elite"};
- String[] micem = {"Logitech G502 Proteus Spectrum", "Logitech G300s", "Razer Atheris"};
- String[] laptopsm = {"Dell XPS 13", "Lenovo Yoga C930", "MSI GS65 Stealth"};
- String item = JOptionPane.showInputDialog("Please select the number of the item you are looking for. Here are our available ones:" +"\n" + "\n (1)Monitors" + "\n (2)Processors" + "\n (3)Keyboards" + "\n (4)Mice" + "\n (5)Laptops");
- // Monitors
- switch (item) {
- case "Monitor":
- case "Monitors":
- case "1":
- JOptionPane.showMessageDialog(null, "You have chosen " +items[0]);
- monimodel = JOptionPane.showInputDialog("Please select the number of the model you want. These are our current available ones:" + "\n" +"(1)"+monitorsm[0] + "\n" + "(2)"+monitorsm[1] + "\n" + "(3)"+monitorsm[2]);
- if (monimodel.equalsIgnoreCase("1"))
- {
- double m1price = 45000;
- JOptionPane.showMessageDialog(null, "You have chosen " + monitorsm[0] + ". the price for this is " + m1price );
- int qty = Integer.parseInt(JOptionPane.showInputDialog("Please enter quantity"));
- total = totalprice (m1price,qty);
- totalall = totalall + total;
- JOptionPane.showMessageDialog(null, "You have purchased " + qty + " of the " +monitorsm[0]+ ". The price is " + total);
- outfile.println(monitorsm[0]+":");
- }
- else if (monimodel.equalsIgnoreCase("2"))
- {
- double m2price = 50000;
- JOptionPane.showMessageDialog(null, "You have chosen " + monitorsm[1] + ". the price for this is " + m2price );
- int qty = Integer.parseInt(JOptionPane.showInputDialog("Please enter quantity"));
- total = totalprice (m2price,qty);
- totalall = totalall + total;
- JOptionPane.showMessageDialog(null, "You have purchased " + qty + " of the " +monitorsm[1]+ ". The price is " + total);
- outfile.println(monitorsm[1]+":");
- }
- else if (monimodel.equalsIgnoreCase("3"))
- {
- double m3price = 50000;
- JOptionPane.showMessageDialog(null, "You have chosen " + monitorsm[2] + ". the price for this is " + m3price );
- int qty = Integer.parseInt(JOptionPane.showInputDialog("Please enter quantity"));
- total = totalprice (m3price,qty);
- totalall = totalall + total;
- JOptionPane.showMessageDialog(null, "You have purchased " + qty + " of the " +monitorsm[2]+ ". The price is " + total);
- outfile.println(monitorsm[2]+":");
- }
- break;
- case "processors":
- case "Processors":
- case "2":
- JOptionPane.showMessageDialog(null, "You have chosen " +items[1]);
- procemodel = JOptionPane.showInputDialog("Please select the number of the model you want. These are our current available ones:" + "\n" +"(1)"+processorsm[0] + "\n" + "(2)"+processorsm[1] + "\n" + "(3)"+processorsm[2]);
- if (procemodel.equalsIgnoreCase("1"))
- {
- double m1price = 30000;
- JOptionPane.showMessageDialog(null, "You have chosen " + processorsm[0] + ". the price for this is " + m1price );
- int qty = Integer.parseInt(JOptionPane.showInputDialog("Please enter quantity"));
- total = totalprice (m1price,qty);
- totalall = totalall + total;
- JOptionPane.showMessageDialog(null, "You have purchased " + qty + " of the " +processorsm[0]+ ". The price is " + total);
- outfile.println(processorsm[0]+":");
- }
- else if (procemodel.equalsIgnoreCase("2"))
- {
- double m2price = 25000;
- JOptionPane.showMessageDialog(null, "You have chosen " + processorsm[1] + ". the price for this is " + m2price );
- int qty = Integer.parseInt(JOptionPane.showInputDialog("Please enter quantity"));
- total = totalprice (m2price,qty);
- totalall = totalall + total;
- JOptionPane.showMessageDialog(null, "You have purchased " + qty + " of the " +processorsm[1]+ ". The price is " + total);
- outfile.println(processorsm[1]+":");
- }
- else if (procemodel.equalsIgnoreCase("3"))
- {
- double m3price = 18000;
- JOptionPane.showMessageDialog(null, "You have chosen " + processorsm[2] + ". the price for this is " + m3price );
- int qty = Integer.parseInt(JOptionPane.showInputDialog("Please enter quantity"));
- total = totalprice (m3price,qty);
- totalall = totalall + total;
- JOptionPane.showMessageDialog(null, "You have purchased " + qty + " of the " +processorsm[2]+ ". The price is " + total);
- outfile.println(processorsm[2]+":");
- }
- break;
- case "Keyboard":
- case "keyboards":
- case "3":
- JOptionPane.showMessageDialog(null, "You have chosen " +items[2]);
- kbmodel = JOptionPane.showInputDialog("Please select the number of the model you want. These are our current available ones:" + "\n" +"(1)"+keyboardsm[0] + "\n" + "(2)"+keyboardsm[1] + "\n" + "(3)"+keyboardsm[2]);
- if (kbmodel.equalsIgnoreCase("1"))
- {
- double m1price = 8000;
- JOptionPane.showMessageDialog(null, "You have chosen " + keyboardsm[0] + ". the price for this is " + m1price );
- int qty = Integer.parseInt(JOptionPane.showInputDialog("Please enter quantity"));
- total = totalprice (m1price,qty);
- totalall = totalall + total;
- JOptionPane.showMessageDialog(null, "You have purchased " + qty + " of the " +keyboardsm[0]+ ". The price is " + total);
- outfile.println(keyboardsm[0]+":");
- }
- else if (kbmodel.equalsIgnoreCase("2"))
- {
- double m2price = 9500;
- JOptionPane.showMessageDialog(null, "You have chosen " + keyboardsm[1] + ". the price for this is " + m2price );
- int qty = Integer.parseInt(JOptionPane.showInputDialog("Please enter quantity"));
- total = totalprice (m2price,qty);
- totalall = totalall + total;
- JOptionPane.showMessageDialog(null, "You have purchased " + qty + " of the " +keyboardsm[1]+ ". The price is " + total);
- outfile.println(keyboardsm[1]+":");
- }
- else if (kbmodel.equalsIgnoreCase("3"))
- {
- double m3price = 12000;
- JOptionPane.showMessageDialog(null, "You have chosen " + keyboardsm[2] + ". the price for this is " + m3price );
- int qty = Integer.parseInt(JOptionPane.showInputDialog("Please enter quantity"));
- total = totalprice (m3price,qty);
- totalall = totalall + total;
- JOptionPane.showMessageDialog(null, "You have purchased " + qty + " of the " +keyboardsm[2]+ ". The price is " + total);
- outfile.println(keyboardsm[2]+":");
- }
- break;
- case "Mice":
- case "Mouse":
- case "4":
- JOptionPane.showMessageDialog(null, "You have chosen " +items[3]);
- procemodel = JOptionPane.showInputDialog("Please select the number of the model you want. These are our current available ones:" + "\n" +"(1)"+micem[0] + "\n" + "(2)"+micem[1] + "\n" + "(3)"+micem[2]);
- if (procemodel.equalsIgnoreCase("1"))
- {
- double m1price = 7000;
- JOptionPane.showMessageDialog(null, "You have chosen " + micem[0] + ". the price for this is " + m1price );
- int qty = Integer.parseInt(JOptionPane.showInputDialog("Please enter quantity"));
- total = totalprice (m1price,qty);
- totalall = totalall + total;
- JOptionPane.showMessageDialog(null, "You have purchased " + qty + " of the " +micem[0]+ ". The price is " + total);
- outfile.println(micem[0]+":");
- }
- else if (procemodel.equalsIgnoreCase("2"))
- {
- double m2price = 3500;
- JOptionPane.showMessageDialog(null, "You have chosen " + micem[1] + ". the price for this is " + m2price );
- int qty = Integer.parseInt(JOptionPane.showInputDialog("Please enter quantity"));
- total = totalprice (m2price,qty);
- totalall = totalall + total;
- JOptionPane.showMessageDialog(null, "You have purchased " + qty + " of the " +micem[1]+ ". The price is " + total);
- outfile.println(micem[1]+":");
- }
- else if (procemodel.equalsIgnoreCase("3"))
- {
- double m3price = 6500;
- JOptionPane.showMessageDialog(null, "You have chosen " + micem[2] + ". the price for this is " + m3price );
- int qty = Integer.parseInt(JOptionPane.showInputDialog("Please enter quantity"));
- total = totalprice (m3price,qty);
- totalall = totalall + total;
- JOptionPane.showMessageDialog(null, "You have purchased " + qty + " of the " +micem[2]+ ". The price is " + total);
- outfile.println(micem[2]+":");
- }
- break;
- case "Laptops":
- case "Laptop":
- case "5":
- JOptionPane.showMessageDialog(null, "You have chosen " +items[4]);
- procemodel = JOptionPane.showInputDialog("Please select the number of the model you want. These are our current available ones:" + "\n" +"(1)"+laptopsm[0] + "\n" + "(2)"+laptopsm[1] + "\n" + "(3)"+laptopsm[2]);
- if (procemodel.equalsIgnoreCase("1"))
- {
- double m1price = 80000;
- JOptionPane.showMessageDialog(null, "You have chosen " + laptopsm[0] + ". the price for this is " + m1price );
- int qty = Integer.parseInt(JOptionPane.showInputDialog("Please enter quantity"));
- total = totalprice (m1price,qty);
- totalall = totalall + total;
- JOptionPane.showMessageDialog(null, "You have purchased " + qty + " of the " +laptopsm[0]+ ". The price is " + total);
- outfile.println(laptopsm[0]+":");
- }
- else if (procemodel.equalsIgnoreCase("2"))
- {
- double m2price = 75000;
- JOptionPane.showMessageDialog(null, "You have chosen " + laptopsm[1] + ". the price for this is " + m2price );
- int qty = Integer.parseInt(JOptionPane.showInputDialog("Please enter quantity"));
- total = totalprice (m2price,qty);
- totalall = totalall + total;
- JOptionPane.showMessageDialog(null, "You have purchased " + qty + " of the " +laptopsm[1]+ ". The price is " + total);
- outfile.println(laptopsm[1]+":");
- }
- else if (procemodel.equalsIgnoreCase("3"))
- {
- double m3price = 90000;
- JOptionPane.showMessageDialog(null, "You have chosen " + laptopsm[2] + ". the price for this is " + m3price );
- int qty = Integer.parseInt(JOptionPane.showInputDialog("Please enter quantity"));
- total = totalprice (m3price,qty);
- totalall = totalall + total;
- JOptionPane.showMessageDialog(null, "You have purchased " + qty + " of the " +laptopsm[2]+ ". The price is " + total);
- outfile.println(laptopsm[2]+":");
- }
- }
- }
- while (JOptionPane.showConfirmDialog(null, "Do you want to shop more?")==0);
- outfile.close();
- // Store items purchased:
- Scanner infile = new Scanner (new FileReader("total.txt"));
- infile.useDelimiter(":");
- while (infile.hasNext()) {
- fitems = infile.next();
- infile.nextLine();
- str = str + fitems + "\n";
- }
- JOptionPane.showMessageDialog(null, "The items you purchased are:\n" + str);
- // UPDATE ITEM INCOMPLETE
- int update = JOptionPane.showConfirmDialog(null, "Do you want to update your purchase?");
- if (update==0)
- {
- String sitem = JOptionPane.showInputDialog(null, "Search for item name");
- Scanner ifile = new Scanner (new FileReader("total.txt"));
- ifile.useDelimiter(":");
- boolean found = false;
- while (ifile.hasNext()) {
- fitem = ifile.next();
- ifile.nextLine();
- if (fitem.equalsIgnoreCase(sitem)){
- JOptionPane.showMessageDialog (null, "Item: " + fitem , "Item Found", 1);
- found = true;
- }
- ifile.close();
- if (!found){
- JOptionPane.showMessageDialog(null,"Item not found", "Error", 1);
- }
- JOptionPane.showMessageDialog(null, "\nThank you for shopping with us! The total of your purchase is " + String.format("%.2f",totalall), "Checkout",1);
- }}
- }
- public static double totalprice(double x, double y) {
- double z = x*y;
- return z;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement