Advertisement
youmed

Trolley

Nov 3rd, 2013
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package  superMarket;
  2.  
  3.  
  4. import java.awt.Dimension;
  5. import java.awt.Font;
  6. import java.awt.Insets;
  7. import java.awt.TextArea;
  8. import java.awt.TextField;
  9. import java.util.ArrayList;
  10.  
  11. import javax.swing.JFrame;
  12.  
  13. public class Trolley {
  14.  
  15.  
  16.     //lists
  17.     static float priceWeight = 0;
  18.      static ArrayList<Double> totalPrice = new ArrayList<Double>();
  19.      static ArrayList<String> listFruit = new ArrayList<String>();
  20.      static ArrayList<Float> amountList = new ArrayList<Float>();
  21.      static float finalPrice = 0, finalWeight;
  22.      static TextArea fruits, price, basketPrice, basketWeight;
  23.      static boolean finished;
  24.     static JFrame frame;
  25.    
  26.     public Trolley(int fruitType) {
  27.  
  28.    
  29.    
  30.        
  31.    
  32.    
  33.     }
  34.    
  35.     public static void addItemBasket(String sName, float pricePerKG , boolean finished, float weight){
  36.        
  37.         Font textFont = new Font("Sans", Font.PLAIN, 24);
  38.         frame = new JFrame("Receipt");
  39.         priceWeight = pricePerKG * weight;
  40.         double newPriceWeight = Math.round(priceWeight*100.0)/100.0;
  41.         listFruit.add(sName);
  42.         totalPrice.add(newPriceWeight);
  43.         amountList.add(weight);
  44.        
  45.        
  46.  
  47.          finalPrice += newPriceWeight;
  48.          finalWeight += weight;
  49.        
  50.         fruits = new TextArea("The fruits you chose:  " + listFruit + "\n" +  " The amount of each fruit:" + amountList);
  51.          price = new TextArea( "The price of your fruits: " + totalPrice );
  52.           basketPrice = new TextArea("Total Price of your trolley:  £" +finalPrice);
  53.          basketWeight = new TextArea("Total Weight of basket in KG: " + finalWeight);
  54.        
  55.          
  56.          Insets insets = frame.getInsets();
  57.          Dimension size = fruits.getPreferredSize();
  58.          fruits.setBounds(10 + insets.left, 10 + insets.top, size.width, size.height);
  59.          fruits.setSize(1920/2,300);
  60.          fruits.setFont(textFont);
  61.          
  62.          price.setBounds(970 + insets.left, 10 + insets.top, size.width, size.height);
  63.          price.setSize(1920/2, 300);
  64.          price.setFont(textFont);
  65.          
  66.          basketPrice.setBounds(10 + insets.left, 310 + insets.top, size.width, size.height);
  67.          basketPrice.setSize(960, 300);
  68.          basketPrice.setFont(textFont);
  69.          
  70.          basketWeight.setBounds(970 + insets.left, 310 + insets.top, size.width, size.height);
  71.          basketWeight.setSize(960, 300);
  72.          basketWeight.setFont(textFont);
  73.          
  74.          
  75.          frame.setSize(1920, 1080);
  76.          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  77.          frame.setResizable(false);
  78.          frame.setLocationRelativeTo(null);
  79.          frame.setLayout(null);
  80.          
  81.         if(finished == false){
  82.             frame.getContentPane().add(fruits);
  83.              frame.getContentPane().add(price);
  84.              frame.getContentPane().add(basketPrice);
  85.             frame.getContentPane().add(basketWeight);
  86.            
  87.            
  88.            
  89.        
  90.            
  91.            
  92.            
  93.         }
  94.         }
  95.    
  96.     public static void printBasket(){
  97.        
  98.          frame.setVisible(true);
  99.     }
  100.        
  101.    
  102.  
  103.  
  104.    
  105.  
  106.    
  107.        
  108.  
  109.        
  110.        
  111.        
  112.    
  113.        
  114.            
  115.        
  116.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement