Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // What the system lacks atm:
- > how to let it run from the top if the user opts to "shop more"
- > how to add up all of the user's purchased items
- > More items...
- package HomePrac;
- import java.io.FileNotFoundException;
- import javax.swing.JOptionPane;
- import java.io.FileReader;
- import java.io.PrintWriter;
- import java.util.*;
- public class FilePrinter {
- public static void main(String[] args) throws FileNotFoundException {
- PrintWriter bill = new PrintWriter ("bill.txt");
- String a = "Monitor" ,b = "Processor", c = "RAM";
- String a1 = "LG", b1 = "Asus", c1 = "Acer";
- String item = JOptionPane.showInputDialog("Please enter what item you are looking for");
- if (item.equalsIgnoreCase(a))
- {
- JOptionPane.showMessageDialog(null, "You have chosen " +a+ "s");
- String monitorbrand = JOptionPane.showInputDialog("Please enter the brand you want. These are our current available ones:" + "\n" + a1 + "\n" + b1 + "\n" + c1);
- if (monitorbrand.equalsIgnoreCase(a1))
- {
- double lgprice = 8000;
- JOptionPane.showMessageDialog(null, "You have chosen " + a1 + ". the price for this is " + lgprice );
- int qty = Integer.parseInt(JOptionPane.showInputDialog("Please enter quantity"));
- double total = lgprice*qty;
- bill.println(total); // Prints the value of selected String to the txt file, so it could be calculated and outputed later on for checkout
- bill.close();
- JOptionPane.showMessageDialog(null, "You have purchased " + qty + " of the " +a1+ ". Your total will now be " + total);
- // Need to add confirm on this part = "Shop more? Select 'No' to proceed to checkout"
- }
- else if (monitorbrand.equalsIgnoreCase(b1))
- {
- double Asusprice = 9500;
- JOptionPane.showMessageDialog(null, "You have chosen " + b1 + ". the price for this is " + Asusprice );
- int qty = Integer.parseInt (JOptionPane.showInputDialog("Please enter quantity"));
- double total = Asusprice*qty;
- bill.println(Asusprice*qty);
- bill.close();
- JOptionPane.showMessageDialog(null, "You have purchased " + qty + " of the " + b1 + ". Your total will now be " + total);
- }
- Scanner infile = new Scanner (new FileReader("bill.txt"));
- double flgprice;
- flgprice = infile.nextDouble();
- JOptionPane.showMessageDialog(null, "Your total is " + flgprice);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement