اذهب إلى المحتوى

RAA

الأعضاء
  • المساهمات

    43
  • تاريخ الانضمام

  • تاريخ آخر زيارة

كل منشورات العضو RAA

  1. public class frame extends javax.swing.JFrame { private test ts; /** * Creates new form frame */ public frame() { initComponents(); } public boolean checkInput(String inputUser, String inputPass) throws FileNotFoundException, IOException{ FileReader in = new FileReader("Info.txt"); BufferedReader br = new BufferedReader(in); String line; while ((line = br.readLine()) != null){ if (line.contains(inputUser) && line.contains(inputPass)){ return true; } } in.close(); return false; } /** * This method is called from within the constructor to initialize the form. * WARNING: Do NOT modify this code. The content of this method is always * regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code"> private void initComponents() { jPanel1 = new javax.swing.JPanel(); jPanel2 = new javax.swing.JPanel(); jLabel2 = new javax.swing.JLabel(); jPanel3 = new javax.swing.JPanel(); jLabel1 = new javax.swing.JLabel(); jLabel4 = new javax.swing.JLabel(); jLabel3 = new javax.swing.JLabel(); jTextField1 = new javax.swing.JTextField(); jTextField2 = new javax.swing.JTextField(); jButton1 = new javax.swing.JButton(); jButton2 = new javax.swing.JButton(); jLabel5 = new javax.swing.JLabel(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); jLabel2.setIcon(new javax.swing.ImageIcon("C:\\Users\\MB\\Downloads\\wo.jpg")); // NOI18N javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2); jPanel2.setLayout(jPanel2Layout); jPanel2Layout.setHorizontalGroup( jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 650, javax.swing.GroupLayout.PREFERRED_SIZE) ); jPanel2Layout.setVerticalGroup( jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 380, Short.MAX_VALUE) ); jPanel3.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout()); jLabel1.setFont(new java.awt.Font("Arial Black", 3, 18)); // NOI18N jLabel1.setText("WELCOME"); jPanel3.add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(175, 45, -1, -1)); jLabel4.setFont(new java.awt.Font("Arial Black", 3, 18)); // NOI18N jLabel4.setText("User Name:"); jPanel3.add(jLabel4, new org.netbeans.lib.awtextra.AbsoluteConstraints(46, 121, 138, -1)); jLabel3.setFont(new java.awt.Font("Arial Black", 3, 18)); // NOI18N jLabel3.setText("Password:"); jPanel3.add(jLabel3, new org.netbeans.lib.awtextra.AbsoluteConstraints(46, 185, 138, -1)); jPanel3.add(jTextField1, new org.netbeans.lib.awtextra.AbsoluteConstraints(202, 125, 142, -1)); jPanel3.add(jTextField2, new org.netbeans.lib.awtextra.AbsoluteConstraints(202, 189, 142, -1)); jButton1.setBackground(new java.awt.Color(255, 255, 255)); jButton1.setFont(new java.awt.Font("Arial Black", 3, 14)); // NOI18N jButton1.setText("Sign in"); jButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton1ActionPerformed(evt); } }); jPanel3.add(jButton1, new org.netbeans.lib.awtextra.AbsoluteConstraints(158, 273, -1, -1)); jButton2.setBackground(new java.awt.Color(255, 255, 255)); jButton2.setFont(new java.awt.Font("Arial Black", 3, 14)); // NOI18N jButton2.setText("Sign up"); jButton2.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton2ActionPerformed(evt); } }); jPanel3.add(jButton2, new org.netbeans.lib.awtextra.AbsoluteConstraints(269, 273, -1, -1)); jLabel5.setIcon(new javax.swing.ImageIcon("C:\\Users\\MB\\Downloads\\owo.jpg")); // NOI18N jPanel3.add(jLabel5, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, -1, 380)); javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); jPanel1.setLayout(jPanel1Layout); jPanel1Layout.setHorizontalGroup( jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup() .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(0, 468, Short.MAX_VALUE)) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup() .addContainerGap(651, Short.MAX_VALUE) .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(37, 37, 37))) ); jPanel1Layout.setVerticalGroup( jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, 375, Short.MAX_VALUE)) ); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) ); pack(); }// </editor-fold> private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: String userName = jTextField1.getText(); String passWord = jTextField2.getText(); try { if(checkInput(userName, passWord)){ ts = new test(); } } catch (Exception e) { JOptionPane.showMessageDialog(null, "Error"); } dispose(); } private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: frame2 f2 = new frame2(); f2.show(); dispose(); } /** * @param args the command line arguments */ public static void main(String args[]) { /* Set the Nimbus look and feel */ //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) "> /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel. * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html */ try { for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { if ("Nimbus".equals(info.getName())) { javax.swing.UIManager.setLookAndFeel(info.getClassName()); break; } } } catch (ClassNotFoundException ex) { java.util.logging.Logger.getLogger(frame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (InstantiationException ex) { java.util.logging.Logger.getLogger(frame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { java.util.logging.Logger.getLogger(frame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(frame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } //</editor-fold> /* Create and display the form */ java.awt.EventQueue.invokeLater(new Runnable() { @Override public void run() { new frame().setVisible(true); } }); } private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: frame f1 = new frame(); f1.show(); dispose(); } private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: /* String name = jTextField1.getText(); String mobileNo = jTextField2.getText(); String email = jTextField3.getText(); String age = jTextField4.getText(); */ try { String name = jTextField1.getText(); String mobileNo = jTextField2.getText(); String email = jTextField3.getText(); String age = jTextField4.getText(); FileWriter Writer = new FileWriter("Info.txt", true); Writer.write("" + name + " " + mobileNo + " " + email + " " + age + " "); Writer.write(System.getProperty("line.separator")); Writer.close(); JOptionPane.showMessageDialog(null, "Success"); setVisible(false); new frame2().setVisible(true); ts = new test(); } catch (Exception e) { JOptionPane.showMessageDialog(null, "Error"); } } /** * @param args the command line arguments */ public static void main(String args[]) { /* Set the Nimbus look and feel */ //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) "> /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel. * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html */ try { for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { if ("Nimbus".equals(info.getName())) { javax.swing.UIManager.setLookAndFeel(info.getClassName()); break; } } } catch (ClassNotFoundException ex) { java.util.logging.Logger.getLogger(frame2.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (InstantiationException ex) { java.util.logging.Logger.getLogger(frame2.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { java.util.logging.Logger.getLogger(frame2.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(frame2.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } //</editor-fold> /* Create and display the form */ java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new frame2().setVisible(true); } }); } احتاج مساعدة بدي اربط ما بين 2 ويندوز انو اذا اليوزر ادخل بيانتو في الويندوز تبعت المعلومات بينتقل الى ويندوز اللوق ان وفي حالة ما ادخل بيانات وضغط على البوتون تبع الحفظ يخرجلو مسج انو ايرور ويجب عليه ادخال معلوماتو لينتقل الى ويندوز اللوق ان كيف ممكن تتعمل ؟
  2. في حالة بدي اعملها بدون فايل بجافا ممكن وكيف ؟
  3. عملت واجهة تسجيل دخول بدي اعمل كود يتحقق من اليوزر والباسوورد وينضافوا في ملف واذا كان تسجيل الدخول صحيح يحولوا على الويندوز الاخرى واحتاج مساعدة وشرح كيفف ممكن بدي اعملها
  4. قمت بتجربة الكود ولكن يحتوي على العديد من الايرور
  5. هل تعمل معك هذه الطريقة؟
  6. ما بيشتغل معي يا ليت تفرجيني بعد اذنك
  7. #include <iostream> #include <string> #include <cmath> using namespace std; int ConvertOctaltoDecimal ( int octal ) { int decimal = 0 , position =0 ; while ( octal > 0 ) { if(position < 3){ int temp = octal % 10 ; decimal = decimal + temp * pow( 8 , position ); octal = octal / 10; position = position + 1 ; } else { cout << "error, more then three digits"; return 0; } } return decimal ; } int CheckOctal ( int octal ) { while ( octal > 0 ) { int temp = octal % 10 ; if ( temp == 8 || temp ==9) { return 0 ; } octal = octal / 10 ; } return 1; } int main() { for (int i = 0; i < 3 ; i++){ cout << "\nPlease Enter octal number from three digits: \n"; int octal; cin >> octal; int check = 0 ; check = CheckOctal ( octal ); if( check == 0){ cout << "\nInvalid Input\n" ; } else { int decimal = 0; decimal = ConvertOctaltoDecimal ( octal ) ; if (decimal != 0){ cout << "This is decimal " << decimal << endl ; } }} return 0 ; }
  8. #include <iostream> #include <string> #include <cmath> using namespace std; int ConvertOctaltoDecimal ( int octal ) { int decimal = 0 , position =0 ; while ( octal > 0 ) { if(position < 3){ int temp = octal % 10 ; decimal = decimal + temp * pow( 8 , position ); octal = octal / 10; position = position + 1 ; } else { cout << "error, more then three digits"; return 0; } } return decimal ; } int CheckOctal ( int octal ) { while ( octal > 0 ) { int temp = octal % 10 ; if ( temp == 8 || temp ==9) { return 0 ; } octal = octal / 10 ; } return 1; } int main() { for (int i = 0; i < 3 ; i++){ cout << "\nPlease Enter octal number from three digits: \n"; int octal; cin >> octal; int check = 0 ; check = CheckOctal ( octal ); if( check == 0){ cout << "\nInvalid Input\n" ; } else { int decimal = 0; decimal = ConvertOctaltoDecimal ( octal ) ; if (decimal != 0){ cout << "This is decimal " << decimal << endl ; } }} return 0 ; } انا عملتو الكود بلغة سي بلس لكن بواجه صعوبة في تحويلو الى الاسمبلي ؟
  9. بدي من اليوزر انو يدخل 3 digits octal ويحولن الى رقم عشري ممكن مساعدة كيف بدي اعملوا ككود بالاسمبلي
  10. متل هيك void swapFirstLast() { node* helpPtr = head; if(head==nullptr) { int value=head->data; cout << "Error : cannot swap(the list has less than two nodes)"; } int temp = helpPtr->data; while (helpPtr != nullptr) { if (helpPtr->next == nullptr) { int value = helpPtr->data; helpPtr->data; } helpPtr = helpPtr->next; } node* helpPtr2 = head; helpPtr2->data; };
  11. لما بدي ادخل زيرو احتاج انو يطبعلي انو الليست فاضية وانو باقي العمليات ما حتتنفذ لكن ما بيحصل هيك ايه المشكلة
  12. import java.util.ArrayList; public class Product { private String productsName; private String productsType; private int productsID; private double productsPrice; private Object list; public Product() { productsName= null; productsType= null; productsID = 0; productsPrice = 0.0; } public Product(String productsName,String productsType,int productsID,double productsPrice) { this.productsName = productsName; this.productsType = productsType; this.productsID = productsID; this.productsPrice = productsPrice; } Product(Product product0) { } public void setproductsName(String productsName) { this.productsName = productsName; } public void setproductsType(String productsType) { this.productsType = productsType; } public void setproductsID(int productsID) { this.productsID = productsID; } public void setproductsPrice(int productsPrice) { this.productsPrice = productsPrice; } public String getproductsName() { return this.productsName; } public String getproductsType() { return this.productsType; } public int getproductsID() { return this.productsID; } public double getproductsPrice() { return this.productsPrice; } public String toString() { String str = "\nProducts name : " + productsName + "\nProducts type: " + productsType + "\nProducts ID: " + productsID + "\n Products price: "+productsPrice+"SR"; return str; } public static String Search(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; } public static Product SelectProducts(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; } } احتاح اعمل ميثود تدعى order تحفظ المنتجات التي تم اختيارها من الميثود selectProduct
  13. كيف استدعيها طيب؟ وبالنسبة للقائمة فين حتكون في كلاس البرودكت او في الميثود الخاصة CreateOrder?
  14. بالنسبة للملف تبع customers ايوا موجود وبيشتغل معايا وبشوف بيانات العميل بالنسبة لاستدعاء الدالة CreateOrder هيا case 4 في main class بالنسبة للنقطة الاخيرة اعملها كذا Arraylist<Product>list2?
  15. من المفترض انو لما ينتهي العميل من ادخال البيانات حقتو واختيار الطلبات تترسل المعلومات لل createOrder ولما بستدعيها حتتطبع معلومات العميل والمنتجات المختارة والسعر الاجمالي للمنتجات بيطبع معلومات العميل ولكن المشكلة انو ما بيطبع جميع المنتجات اللي اختارها العميل ولا بيحسب مجموع السعر الكلي للمنتجات المختارة
  16. وطيب ومشكلة عدم طباعة المنتجات كاملة اللي اختارها العميل؟ فقط بيطبع المنتج الاخير اللي اختارو العميل
  17. انشئت ميثود create order ومن المفترض بعد ما بيختار العميل الطلبات بتترسل معلومات العميل المدخلة والطلبات المختارة الى هذه الميثود وحساب السعر الاجمالي ولكن المشكلة انو بتطبع الطلب الاخير اللي اختارو العميل ما بتطبع كل الطلبات وايضا ما بتحسب السعر الاجمالي ايش الحل؟ //main class import java.io.IOException; import java.util.ArrayList; import java.util.Scanner; public class SuperMarket { public static void main(String[] args) throws IOException { Scanner input = new Scanner (System.in); //Customer class part Scanner readIn = new Scanner (System.in); ArrayList<Customer> customers = new ArrayList<>(); Customer cr= new Customer(); Invoices text=new Invoices(); Product p =new Product(); 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 = new Customer(name,number,email); cr.WritingInFile(); } //Product and invoice class part if (choice==2){ ArrayList<Product> list = new ArrayList<>(); Product p1 = new Product("Apple","Fruits and Vegetables section",340,15.5); Product p2 = new Product("Saudi coffee","Roaster section",451,35.25); Product p3 = new Product("Chocolate","Sweets section",562,40); Product p4 = new Product("Spanish Nuts Pie","Bakery section",673,70); Product p5 = new Product("Rasberry jam","Canned section",784,28); Product p6 = new Product("carrot","Fruits and Vegetables section",341,20); Product p7 = new Product("Nuts","Roaster section",452,25); Product p8 = new Product("Candies","Sweets section",563,45); Product p9 = new Product("French bakery","Bakery section",674,60); Product p10 = new Product("Mushrooms","Canned section",785,35); Product p11 = new Product("watermelon","Fruits and Vegetables section",342,10); Product p12 = new Product("Roasted coffee","Roaster section",453,80); Product p13 = new Product("Biscuit","Sweets section",564,30); Product p14 = new Product("Corn bread","Bakery section",675,39); Product p15 = new Product("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){ case 1: System.out.println("-----Products List-----\n"+list.toString()); break; case 2: System.out.println("Dear customer, enter the name of the product you want to search for, and upon completion, enter the word Done"); String ProductName = 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; case 3: System.out.println("Dear customer, enter the ID of the product you want to choose, and when finished, enter the number 0"); int ProductID = 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; case 4: //Product p = new Product(); Invoices bill = new Invoices(cr,p); System.out.print(bill); break; } System.out.println("\n----------------------------"); }while (select!=5); } if (choice==3){ Invoices bill = new Invoices(cr,p); System.out.print(bill); } }while(choice!=4); System.out.println("\nThank you for shopping from the \"one click\" supermarket"); } } //product class import java.util.ArrayList; public class Product { private String productsName; private String productsType; private int productsID; private double productsPrice; private Object list; public Product() { productsName= null; productsType= null; productsID = 0; productsPrice = 0.0; } public Product(String productsName,String productsType,int productsID,double productsPrice) { this.productsName = productsName; this.productsType = productsType; this.productsID = productsID; this.productsPrice = productsPrice; } Product(Product product0) { } public void setproductsName(String productsName) { this.productsName = productsName; } public void setproductsType(String productsType) { this.productsType = productsType; } public void setproductsID(int productsID) { this.productsID = productsID; } public void setproductsPrice(int productsPrice) { this.productsPrice = productsPrice; } public String getproductsName() { return this.productsName; } public String getproductsType() { return this.productsType; } public int getproductsID() { return this.productsID; } public double getproductsPrice() { return this.productsPrice; } public String toString() { String str = "\nProducts name : " + productsName + "\nProducts type: " + productsType + "\nProducts ID: " + productsID + "\n Products price: "+productsPrice+"SR"; return str; } public static String Search(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; } public static Product SelectProducts(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 class import java.io.File; import java.io.FileNotFoundException; import java.io.FileWriter; import java.io.IOException; import java.io.PrintWriter; import java.util.Scanner; public class Customer { String name; int number; String email; private String nameOfCustomer; private int phoneNumber; private String emailCustomer; public Customer() { this.nameOfCustomer=""; this.phoneNumber=0; this.emailCustomer=""; } public Customer(String nameOfCustomer, int phoneNumber, String emailCustomer) { this.nameOfCustomer = nameOfCustomer; this.phoneNumber = phoneNumber; this.emailCustomer = emailCustomer; } Customer(Customer customer0) { } public String getNameOfCustomer() { return nameOfCustomer; } public int getPhoneNumber() { return phoneNumber; } public String getEmailCustomer() { return emailCustomer; } public void setNameOfCustomer(String nameOfCustomer) { this.nameOfCustomer = nameOfCustomer; } public void setPhoneNumber(int phoneNumber) { this.phoneNumber = phoneNumber; } public void setEmailCustomer(String emailCustomer) { this.emailCustomer = emailCustomer; } public String toString(){ String data; data="Customer name : "+this.nameOfCustomer+"\nCustomer phone number : "+this.phoneNumber+ "\nCustomer email : "+this.emailCustomer; return data; } public void WritingInFile() throws IOException{ FileWriter myFile= new FileWriter("Customer information.txt",true); PrintWriter write= new PrintWriter(myFile); write.print(this.nameOfCustomer+"\t"); write.print(this.phoneNumber+"\t"); write.print(this.emailCustomer+"\t"); write.close(); } public void displayInformation() throws FileNotFoundException{ System.out.println("Customer name\t phone number\t Customer email"); File file = new File("Customer information.txt"); Scanner readIn = new Scanner(file); while(readIn.hasNext()){ String line =readIn.nextLine(); System.out.println(line); } readIn.close(); } } //invoices class import java.util.ArrayList; public class Invoices { private static int ArrayList; private double total=0; Customer customer; Product product; //Product product; //Customer Customer1; public Invoices (Product product0,int total0,Customer customer0){ this.product = new Product(product0); this.total=total; this.customer= new Customer(customer0); } public Invoices(){ this.product=null; this.total=0; this.customer=null; } public Invoices(Customer c,Product p ){ customer = c; product = p; } public Product getProduct() { return new Product (product); } public void setProduct(Product product) { this.product = new Product (product); } public double gettotal() { return total; } public void settotal(int total) { this.total = total; } public Customer getCustomer() { return new Customer (customer); } public void setCustomer(Customer customer) { this.customer = new Customer (customer); } public String toString(){ String text="Invoices information :\n" +"Customer information :"+ customer +"\nThe products :\n"+ product +"\nThe total price :" + total ; return text; } public void 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 ; } }
  18. عملت الميثود وبتشتغل معايا ولكن المشكلة بتاخذ منتج واحد مش كل المنتجات اللي بيختارها العميل //main class
  19. كلاس الفاتورة يتضمن ميثود Create order واحتاج منها تستقبل من كلاس العميل المعلومات اللي بيدخلها ومن كلاس المنتجات المنتجات اللي بيختارها العميل وفي النهاية يحسب الاجمالي
  20. احتاج مساعدة في التعديل على ميثود تستقبل ايضا بيانات العميل اللي بيدخلها
  21. //main class import java.io.IOException; import java.util.ArrayList; import java.util.Scanner; public class SuperMarket { public static void main(String[] args) throws IOException { Scanner input = new Scanner (System.in); Scanner readIn = new Scanner (System.in); ArrayList<Customer> customers = new ArrayList<>(); Customer cr= new Customer(); int choice; while (true){ System.out.println("1- Add new Customer :"); 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 = new Customer(name,number,email); cr.WritingInFile(); } //Product and invoice class part ArrayList<Product> list = new ArrayList<>(); Product p1 = new Product("Apple","Fruits and Vegetables section",340,15.5); Product p2 = new Product("Saudi coffee","Roaster section",451,35.25); Product p3 = new Product("Chocolate","Sweets section",562,40); Product p4 = new Product("Spanish Nuts Pie","Bakery section",673,70); Product p5 = new Product("Rasberry jam","Canned section",784,28); Product p6 = new Product("carrot","Fruits and Vegetables section",341,20); Product p7 = new Product("Nuts","Roaster section",452,25); Product p8 = new Product("Candies","Sweets section",563,45); Product p9 = new Product("French bakery","Bakery section",674,60); Product p10 = new Product("Mushrooms","Canned section",785,35); Product p11 = new Product("watermelon","Fruits and Vegetables section",342,10); Product p12 = new Product("Roasted coffee","Roaster section",453,70); Product p13 = new Product("Biscuit","Sweets section",564,30); Product p14 = new Product("Corn bread","Bakery section",675,39); Product p15 = new Product("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.print(">>>>>"); select = input.nextInt(); switch(select){ case 1: System.out.println("-----Products List-----\n"+list.toString()); break; case 2: System.out.println("Dear customer, enter the name of the product you want to search for, and upon completion, enter the word Done"); String ProductName = input.next(); while (!"Done".equals(ProductName)) { String p = 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; case 3: System.out.println("Dear customer, enter the ID of the product you want to choose, and when finished, enter the number 0"); int ProductID = input.nextInt(); while (ProductID != 0) { Product 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; case 4: break; } System.out.println("----------------------------"); }while (select!=5); } } } //invoices class import java.util.ArrayList; public class Invoices { private static int ArrayList; int total=0; private Customer customer; private Product product; public Invoices (String bill0,Product product0,int total0,Customer customer0){ this.product = new Product(product0); this.total=total; this.customer= new Customer(customer0); } public Invoices(){ this.product=null; this.total=0; this.customer=null; } public Product getProduct() { return new Product (product); } public void setProduct(Product product) { this.product = new Product (product); } public int gettotal() { return total; } public void setint(int total) { this.total = total; } public Customer getCustomer() { return new Customer (customer); } public void setCustomer(Customer customer) { this.customer = new Customer (customer); } public String toString(){ String text=""" Invoices information : Customer information : """+this.customer+ "\nThe products :\n"+this.product+"\nThe total price :" +this.total; return text; } public static void creatInoices(ArrayList<Product> list1, ArrayList<Product> list2) { double total=0; 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 += list1.get(i).getproductsPrice(); break ; } } } System.out.println("total is: " + total); } }
  22. الدالة تطبع المنتجات اللي اختارها العميل والمعلومات تبعتو والسعر الاجمالي //class customer import java.io.File; import java.io.FileNotFoundException; import java.io.FileWriter; import java.io.IOException; import java.io.PrintWriter; import java.util.Scanner; public class Customer { String name; int number; String email; private String nameOfCustomer; private int phoneNumber; private String emailCustomer; public Customer() { this.nameOfCustomer=""; this.phoneNumber=0; this.emailCustomer=""; } public Customer(String nameOfCustomer, int phoneNumber, String emailCustomer) { this.nameOfCustomer = nameOfCustomer; this.phoneNumber = phoneNumber; this.emailCustomer = emailCustomer; } Customer(Customer customer0) { throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody } public String getNameOfCustomer() { return nameOfCustomer; } public int getPhoneNumber() { return phoneNumber; } public String getEmailCustomer() { return emailCustomer; } public void setNameOfCustomer(String nameOfCustomer) { this.nameOfCustomer = nameOfCustomer; } public void setPhoneNumber(int phoneNumber) { this.phoneNumber = phoneNumber; } public void setEmailCustomer(String emailCustomer) { this.emailCustomer = emailCustomer; } public String toString(){ String data; data="Customer name : "+this.nameOfCustomer+"\nCustomer phone number : "+this.phoneNumber+ "\nCustomer email : "+this.emailCustomer; return data; } public void WritingInFile() throws IOException{ FileWriter myFile= new FileWriter("Customer information.txt",true); PrintWriter write= new PrintWriter(myFile); write.print(this.nameOfCustomer+"\t"); write.print(this.phoneNumber+"\t"); write.print(this.emailCustomer+"\t"); write.close(); } public void displayInformation() throws FileNotFoundException{ System.out.println("Customer name\t phone number\t Customer email"); File file = new File("Customer information.txt"); Scanner readIn = new Scanner(file); while(readIn.hasNext()){ String line =readIn.nextLine(); System.out.println(line); } readIn.close(); } } //class invoices import java.util.ArrayList; public class Invoices { public double total; private Customer customer; private Product product; public Invoices (double total0,Product product0,Customer customer0){ this.total=total0; this.product = new Product(product0); this.customer= new Customer(customer0); } public Invoices(){ this.total=0; this.product=null; this.customer=null; } public double getTotal() { return total; } public void setTotal(double total) { this.total = total; } public Product getProduct() { return new Product (product); } public void setProduct(Product product) { this.product = new Product (product); } public Customer getCustomer() { return new Customer (customer); } public void setCustomer(Customer customer) { this.customer = new Customer (customer); } public String toString(){ String text=""" Invoices information : Customer information : """+this.customer+ "\nThe products :\n"+this.product+"\nThe total price :" +this.total; return text; } public static void creatInoices(ArrayList<Product> list, int productsID) { double total=0; for (int i = 0; i < list.size(); i++) { Product currentProduct = list.get(i); int currentProductID = currentProduct.getproductsID(); if (productsID == currentProductID) { total+=list.get(i).getproductsPrice(); return ; } } System.out.println("Thank you"); } } الكود تبع الكلاسات ممكن توضح الفكرة اكثر كيف ممكن اعملها؟
  23. الكود //Class customer import java.io.File; import java.io.FileNotFoundException; import java.io.FileWriter; import java.io.IOException; import java.io.PrintWriter; import java.util.Scanner; public class Customer { String name; int number; String email; private String nameOfCustomer; private int phoneNumber; private String emailCustomer; public Customer() { this.nameOfCustomer=""; this.phoneNumber=0; this.emailCustomer=""; } public Customer(String nameOfCustomer, int phoneNumber, String emailCustomer) { this.nameOfCustomer = nameOfCustomer; this.phoneNumber = phoneNumber; this.emailCustomer = emailCustomer; } Customer(Customer customer0) { throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody } public String getNameOfCustomer() { return nameOfCustomer; } public int getPhoneNumber() { return phoneNumber; } public String getEmailCustomer() { return emailCustomer; } public void setNameOfCustomer(String nameOfCustomer) { this.nameOfCustomer = nameOfCustomer; } public void setPhoneNumber(int phoneNumber) { this.phoneNumber = phoneNumber; } public void setEmailCustomer(String emailCustomer) { this.emailCustomer = emailCustomer; } public String toString(){ String data; data="Customer name : "+this.nameOfCustomer+"\nCustomer phone number : "+this.phoneNumber+ "\nCustomer email : "+this.emailCustomer; return data; } public void WritingInFile() throws IOException{ FileWriter myFile= new FileWriter("Customer information.txt",true); PrintWriter write= new PrintWriter(myFile); write.print(this.nameOfCustomer+"\t"); write.print(this.phoneNumber+"\t"); write.print(this.emailCustomer+"\t"); write.close(); } public void displayInformation() throws FileNotFoundException{ System.out.println("Customer name\t phone number\t Customer email"); File file = new File("Customer information.txt"); Scanner readIn = new Scanner(file); while(readIn.hasNext()){ String line =readIn.nextLine(); System.out.println(line); } readIn.close(); } } import java.util.ArrayList; public class Invoices { public double total; private Customer customer; private Product product; public Invoices (double total0,Product product0,Customer customer0){ this.total=total0; this.product = new Product(product0); this.customer= new Customer(customer0); } public Invoices(){ this.total=0; this.product=null; this.customer=null; } public double getTotal() { return total; } public void setTotal(double total) { this.total = total; } public Product getProduct() { return new Product (product); } public void setProduct(Product product) { this.product = new Product (product); } public Customer getCustomer() { return new Customer (customer); } public void setCustomer(Customer customer) { this.customer = new Customer (customer); } public String toString(){ String text=""" Invoices information : Customer information : """+this.customer+ "\nThe products :\n"+this.product+"\nThe total price :" +this.total; return text; } public static void creatInoices() { System.out.println("Thank you"); } }
  24. public static void creatInoices(ArrayList<Product> list, int productsID) { double total=0; for (int i = 0; i < list.size(); i++) { Product currentProduct = list.get(i); int currentProductID = currentProduct.getproductsID(); if (productsID == currentProductID) { total+=list.get(i).getproductsPrice(); return ; } } System.out.println("Thank you"); } صحيح؟؟
  25. ايوا انا عملت كلاس المنتجات وكلاس للعملاء واحتاج ارسل المعلومات تبعهم الاثنين لكلاس الفاتورة
×
×
  • أضف...