Advertisement
cynthiarez

Final Project 2nd Attempt (Total change)

Sep 10th, 2019
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.76 KB | None | 0 0
  1. // What the system lacks atm:
  2. > how to let it run from the top if the user opts to "shop more"
  3. > how to add up all of the user's purchased items
  4. > More items...
  5.  
  6. package HomePrac;
  7. import java.io.FileNotFoundException;
  8. import javax.swing.JOptionPane;
  9. import java.io.FileReader;
  10. import java.io.PrintWriter;
  11. import java.util.*;
  12.  
  13. public class FilePrinter {
  14.  
  15. public static void main(String[] args) throws FileNotFoundException {
  16.  
  17. PrintWriter bill = new PrintWriter ("bill.txt");
  18.  
  19. String a = "Monitor" ,b = "Processor", c = "RAM";
  20. String a1 = "LG", b1 = "Asus", c1 = "Acer";
  21.  
  22. String item = JOptionPane.showInputDialog("Please enter what item you are looking for");
  23.  
  24.  
  25. if (item.equalsIgnoreCase(a))
  26. {
  27. JOptionPane.showMessageDialog(null, "You have chosen " +a+ "s");
  28. String monitorbrand = JOptionPane.showInputDialog("Please enter the brand you want. These are our current available ones:" + "\n" + a1 + "\n" + b1 + "\n" + c1);
  29.  
  30.  
  31.  
  32. if (monitorbrand.equalsIgnoreCase(a1))
  33. {
  34. double lgprice = 8000;
  35. JOptionPane.showMessageDialog(null, "You have chosen " + a1 + ". the price for this is " + lgprice );
  36. int qty = Integer.parseInt(JOptionPane.showInputDialog("Please enter quantity"));
  37.  
  38. double total = lgprice*qty;
  39. bill.println(total); // Prints the value of selected String to the txt file, so it could be calculated and outputed later on for checkout
  40. bill.close();
  41.  
  42. JOptionPane.showMessageDialog(null, "You have purchased " + qty + " of the " +a1+ ". Your total will now be " + total);
  43.  
  44. // Need to add confirm on this part = "Shop more? Select 'No' to proceed to checkout"
  45.  
  46. }
  47.  
  48. else if (monitorbrand.equalsIgnoreCase(b1))
  49. {
  50. double Asusprice = 9500;
  51. JOptionPane.showMessageDialog(null, "You have chosen " + b1 + ". the price for this is " + Asusprice );
  52. int qty = Integer.parseInt (JOptionPane.showInputDialog("Please enter quantity"));
  53.  
  54. double total = Asusprice*qty;
  55. bill.println(Asusprice*qty);
  56. bill.close();
  57.  
  58. JOptionPane.showMessageDialog(null, "You have purchased " + qty + " of the " + b1 + ". Your total will now be " + total);
  59. }
  60.  
  61.  
  62.  
  63. Scanner infile = new Scanner (new FileReader("bill.txt"));
  64.  
  65. double flgprice;
  66. flgprice = infile.nextDouble();
  67.  
  68. JOptionPane.showMessageDialog(null, "Your total is " + flgprice);
  69.  
  70.  
  71. }
  72. }
  73.  
  74.  
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement