/*************************** Programmed by : Dodie Pecayo Batoctoy - 0528-0503I2017 Java Application Programming (CS214) Assignment T1 - 2005 http://www.geocities.com/myfavoritecreator/java/assignment_T105/ ******************************/ import java.io.*; public class T105{ static Food c1,c2,c3,p1,p2,k1,k2; //----- declare them all //****** // START HERE //********* public static void main (String[]args) throws Exception { //------ assign them all c1=new Food(2,0,20.00,36.00); // ---------cheese cake c2=new Food(4,0,16.00,30.00); //-------chocolate cake c3=new Food(2,0,12.00,28.00); //-----Strawberry cake p1=new Food(20,0,0.50,1.20); //---- Egg pastry p2=new Food(20,0,0.40,1.20); //----Pineapple pastry k1=new Food(100,0,0.20,0.80); //-----Pecan and Nuts Cookies k2=new Food(100,0,0.30,0.70); //---- Chocolate chips Cookies char choice='f'; //---------- display do{ System.out.println("\n Famous Bakery, Madamme Memziers\n\n" + "Category________Favorite_________Qty Prepared______Qty Sold________Selling Price\n" + "Cake [c1]Cheese "+c1.prepared()+" "+c1.sold()+" "+c1.selling_price()+"\n"+ " [c2]Chocolate "+c2.prepared()+" "+c2.sold()+" "+c2.selling_price()+"\n"+ " [c3]Cheese "+c3.prepared()+" "+c3.sold()+" "+c3.selling_price()+"\n"+ "Pastry [p1]Egg "+p1.prepared()+" "+p1.sold()+" "+p1.selling_price()+"\n"+ " [p2]Pineapple "+p2.prepared()+" "+p2.sold()+" "+p2.selling_price()+"\n"+ "Cookie [k1]Pecans and Nuts "+k1.prepared()+" "+k1.sold()+" "+k1.selling_price()+"\n"+ " [k2]Chocolate Chips "+k2.prepared()+" "+k2.sold()+" "+k2.selling_price()+"\n"+ "-----------------------------------------------------------------\n"+ "[S]ales [D]aily Order [C]ollection [E]xit "); System.out.print("Enter choice: "); choice=(char)System.in.read(); EnterKey(); // absorb enter key..... //---------- SELECTION----------- switch(choice){ case 'S': case 's': Sales(); break; case 'D': case 'd': DailyOrder(); break; case 'C': case 'c': Collection(); break; case 'E': case 'e': System.out.print("Bye\n"); choice='e'; break; default: System.out.println("error input \n"); } }while(choice!='e'); } //**************************** //----------- DISPLAY THEM ALL //*************************** public static void Collection()throws Exception{ double c1_p=c1.prepared(),c2_p=c2.prepared(),c3_p=c3.prepared(), p1_p=p1.prepared(),p2_p=p2.prepared(), k1_p=k1.prepared(),k2_p=k2.prepared(); int c1_s=c1.sold(),c2_s=c2.sold(),c3_s=c3.sold(), p1_s=p1.sold(),p2_s=p2.sold(), k1_s=k1.sold(),k2_s=k2.sold(); double c1_c=c1.cost_price(),c2_c=c2.cost_price(),c3_c=c3.cost_price(), p1_c=p1.cost_price(),p2_c=p2.cost_price(), k1_c=k1.cost_price(),k2_c=k2.cost_price(); double c1_se=c1.selling_price(),c2_se=c2.selling_price(),c3_se=c3.selling_price(), p1_se=p1.selling_price(),p2_se=p2.selling_price(), k1_se=k1.selling_price(),k2_se=k2.selling_price(); System.out.println("\n Famous Bakery, Madamme Memziers\n\n" + "Category_Code___Prepared____Sold_____Cost_____Selling______Difference\n" + "Cake [c1] "+c1_p+" "+c1_s+" "+(c1_c*c1_p)+" "+(c1_se*c1_p)+" "+ ( (c1_se*c1_p)-(c1_c*c1_p) ) +"\n"+ " [c2] "+c2_p+" "+c2_s+" "+(c2_c*c2_p)+" "+(c2_se*c2_p)+" "+ ( (c2_se*c2_p)-(c2_c*c2_p) ) +"\n"+ " [c3] "+c3_p+" "+c3_s+" "+(c3_c*c3_p)+" "+(c3_se*c3_p)+" "+ ( (c3_se*c3_p)-(c3_c*c3_p) ) +"\n"+ "Pastry [p1] "+p1_p+" "+p1_s+" "+(p1_c*p1_p)+" "+(p1_se*p1_p)+" "+ ( (p1_se*p1_p)-(p1_c*p1_p) ) +"\n"+ " [p2] "+p2_p+" "+p2_s+" "+(p2_c*p2_p)+" "+(p2_se*p2_p)+" "+ ( (p2_se*p2_p)-(p2_c*p2_p) ) +"\n"+ "Cookie [k1] "+k1_p+" "+k1_s+" "+(k1_c*k1_p)+" "+(k1_se*k1_p)+" "+ ( (k1_se*k1_p)-(k1_c*k1_p) ) +"\n"+ " [k2] "+k2_p+" "+k2_s+" "+(k2_c*k2_p)+" "+(k2_se*k2_p)+" "+ ( (k2_se*k2_p)-(k2_c*k2_p) ) +"\n"+ "-----------------------------------------------------------------\n"+ "Total "+( (c1_c*c1_p)+(c2_c*c2_p)+(c3_c*c3_p)+(p1_c*p1_p)+(p2_c*p2_p)+(k1_c*k1_p)+(k2_c*k2_p) )+ //------total cost " "+ ( (c1_se*c1_p)+(c2_se*c2_p)+(c3_se*c3_p)+(p1_se*p1_p)+(p2_se*p2_p)+(k1_se*k1_p)+(k2_se*k2_p) ) + //------ total selling " "+ ( ((c1_se*c1_p)-(c1_c*c1_p))+((c2_se*c2_p)-(c2_c*c2_p))+((c3_se*c3_p)-(c3_c*c3_p))+ ((p1_se*p1_p)-(p1_c*p1_p))+((p2_se*p2_p)-(p2_c*p2_p))+ ((k1_se*k1_p)-(k1_c*k1_p))+((k2_se*k2_p)-(k2_c*k2_p)) ) + //-------- Total difference " \n"+ "Press Enter key "); EnterKey(); } //************************** //------- DAILY ORDER //************************** public static void DailyOrder()throws IOException,Exception{ boolean insufficient=Checker();//----------check if insufficient quantity if(insufficient==true){ System.out.print("\n\nInsufficient Quantity\nPlease Come again.....\n\nPress Enter Key...\n"); EnterKey(); } else{ Sales(); //------ call sales again..... } } //------This method checks all food if insufficient //PARAMETERS - NONE //RETURN VALUE - true or false //-------------- public static boolean Checker(){ boolean insufficient=false; if(c1.sold()>=c1.prepared()){ insufficient=true; } if(c2.sold()>=c2.prepared()){ insufficient=true; } if(c3.sold()>=c3.prepared()){ insufficient=true; } if(p1.sold()>=p1.prepared()){ insufficient=true; } if(p2.sold()>=p2.prepared()){ insufficient=true; } if(k1.sold()>=k1.prepared()){ insufficient=true; } if(k2.sold()>=k2.prepared()){ insufficient=true; } return insufficient; } //************************** //------- SALES //************************** public static void Sales()throws Exception, IOException{ BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); char choice='f'; String productcode; int quantity=0; do{ System.out.print("\nItems sold:\n"); System.out.print("Enter product code: "); productcode=br.readLine().toUpperCase(); //---------- CHECK IF PRODUCT CODE IS CORRECT if(productcode.compareTo("C1")==0||productcode.compareTo("C2")==0||productcode.compareTo("C3")==0|| productcode.compareTo("P1")==0||productcode.compareTo("P2")==0|| productcode.compareTo("K1")==0||productcode.compareTo("K2")==0){ System.out.print("Enter Quantity:"); quantity=Integer.parseInt(br.readLine()); //----------SOLVE FOR THE QUANTITY SOLVEforQuantity(productcode,quantity); //------- CHECK IF MORE ITEMS OR NOT System.out.print("More Items[y/n]?: "); choice=(char)System.in.read(); EnterKey(); switch(choice){ case 'Y': case 'y': choice='y'; break; case 'N': case 'n': System.out.print("\nTotal amount due: $"+AmountDue()); EnterKey(); choice='n'; break; default: choice='y'; } } else{ System.out.print("Invalid product Code!\n"); } }while(choice!='n'); } //--------amount due after [sales] public static double AmountDue(){ double Total=0; Total= (c1.selling_price()*c1.sold()) + (c2.selling_price()*c2.sold()) + (c3.selling_price()*c3.sold())+ (p1.selling_price()*p1.sold())+ (p2.selling_price()*p2.sold())+ (k1.selling_price()*k1.sold())+ (k2.selling_price()*k2.sold()); return Total; } public static void SOLVEforQuantity(String productcode,int quantity){ int choice=0; if(productcode.compareTo("C1")==0){ choice=1; } if(productcode.compareTo("C2")==0){ choice=2; } if(productcode.compareTo("C3")==0){ choice=3; } if(productcode.compareTo("P1")==0){ choice=4; } if(productcode.compareTo("P2")==0){ choice=5; } if(productcode.compareTo("K1")==0){ choice=6; } if(productcode.compareTo("K2")==0){ choice=7; } switch(choice){ //---------increase quantity in each product case 1: c1.addsold(c1.sold()+quantity); break; case 2: c2.addsold(c2.sold()+quantity); break; case 3: c3.addsold(c3.sold()+quantity); break; case 4: p1.addsold(p1.sold()+quantity); break; case 5: p2.addsold(p2.sold()+quantity); break; case 6: k1.addsold(k1.sold()+quantity); break; case 7: k2.addsold(k2.sold()+quantity); break; } } public static void EnterKey()throws Exception{ //---- absorb Enter key System.in.read(); System.in.read(); } } /******************* CLASS FOOD........ *******************/ class Food{ private int prepared=0,sold=0; private double cost_price=0, selling_price=0; Food(int prepared, int sold,double cost_price, double selling_price){ //------ constructor this.prepared=prepared; this.sold=sold; this.cost_price=cost_price; this.selling_price=selling_price; } //METHODS......... public int prepared(){ // extract prepared return this.prepared; } public int sold(){ // extract sold return this.sold; } public void addsold(int num){ // assign sold this.sold=num; } public double cost_price(){ // extract cost price return this.cost_price; } public double selling_price(){ // extract selling price return this.selling_price; } }