بتاريخ: 19 مايو 20169 سنة comment_274863 السلام علبكم ريد مساعد في حل مسئلتين صعبني شوي بليز ... 1. Write Java code for the following scenario: a. Create class to represent a Student details StudentID, StudentName, ModuleName, and StudentMarks. Choose appropriate data type for each attribute. b. Implement a constructor to initialize all the member variables from given parameters. c. Methods: void Display() to display the all the details of the Student. void UpdateMarks(double MK) to update StudentMarks of the student. d. Write a custom exception for the following situations while updating marks When Student marks are updated with a value less than or equal to zero a custom exception must be raised with the following message “Student Marks cannot be zero/ less than zero”. When Student marks are updated with a value greater than hundred a custom exception must be raised with the following message “Student Marks cannot be greater than hundred”. e. invoke both custom exceptions in UpdateMarks methodf. Implement a class MainClass hosting Main Create object of Student class. Call all the methods in such a way that all custom exceptions are raised. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 2. Write Java code for the following scenario: a. Create class to represent a LibraryMember details MemberID, MemberName, Department, and TotalBooks. Choose appropriate data type for each attribute. b. Implement a constructor to initialize all the member variables from given parameters. c. Methods: void Display() to display the all the details of the Student. d. Write a custom exception for the following situations while issue and returning of books When Member is issued books TotalBooks attribute is updated by adding number of books issued to TotalBooks. After addition if TotalBooks is 6 or more a custom exception must be raised with the following message “Member cannot be issued more than five books”. When Member is returns a book TotalBooks attribute is updated by subtracting the number of books from the TotalBooks. If after subtracting TotalBooks reduces to Zero a custom exception must be raised with the following message “Member has returned all the books”. e. Assume the following methods for the above exceptions. void issue(int NoofBooks). void Return(int NoofBooks). f. Implement a class MainClass hosting Main(): Create object of Student class. Call all the methods in such a way that all custom exceptions are raised. تقديم بلاغ
بتاريخ: 20 مايو 20169 سنة comment_274891 هذا الكود يحقق ما سألت عنه في السؤال الأول بكل فروعه ووضعت تعليق توضيحي في بداية كل method import javax.swing.JOptionPane; public class Student extends Exception { /* a. Create class to represent a Student details StudentID, * StudentName, ModuleName, and StudentMarks * Choose appropriate data type for each attribute.*/ int studentID; String studentName; Double studentMarks; String moduleName; /* b. Implement a constructor to initialize all the member variables from given parameters.*/ public Student(int studentID,String studentName,Double studentMarks,String moduleName) { this.studentID=studentID; this.studentName=studentName; this.studentMarks=studentMarks; this.moduleName=moduleName; } /* c. Methods: void Display() to display the all the details of the Student*/ public void displayDetails() { System.out.println("The Student Id is " + studentID); System.out.println("The Student Name is " + studentName); System.out.println("The Student markrs is " + studentMarks); System.out.println("The Student Module is " + moduleName); } private Student() { } public Student(String message) { super(message); } /* void UpdateMarks(double MK) to update StudentMarks of the student. d. Write a custom exception for the following situations while updating marks When Student marks are updated with a value less than or equal to zero a custom exception must be raised with the following message “Student Marks cannot be zero/ less than zero”. When Student marks are updated with a value greater than hundred a custom exception must be raised with the following message “Student Marks cannot be greater than hundred”.*/ public void updateMarks(double MK) { Student student = new Student(); student.exceptionLessupdateMarks(MK); student.exceptionGreatUpdateMarks(MK); } /*Custom Exception For Mark Less Than Zero*/ public void exceptionLessupdateMarks(double MK) { try { if(MK<=0) { throw new Student(); } } catch(Student ex) { System.out.println("Student Marks cannot be zero/ less than zero"); } } /*Custom Exception For Mark Greater Than hundred*/ public void exceptionGreatUpdateMarks(double MK) { try { if(MK>100) { throw new Student(); } } catch(Student ex) { System.out.println("Student Marks cannot be greater than hundred"); } } /* e. invoke both custom exceptions in UpdateMarks methodf. Implement a class MainClass hosting Main Create object of Student class. Call all the methods in such a way that all custom exceptions are raised. */ public static void main(String[] args) { String studentID = JOptionPane.showInputDialog("Please Enter Student ID"); String studentName = JOptionPane.showInputDialog("Please Enter Student Name "); String studentMarks = JOptionPane.showInputDialog("Please Enter Student Marks "); String moduleName = JOptionPane.showInputDialog("Please Enter Student Module"); Student student = new Student(Integer.parseInt(studentID),studentName,Double.parseDouble(studentMarks),moduleName); student.displayDetails(); String studentMarksUpdate = JOptionPane.showInputDialog("Updat Student Mark"); student.updateMarks(Double.parseDouble(studentMarksUpdate)); } } السؤال الثاني حاول أن تستفد من حل السؤال الأول وقم بحله فهو مشابه تقريباً وبالتوفيق تقديم بلاغ
بتاريخ: 20 مايو 20169 سنة كاتب الموضوع comment_274892 شكرا جزيلا اختي العزيزه على مجهودك وفقك الله تقديم بلاغ
انضم إلى المناقشة
يمكنك المشاركة الآن والتسجيل لاحقاً. إذا كان لديك حساب, سجل دخولك الآن لتقوم بالمشاركة من خلال حسابك.