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

Zeina Almakdisi

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

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

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

أجوبة بواسطة Zeina Almakdisi

  1. كود لتوضيح السؤال

    import java.lang.*;
    
    public class HelloWorld {
        public static void main(String args[]) {
                  
            int x = 7;
    
            int y = 3;   
            
            double z = 7 / 3;
            
        System.out.println(z); 
        }
    }

    أو

    public class HelloWorld {
        public static void main(String args[]) {
                  int x = 7;
    
            int y;   
            
            double z=4.5;
            
            y=(int)x+z;
        System.out.println(y); 
        }
    }

     

    • أعجبني 1
  2. مرحبا 

    اريد الاشتراك بالكورسات 

    لكن لدي بعض الاسئلة: 

    1_هل هذه الشهادة معترف عليها؟ 

    2_متى ينتهي اشتراكي في الدورة؟ 

    3_ ماذا يحصل أن لم انجح بالاختبار؟ هل يمكنني اعادته او اكون قد خسرت شهادة الدورة؟  

    • أعجبني 1
  3. قمت بإنشاء كلاس اسمه admin باستخدام طريقة التغليف

    وقمت بتجربة انشاء غرض ضمن كلاس main واريد طباعة الاسم 

    لكن لم ينجح الامر لوجود مشكلة 

    public class admin {
    
      private String First_Name;
      private String Last_Name;
    
      public String getFirst_Name() {          
        return First_Name;
      }
      public String getLast_Name() {          
        return Last_Name;
      }
      public void setFirst_Name(String n) {      
        First_Name = n;
      }
      public void setLast_Name (String L) {      
        Last_Name = L;
      }
    
      public class Main {
    
        public static void main(String[] args) {
          admin ad = new admin();
    
          ad.setFirst_Name="Majd";
          ad.setLast_Name="mm";
    
          System.out.print(First_Name);
    
          System.out.print(Last_Name);
        }
      }
    }

      

    • أعجبني 1
  4. قمت بإنشاء كلاس اسمه admin باستخدام طريقة التغليف

    وقمت بتجربة انشاء غرض ضمن كلاس main وادخال اسم 

    لكم لم ينجح الأمر لوجود مشكلة ماهي :(

    • public class admin {
       
          private String First_Name;
          private String Last_Name;
         // private int number;
         // private double salary;
        
         public String getFirst_Name() {          
              return First_Name;
          }
          public String getLast_Name() {          
              return Last_Name;
          }
         public void setFirst_Name(String n) {      
              First_Name = n;
          }
         public void setLast_Name (String L) {      
              Last_Name = L;
          }
        
        public class Main {
       
          public static void main(String[] args) {
             admin ad = new admin();
            
            ad.First_Name="Majd";
            ad.Last_Name="mm";
          }}
        
        

       

     

    • أعجبني 2
  5. public class Employee {
                           
        String name;       
        int    age;        
        double salary;    
     
    }
    public class Main {
     
        public static void main(String[] args) {
     
            
            name   = "Zeina";
            age    = 21;
            salary = 1500000;
    }}

    قمت بإنشاء كلاس إسمه Employee و فكرته تخزين معلومات الموظفين

    name ,salary,age
    بعدها قمت باضافة معلومات الموظف في الكلاس Main 

    لكن لم ينجح الأمر 

    أرجو المساعدة..

    • أعجبني 1
  6.  قمت بتعريف كلاس بداخله قمت بتعريف enumيمثل أيام الأسبوع إسمه Days
    لكن اريد في الدالة main() عرض قيمة رقم الـ Index الخاص في كل يوم

    هل يمكن المساعدة في ذلك

     enum Days {
            MONDAY,
            TUESDAY,
            WEDNESDAY,
            THURSDAY,
            FRIDAY,
            SATURDAY,
            SUNDAY
        }
        public static void main(String[] args) {
    
    }

     

    • أعجبني 1
  7. قمت بانشاء قائمة منسدلة بلغة HTML تتيح للمستخدم اختيار اللغة الخاصة به

    لكن اريد أن يكون العنصر المختار افتراضيا French كيف يمكنني فعل ذلك 

    الكود الذي أريد التعديل عليه

    <select >
      <option value="arabic">Arabic</option>
      <option value="english">English</option>
      <option value="french">French</option>
      <option value="spanish">Spanish</option>
    </select>

     

    • أعجبني 1
  8. قمت بانشاء صفحتين بلغة html 

    احتاج للمساعدة بحيث عند الضغط على الزر الموجود في الصفحة الأولى يتم فتح الصفحة الثانية 

         <ul class="navbar-nav text-uppercase ml-auto "  >
     <li class="nav-item"><a class="nav-link js-scroll-trigger"  target="_blank" >Home</a></li>
      <li class="nav-item"><a class="nav-link js-scroll-trigger" target="_blank" >track</a></li>
                                   </ul>

     

    • أعجبني 1
  9. لماذا لم يقم بعمل break , وكتب return

    if (answer == "Y") {
    	continue;
    }
    else if (answer == "N") {
    	return;
    }
    else
    {
    	return;
    }

    الشيفرة كاملة

    class Program
    {
      static void Main(string[] args)
      {
    
        while (true)
        {
    
          Random random = new Random();
    
          int correctNumber = random.Next(1, 10);
    
          int guess = 0;
    
          Console.WriteLine("Guess a number between 1 and 10");
    
          while (guess != correctNumber)
          {
            string input = Console.ReadLine();
    
            if (!int.TryParse(input, out guess))
            {
              Console.WriteLine("Please use an actual number");
    
              continue;
            }
    
            // Cast to int and put in guess
            guess = Int32.Parse(input);
    
            // Match guess to correct number
            if (guess != correctNumber)
            {
              // Print error message
              PrintColorMessage(ConsoleColor.Red, "Wrong number, please try again");
            }
          }
    
          // Print success message
          PrintColorMessage(ConsoleColor.Yellow, "CORRECT!! You guessed it!");
    
          // Ask to play again
          Console.WriteLine("Play Again? [Y or N]");
    
          // Get answer
          string answer = Console.ReadLine().ToUpper();
    
          if (answer == "Y") {
            continue;
          }
          else if (answer == "N") {
            return;
          }
          else
          {
            return;
          }
        }           
    
      }
    
    
    }

     

    • أعجبني 1
  10. عند تشغيل الواجهة لمشروع الجافا يظهر الخطأ 

    java.sql.SQLException: Operation not allowed for a result set of type ResultSet.TYPE_FORWARD_ONLY.
    	at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:129)
    	at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122)
    	at com.mysql.cj.jdbc.result.ResultSetImpl.last(ResultSetImpl.java:1752)
    	at DBconnection.ResultSetTableModel.setQuery(ResultSetTableModel.java:33)
    	at DBconnection.ResultSetTableModel.<init>(ResultSetTableModel.java:24)
    	at GUI.ST.<init>(ST.java:204)
    	at GUI.ST$1.run(ST.java:189)

    و الشيفرة التي سببت الخطأ :

    	public void setQuery(String query) throws SQLException {
    		// TODO Auto-generated method stub
    		resultSet = statement.executeQuery(query);
    		metaData= resultSet.getMetaData();
    		resultSet.last();
    
    		numberOfRows= resultSet.getRow();
    		fireTableStructureChanged();
    		
    	}

     

    • أعجبني 1
  11. لايسمح بادخال أي قيمة الى الحقول 

    package GUI;
    
    
    import java.awt.Color;
    import java.awt.EventQueue;
    ..
    
    import javax.swing.DefaultComboBoxModel;
    import javax.swing.Icon;
    import javax.swing.ImageIcon;
    ..
    
    import DBconnection.DbConnection;
    import DBconnection.ResultSetTableModel;
    
    ..
    
       public class ST
       {
    		private JFrame frmStack;
    		private JTextField textField_admin_edit_id;
    		private static final String DEFAULT_Query_employee = "SELECT * FROM employee";
    
    		private static final String url= "jdbc:mysql://localhost/stack?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC";               
    		private static final String userName = "root";
    		private static final String password ="123456";
    	
    			
    		private static DbConnection dbc;
    
    		private JTextField textField_Employee_edit_address;
    
    		
           public static void main (String[] args)
           {
               System.out.println("\n\n***** MySQL JDBC Connection Testing *****");
    		   Connection conn = null;
               try
               {
                   String userName = "root";
                   String password = "zeina123456";
             
                   String url = "jdbc:mysql://localhost/stack?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC";        
                   conn = DriverManager.getConnection (url, userName, password);
                   System.out.println ("\nDatabase Connection Established...");
                   JOptionPane.showMessageDialog(null, "Database Connection Established...");
               }
              catch (Exception ex)
               {
                  JOptionPane.showMessageDialog(null, "cannot connect to database server");
    		       System.err.println ("Cannot connect to database server");
    			   ex.printStackTrace();
               }      
    		   
    		   finally
               {
                   if (conn != null)
                   {
                       try
                       {
                           System.out.println("\n***** Let terminate the Connection *****");
                           JOptionPane.showMessageDialog(null, "Let terminate the Connection...");
    					   conn.close ();					   
                           System.out.println ("\nDatabase connection terminated...");
                       }
                       catch (Exception ex)
    
       {
    				   System.out.println ("Error in connection termination!");
    				   }
                   }
               }
    
           EventQueue.invokeLater(new Runnable() {
    			public void run() {
    				
    			
    				
    				
    		
    				try {
    					ST window = new ST();
    					window.frmStack.setVisible(true);
    				} catch (Exception e) {
    					e.printStackTrace();
    				}
    			}
    		});
    	}
    
    	
    	
    	public ST() {
    		initialize();
    		
    	}
    
    	
    	private void initialize() {
    		frmStack = new JFrame();
    		frmStack.setTitle("STACK");
    		frmStack.setBounds(100, 100, 1200, 750);
    		frmStack.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    		frmStack.getContentPane().setLayout(null);
    	
    		
    		JPanel panel_1 = new JPanel();
    		panel_1.addComponentListener(new ComponentAdapter() {
    			@Override
    			public void componentShown(ComponentEvent arg0) {
    				String sql= "Select * From admin";
    				ResultSet rs=dbc.runSelect(sql);
    				try {
    					rs.next();
    					textField_admin_edit_id.setText(rs.getString("Admin_Id"));
    					textField_admin_edit_fname.setText(rs.getString("First_Name"));
    					textField_admin_edit_lname.setText(rs.getString("Last_Name"));
    
    					rs.close();
    					
    				} catch (SQLException e) {
    					// TODO Auto-generated catch block
    					e.printStackTrace();
    				}
    			}
    		});
    		/*panel_1.addComponentListener(new ComponentAdapter() {
    			@Override
    			public void componentShown(ComponentEvent arg0) {
    				textField_admin_edit_id.setText(label_admin_info_id.getText());
    				textField_admin_edit_phone.setText(label_admin_info_phone.getText());
    			}
    		});
    		*/
    		JPanel panel = new JPanel();
    		tabbedPane_1.addTab("Info", null, panel, null);
    		panel.setLayout(null);
    		
    		JLabel lblNewLabel = new JLabel("ID");
    		lblNewLabel.setFont(new Font("Segoe Print", Font.BOLD, 25));
    		lblNewLabel.setBounds(42, 72, 162, 26);
    		panel.add(lblNewLabel);
    
    		
    		JLabel label_admin_info = new JLabel("");
    		label_admin_info.setBounds(556, 72, 305, 314);
    		panel.add(label_admin_info);
    		
    		tabbedPane_1.addTab("Edit", null, panel_1, null);
    		panel_1.setLayout(null);
    		
    		JLabel lblNewLabel_10 = new JLabel("ID");
    		lblNewLabel_10.setFont(new Font("Segoe Print", Font.BOLD, 21));
    		lblNewLabel_10.setBounds(27, 45, 125, 22);
    		panel_1.add(lblNewLabel_10);
    		
    		
    		textField_admin_edit_id = new JTextField();
    		textField_admin_edit_id.setEnabled(false);
    		textField_admin_edit_id.setBounds(260, 45, 145, 22);
    		panel_1.add(textField_admin_edit_id);
    		textField_admin_edit_id.setColumns(10);
    		
    		
    		JLabel lblAdminphoto = new JLabel("");
    		lblAdminphoto.setBounds(647, 45, 304, 314);
    		panel_1.add(lblAdminphoto);
    		
    		JButton btnNewButton = new JButton("Browse");
    		btnNewButton.setFont(new Font("Segoe Print", Font.BOLD, 15));
    		btnNewButton.addActionListener(new ActionListener() {
    			public void actionPerformed(ActionEvent arg0) {
    				JFileChooser jf=new JFileChooser();
    				jf.showOpenDialog(null);
    				try {
    					textField_admin_edit_image.setText(jf.getSelectedFile().getAbsolutePath());
    					Icon c = new ImageIcon(textField_admin_edit_image.getText());
    					lblAdminphoto.setIcon(c);
    					}
    					catch (NullPointerException e) {
    						
    					}
    			}
    		});
    		btnNewButton.setBounds(434, 269, 97, 31);
    		panel_1.add(btnNewButton);
    		
    		JButton btnEdit = new JButton("Edit");
    		btnEdit.setFont(new Font("Segoe Print", Font.BOLD, 25));
    		btnEdit.addActionListener(new ActionListener() {
    			
    			public void actionPerformed(ActionEvent arg0) {
    				
    				Admindao ad = new Admindao();
    				Admin adm = new Admin(textField_admin_edit_fname.getText(), textField_admin_edit_lname.getText(), textField_admin_edit_username.getText(), textField_admin_edit_phone.getText(),textField_admin_edit_id.getText(),textField_admin_edit_image.getText());
    				try {
    					ad.uptadeAdmin(dbc.getConnection(), adm);
    					JOptionPane.showMessageDialog(null, "admin updated succesufly");
    				} catch (SQLException e) {
    					// TODO Auto-generated catch block
    					e.printStackTrace();
    				}
    				
    				
    			}
    		});
    		btnEdit.setBounds(200, 513, 97, 30);
    		panel_1.add(btnEdit);
    		
    		
    		JPanel panel_2 = new JPanel();
    		panel_2.addComponentListener(new ComponentAdapter() {
    			@Override
    			public void componentShown(ComponentEvent arg0) {
    				String sql="select * from company ;";
    				ResultSet rs= dbc.runSelect(sql);
    				try {
    					rs.next();
    					textField_admin_company_name.setText( rs.getString("Name"));
    					textField_admin_company_address1.setText(rs.getString("Address1"));
    					textField_admin_company_address2.setText(rs.getString("Address2"));
    					textField_admin_company_phone1.setText(rs.getString("Phone1"));
    					textField_admin_company_phone2.setText(rs.getString("Phone2"));
    					textField_admin_company_website.setText(rs.getString("Website"));
    					textField_admin_company_postalcode.setText(rs.getString("PostalCode"));
    				} catch (SQLException e) {
    					// TODO Auto-generated catch block
    					e.printStackTrace();
    				}
    			}
    		});
    		
    		tabbedPane_1.addTab("Comapny", null, panel_2, "");
    		panel_2.setLayout(null);
    		
    
    		
    		JButton btnEdit_1 = new JButton("Edit");
    		btnEdit_1.addActionListener(new ActionListener() {
    			public void actionPerformed(ActionEvent arg0) {
    				Company comp = new Company(textField_admin_company_name.getText(), textField_admin_company_address1.getText(), textField_admin_company_address2.getText(), textField_admin_company_phone1.getText(), textField_admin_company_phone2.getText(), textField_admin_company_website.getText(), textField_admin_company_postalcode.getText());
    				Companydao compdao = new Companydao();
    				try {
    					compdao.uptadeCompany(dbc.getConnection(), comp);
    				} catch (SQLException e) {
    					// TODO Auto-generated catch block
    					e.printStackTrace();
    				}
    				
    			}
    		});
    		btnEdit_1.setBounds(520, 575, 97, 25);
    		panel_2.add(btnEdit_1);
    		
    		textField_admin_company_name = new JTextField();
    		textField_admin_company_name.setToolTipText("");
    		textField_admin_company_name.setBounds(265, 151, 304, 31);
    		panel_2.add(textField_admin_company_name);
    		textField_admin_company_name.setColumns(10);
    		
    
    		
    		JButton btnEdit_7 = new JButton("edit");
    		btnEdit_7.addActionListener(new ActionListener() {
    			public void actionPerformed(ActionEvent arg0) {
    				Company comp = new Company(textField_admin_company_name.getText(), textField_admin_company_address1.getText(), textField_admin_company_address2.getText(), textField_admin_company_phone1.getText(), textField_admin_company_phone2.getText(), textField_admin_company_website.getText(), textField_admin_company_postalcode.getText());
    				Companydao cdao= new Companydao();
    				try {
    					cdao.uptadeCompany(dbc.getConnection(), comp);
    					JOptionPane.showMessageDialog(null, "company edited successfully!");
    				} catch (SQLException e) {
    					// TODO Auto-generated catch block
    					e.printStackTrace();
    				}
    				
    			}
    		});
    		btnEdit_7.setFont(new Font("Segoe Print", Font.BOLD, 25));
    		btnEdit_7.setBounds(652, 278, 142, 39);
    		panel_2.add(btnEdit_7);
    		
    		
    		JPanel panel_3 = new JPanel();
    		panel_3.addComponentListener(new ComponentAdapter() {
    			@Override
    			public void componentShown(ComponentEvent arg0) {
    				
    					try {
    					tableModel_employee.setQuery(DEFAULT_Query_employee);
    					table_employee.setRowSorter(null);
    				} catch (SQLException e) {
    					// TODO Auto-generated catch block
    					e.printStackTrace();
    				}
    			}
    		});
    		tabbedPane_3.addTab("Show", null, panel_3, null);
    		panel_3.setLayout(null);
    		
    		JScrollPane scrollPane = new JScrollPane(table_employee);
    		scrollPane.setBounds(0, 86, 1024, 459);
    		panel_3.add(scrollPane);
    		
    		table_employee= new JTable(tableModel_employee);
    		table_employee.setFont(new Font("Segoe Print", Font.BOLD, 16));
    		scrollPane.setViewportView(table_employee);
    		
    		JButton button = new JButton("Refresh table");
    		button.setFont(new Font("Segoe Print", Font.BOLD, 18));
    		button.addActionListener(new ActionListener() {
    			public void actionPerformed(ActionEvent arg0) {
    				try {
    					tableModel_employee.setQuery(DEFAULT_Query_employee);
    					table_employee.setRowSorter(null);
    				} catch (SQLException e1) {
    					// TODO Auto-generated catch block
    					e1.printStackTrace();
    				}
    			}
    		});
    		button.setBounds(91, 32, 162, 41);
    		panel_3.add(button);
    		
    		JButton button_1 = new JButton("Filter table");
    		button_1.setFont(new Font("Segoe Print", Font.BOLD, 18));
    		button_1.addActionListener(new ActionListener() {
    			public void actionPerformed(ActionEvent arg0) {
    				TableRowSorter<TableModel> sorter = new TableRowSorter<TableModel>(tableModel_employee);
    				table_employee.setRowSorter(sorter);
    				sorter.setRowFilter(RowFilter.regexFilter(textField_employee_show.getText()));
    
    			}
    		});
    		button_1.setBounds(513, 31, 154, 42);
    		panel_3.add(button_1);
    		
    		textField_employee_show = new JTextField("");
    		textField_employee_show.setFont(new Font("Segoe Print", Font.BOLD, 18));
    		textField_employee_show.setToolTipText("inter text to filter");
    		textField_employee_show.setBounds(706, 39, 120, 30);
    		panel_3.add(textField_employee_show);
    		
    		JPanel panel_4 = new JPanel();
    		tabbedPane_3.addTab("Add", null, panel_4, null);
    		panel_4.setLayout(null);
    		
    		
    		 JTextField();
    		
    				} catch (SQLException e) {
    					// TODO Auto-generated catch block
    					e.printStackTrace();
    				}
    				comboBox_employee_edit_employee.setModel(dc);
    				
    				
    			}
    		});
    		btnEdit_2.setBounds(100, 387, 178, 53);
    		panel_18.add(btnEdit_2);
    		panel_18.addComponentListener(new ComponentAdapter() {
    			@Override
    			public void componentShown(ComponentEvent arg0) {
    			
    				String sql="select First_Name , last_Name from employee; ";
    				ResultSet rs= dbc.runSelect(sql);
    				DefaultComboBoxModel<String> dc= new DefaultComboBoxModel<String>();
    				try {
    					while(rs.next()) {
    						dc.addElement(rs.getString("First_Name")+" "+rs.getString("Last_Name"));
    					}
    				} catch (SQLException e) {
    					// TODO Auto-generated catch block
    					e.printStackTrace();
    				}
    				comboBox_employee_edit_employee.setModel(dc);
    				
    			}
    		});
    		comboBox_employee_edit_employee.setBounds(209, 76, 153, 25);
    		panel_18.add(comboBox_employee_edit_employee);
    		
    		JButton btnShowInfo = new JButton("show info");
    		btnShowInfo.setFont(new Font("Segoe Print", Font.BOLD, 25));
    		btnShowInfo.addActionListener(new ActionListener() {
    			public void actionPerformed(ActionEvent arg0) {
    				String s=(String)comboBox_employee_edit_employee.getSelectedItem();
    				if(s.isEmpty())
    				{
    				}
    				
    				else{
    					Scanner scn = new Scanner(s);
    					String name=scn.next();
    					String last=scn.next();
    					scn.close();
    					String sql="select * from employee where First_Name='"+name+"' and Last_Name='"+last+"';";
    					ResultSet rs=dbc.runSelect(sql);
    					try {
    						rs.next();
    						textField_employee_edit_fname.setText( rs.getString("First_Name"));
    						textField_Employee_edit_lname.setText(rs.getString("Last_name"));
    						textField_Employee_edit_phone.setText(rs.getString("phone"));
    						textField_Employee_edit_address.setText(rs.getString("Address"));
    						
    					} catch (SQLException e) {
    						// TODO Auto-generated catch block
    						e.printStackTrace();
    					}
    				}
    				
    			}
    		});
    		btnShowInfo.setBounds(419, 66, 184, 35);
    		panel_18.add(btnShowInfo);
    		
    		JComboBox comboBox_employee_delete_fullname = new JComboBox();
    		comboBox_employee_delete_fullname.setFont(new Font("Segoe Print", Font.BOLD, 25));
    		JPanel panel_6 = new JPanel();
    		panel_6.addComponentListener(new ComponentAdapter() {
    			@Override
    			public void componentShown(ComponentEvent arg0) {
    						String sql="select First_Name , last_Name from employee; ";
    						ResultSet rs= dbc.runSelect(sql);
    						DefaultComboBoxModel<String> dc= new DefaultComboBoxModel<String>();
    						try {
    							while(rs.next()) {
    								dc.addElement(rs.getString("First_Name")+" "+rs.getString("Last_Name"));
    							}
    						} catch (SQLException e) {
    							// TODO Auto-generated catch block
    							e.printStackTrace();
    						}
    						comboBox_employee_delete_fullname.setModel(dc);
    		
    			}
    		});
    		
    		
    		

    علما أنه نجح الاتصال مع قاعدة MySQL

    • أعجبني 1
×
×
  • أضف...