انشئت ميثود create order ومن المفترض بعد ما بيختار العميل الطلبات بتترسل معلومات العميل المدخلة والطلبات المختارة الى هذه الميثود وحساب السعر الاجمالي
ولكن المشكلة انو بتطبع الطلب الاخير اللي اختارو العميل ما بتطبع كل الطلبات وايضا ما بتحسب السعر الاجمالي ايش الحل؟
بتاريخ 12 ساعات قال RAA:
انشئت ميثود create order ومن المفترض بعد ما بيختار العميل الطلبات بتترسل معلومات العميل المدخلة والطلبات المختارة الى هذه الميثود وحساب السعر الاجمالي
ولكن المشكلة انو بتطبع الطلب الاخير اللي اختارو العميل ما بتطبع كل الطلبات وايضا ما بتحسب السعر الاجمالي ايش الحل؟
//main class import java.io.IOException;import java.util.ArrayList;import java.util.Scanner;publicclassSuperMarket{publicstaticvoid main(String[] args) throws IOException{Scanner input =newScanner(System.in);//Customer class partScanner readIn =newScanner(System.in);ArrayList<Customer> customers =newArrayList<>();Customer cr=newCustomer();Invoices text=newInvoices();Product p =newProduct();int choice =0;do{System.out.println("\n----------------------------");System.out.println("1- Enter (1) to add new Customer");System.out.println("2- Enter (2) to add products");System.out.println("3- Enter (3) to see the Invoice");System.out.println("4- Enter (4) to exit");System.out.println(">>>> Enter your choice :");String name = null;int number =0;String email = null;
choice=readIn.nextInt();if(choice==1){
readIn.nextLine();System.out.println("Enter Customer name : ");
name = readIn.nextLine();System.out.println("Enter Customer number : ");
number = readIn.nextInt();
readIn.nextLine();System.out.println("Enter Customer email : ");
email = readIn.nextLine();
cr =newCustomer(name,number,email);
cr.WritingInFile();}//Product and invoice class partif(choice==2){ArrayList<Product>list=newArrayList<>();Product p1 =newProduct("Apple","Fruits and Vegetables section",340,15.5);Product p2 =newProduct("Saudi coffee","Roaster section",451,35.25);Product p3 =newProduct("Chocolate","Sweets section",562,40);Product p4 =newProduct("Spanish Nuts Pie","Bakery section",673,70);Product p5 =newProduct("Rasberry jam","Canned section",784,28);Product p6 =newProduct("carrot","Fruits and Vegetables section",341,20);Product p7 =newProduct("Nuts","Roaster section",452,25);Product p8 =newProduct("Candies","Sweets section",563,45);Product p9 =newProduct("French bakery","Bakery section",674,60);Product p10 =newProduct("Mushrooms","Canned section",785,35);Product p11 =newProduct("watermelon","Fruits and Vegetables section",342,10);Product p12 =newProduct("Roasted coffee","Roaster section",453,80);Product p13 =newProduct("Biscuit","Sweets section",564,30);Product p14 =newProduct("Corn bread","Bakery section",675,39);Product p15 =newProduct("White honey","Canned section",786,58.75);System.out.println();list.add(p1);list.add(p2);list.add(p3);list.add(p4);list.add(p5);list.add(p6);list.add(p7);list.add(p8);list.add(p9);list.add(p10);list.add(p11);list.add(p12);list.add(p13);list.add(p14);list.add(p15);int select =0;do{System.out.println("To display the list of all products, please select the number -1-");System.out.println("To search for a product and its availability, please choose the number -2-");System.out.println("To select specific products, please choose the number -3-");System.out.println("To complete the order and purchase please choose the number -4-");System.out.println("To exit please choose the number -5-");System.out.println(">>>>> Enter your choice:");
select = input.nextInt();switch(select){case1:System.out.println("-----Products List-----\n"+list.toString());break;case2:System.out.println("Dear customer, enter the name of the product you want to search for, and upon completion, enter the word Done");StringProductName= input.next();while(!"Done".equals(ProductName)){String pe =Product.Search(list,ProductName);System.out.println("Dear customer, enter the name of the product you want to search for, and upon completion, enter the word done");ProductName= input.next();}break;case3:System.out.println("Dear customer, enter the ID of the product you want to choose, and when finished, enter the number 0");intProductID= input.nextInt();while(ProductID!=0){
p =Product.SelectProducts(list,ProductID);System.out.println("Dear customer, enter the ID of the product you want to choose, and when finished, enter the number 0");ProductID= input.nextInt();}break;case4://Product p = new Product();Invoices bill =newInvoices(cr,p);System.out.print(bill);break;}System.out.println("\n----------------------------");}while(select!=5);}if(choice==3){Invoices bill =newInvoices(cr,p);System.out.print(bill);}}while(choice!=4);System.out.println("\nThank you for shopping from the \"one click\" supermarket");}}//product classimport java.util.ArrayList;publicclassProduct{privateString productsName;privateString productsType;privateint productsID;privatedouble productsPrice;privateObjectlist;publicProduct(){
productsName= null;
productsType= null;
productsID =0;
productsPrice =0.0;}publicProduct(String productsName,String productsType,int productsID,double productsPrice){this.productsName = productsName;this.productsType = productsType;this.productsID = productsID;this.productsPrice = productsPrice;}Product(Product product0){}publicvoid setproductsName(String productsName){this.productsName = productsName;}publicvoid setproductsType(String productsType){this.productsType = productsType;}publicvoid setproductsID(int productsID){this.productsID = productsID;}publicvoid setproductsPrice(int productsPrice){this.productsPrice = productsPrice;}publicString getproductsName(){returnthis.productsName;}publicString getproductsType(){returnthis.productsType;}publicint getproductsID(){returnthis.productsID;}publicdouble getproductsPrice(){returnthis.productsPrice;}publicString toString(){String str ="\nProducts name : "+ productsName +"\nProducts type: "+ productsType +"\nProducts ID: "+ productsID +"\n Products price: "+productsPrice+"SR";return str;}publicstaticStringSearch(ArrayList<Product>list,String productsName){for(int i =0; i<list.size();i++){String currentProductName =list.get(i).getproductsName();if(productsName.equals(currentProductName)){System.out.println("This product is available");System.out.println("informations related to this product:\n"+list.get(i));return currentProductName;}}System.out.println("Sorry,this product is not available");return null;}publicstaticProductSelectProducts(ArrayList<Product>list,int productsID){for(int i =0; i <list.size(); i++){Product currentProduct =list.get(i);int currentProductID = currentProduct.getproductsID();if(productsID == currentProductID){System.out.println("informations related to this product ID:\n"+list.get(i));return currentProduct;}}System.out.println("Sorry but this product ID is wrong");return null;}}//customer classimport java.io.File;import java.io.FileNotFoundException;import java.io.FileWriter;import java.io.IOException;import java.io.PrintWriter;import java.util.Scanner;publicclassCustomer{String name;int number;String email;privateString nameOfCustomer;privateint phoneNumber;privateString emailCustomer;publicCustomer(){this.nameOfCustomer="";this.phoneNumber=0;this.emailCustomer="";}publicCustomer(String nameOfCustomer,int phoneNumber,String emailCustomer){this.nameOfCustomer = nameOfCustomer;this.phoneNumber = phoneNumber;this.emailCustomer = emailCustomer;}Customer(Customer customer0){}publicString getNameOfCustomer(){return nameOfCustomer;}publicint getPhoneNumber(){return phoneNumber;}publicString getEmailCustomer(){return emailCustomer;}publicvoid setNameOfCustomer(String nameOfCustomer){this.nameOfCustomer = nameOfCustomer;}publicvoid setPhoneNumber(int phoneNumber){this.phoneNumber = phoneNumber;}publicvoid setEmailCustomer(String emailCustomer){this.emailCustomer = emailCustomer;}publicString toString(){String data;
data="Customer name : "+this.nameOfCustomer+"\nCustomer phone number : "+this.phoneNumber+"\nCustomer email : "+this.emailCustomer;return data;}publicvoidWritingInFile() throws IOException{FileWriter myFile=newFileWriter("Customer information.txt",true);PrintWriter write=newPrintWriter(myFile);
write.print(this.nameOfCustomer+"\t");
write.print(this.phoneNumber+"\t");
write.print(this.emailCustomer+"\t");
write.close();}publicvoid displayInformation() throws FileNotFoundException{System.out.println("Customer name\t phone number\t Customer email");File file =newFile("Customer information.txt");Scanner readIn =newScanner(file);while(readIn.hasNext()){String line =readIn.nextLine();System.out.println(line);}
readIn.close();}}//invoices classimport java.util.ArrayList;publicclassInvoices{privatestaticintArrayList;privatedouble total=0;Customer customer;Product product;//Product product;//Customer Customer1;publicInvoices(Product product0,int total0,Customer customer0){this.product =newProduct(product0);this.total=total;this.customer=newCustomer(customer0);}publicInvoices(){this.product=null;this.total=0;this.customer=null;}publicInvoices(Customer c,Product p ){
customer = c;
product = p;}publicProduct getProduct(){returnnewProduct(product);}publicvoid setProduct(Product product){this.product =newProduct(product);}publicdouble gettotal(){return total;}publicvoid settotal(int total){this.total = total;}publicCustomer getCustomer(){returnnewCustomer(customer);}publicvoid setCustomer(Customer customer){this.customer =newCustomer(customer);}publicString toString(){String text="Invoices information :\n"+"Customer information :"+ customer
+"\nThe products :\n"+ product
+"\nThe total price :"+ total ;return text;}publicvoid creatOrder(ArrayList<Product> list1,ArrayList<Product> list2){for(int i =0; i < list1.size(); i++){int currentProductID1 = list1.get(i).getproductsID();for(int j =0; j < list2.size(); j++){int currentProductID2 = list2.get(j).getproductsID();if(currentProductID1 == currentProductID2){
total +=list2.get(i).getproductsPrice();//list1.get(i).getproductsPrice();break;}}
السؤال
RAA
انشئت ميثود create order ومن المفترض بعد ما بيختار العميل الطلبات بتترسل معلومات العميل المدخلة والطلبات المختارة الى هذه الميثود وحساب السعر الاجمالي
ولكن المشكلة انو بتطبع الطلب الاخير اللي اختارو العميل ما بتطبع كل الطلبات وايضا ما بتحسب السعر الاجمالي ايش الحل؟
9 أجوبة على هذا السؤال
Recommended Posts
انضم إلى النقاش
يمكنك أن تنشر الآن وتسجل لاحقًا. إذا كان لديك حساب، فسجل الدخول الآن لتنشر باسم حسابك.