Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package superMarket;
- import java.awt.Dimension;
- import java.awt.Font;
- import java.awt.Insets;
- import java.awt.TextArea;
- import java.awt.TextField;
- import java.util.ArrayList;
- import javax.swing.JFrame;
- public class Trolley {
- //lists
- static float priceWeight = 0;
- static ArrayList<Double> totalPrice = new ArrayList<Double>();
- static ArrayList<String> listFruit = new ArrayList<String>();
- static ArrayList<Float> amountList = new ArrayList<Float>();
- static float finalPrice = 0, finalWeight;
- static TextArea fruits, price, basketPrice, basketWeight;
- static boolean finished;
- static JFrame frame;
- public Trolley(int fruitType) {
- }
- public static void addItemBasket(String sName, float pricePerKG , boolean finished, float weight){
- Font textFont = new Font("Sans", Font.PLAIN, 24);
- frame = new JFrame("Receipt");
- priceWeight = pricePerKG * weight;
- double newPriceWeight = Math.round(priceWeight*100.0)/100.0;
- listFruit.add(sName);
- totalPrice.add(newPriceWeight);
- amountList.add(weight);
- finalPrice += newPriceWeight;
- finalWeight += weight;
- fruits = new TextArea("The fruits you chose: " + listFruit + "\n" + " The amount of each fruit:" + amountList);
- price = new TextArea( "The price of your fruits: " + totalPrice );
- basketPrice = new TextArea("Total Price of your trolley: £" +finalPrice);
- basketWeight = new TextArea("Total Weight of basket in KG: " + finalWeight);
- Insets insets = frame.getInsets();
- Dimension size = fruits.getPreferredSize();
- fruits.setBounds(10 + insets.left, 10 + insets.top, size.width, size.height);
- fruits.setSize(1920/2,300);
- fruits.setFont(textFont);
- price.setBounds(970 + insets.left, 10 + insets.top, size.width, size.height);
- price.setSize(1920/2, 300);
- price.setFont(textFont);
- basketPrice.setBounds(10 + insets.left, 310 + insets.top, size.width, size.height);
- basketPrice.setSize(960, 300);
- basketPrice.setFont(textFont);
- basketWeight.setBounds(970 + insets.left, 310 + insets.top, size.width, size.height);
- basketWeight.setSize(960, 300);
- basketWeight.setFont(textFont);
- frame.setSize(1920, 1080);
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- frame.setResizable(false);
- frame.setLocationRelativeTo(null);
- frame.setLayout(null);
- if(finished == false){
- frame.getContentPane().add(fruits);
- frame.getContentPane().add(price);
- frame.getContentPane().add(basketPrice);
- frame.getContentPane().add(basketWeight);
- }
- }
- public static void printBasket(){
- frame.setVisible(true);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement