CHAPTER 8 ASSIGNMENT - LEARN JAVA BY EXAMPLE
Trang 1 trong tổng số 1 trang
CHAPTER 8 ASSIGNMENT - LEARN JAVA BY EXAMPLE
Exercise 1 :
1. sDeclare a class, calArea, with length and width as its members of type double. The class should define one constructor to initialize the instance variables length and width. The class will have one more constructor to accept two values and assign them to length and width respectively. Further the class should define two methods - area() and display(). The area() method should compute the area and return it. The display() method will be used to display the returned value.
2. Write a class called distance which has two members feet and inches of type double. Define a method calculate() to accept a value indicating number of inches, and display the corresponding value in feet (and inches).
Exercise 2 :
Create a class called Employee with name and salary of type String and double respectively. Define a method calculatepay() in the Employee class with no code as it will be overridden in the subclasses. Create three subclasses - Manager, Scientist and Laborer from the Employee class. The Manager class has a member called business_amount of type double. The Scientist class has a member called publication of type int. The Laborer class has a member named hrsworked of type int. All these subclasses have to override a method called calculatepay and calculate the total_pay based on the formula given:
total_pay=salary + commission;
In the Manager class, if the business_amount is greater than Rs. 50,000, the commission should be calculated as 10% of the business_amount. Otherwise the commission should be calculated as 5% of the business_amount.
In the Scientist class, if the number of publication is more than 25, the commission should be calculated as 20% of salary. If number of publication is less than 25, then the commission should be calculated as 10% of salary.
For the Laborer class the commission should be calculated as 15% of salary, if hrsworked is more than 50. If hrsworked is less than 50 then the commission is 8% of salary.
All these subclasses will have a display() method to display the name and salary. Additionally these display() methods will display business_amount, publication and hrsworked for the classes Manager, Scientist, and Laborer respectively.
Lời giải: [You must be registered and logged in to see this link.]
1. sDeclare a class, calArea, with length and width as its members of type double. The class should define one constructor to initialize the instance variables length and width. The class will have one more constructor to accept two values and assign them to length and width respectively. Further the class should define two methods - area() and display(). The area() method should compute the area and return it. The display() method will be used to display the returned value.
2. Write a class called distance which has two members feet and inches of type double. Define a method calculate() to accept a value indicating number of inches, and display the corresponding value in feet (and inches).
Exercise 2 :
Create a class called Employee with name and salary of type String and double respectively. Define a method calculatepay() in the Employee class with no code as it will be overridden in the subclasses. Create three subclasses - Manager, Scientist and Laborer from the Employee class. The Manager class has a member called business_amount of type double. The Scientist class has a member called publication of type int. The Laborer class has a member named hrsworked of type int. All these subclasses have to override a method called calculatepay and calculate the total_pay based on the formula given:
total_pay=salary + commission;
In the Manager class, if the business_amount is greater than Rs. 50,000, the commission should be calculated as 10% of the business_amount. Otherwise the commission should be calculated as 5% of the business_amount.
In the Scientist class, if the number of publication is more than 25, the commission should be calculated as 20% of salary. If number of publication is less than 25, then the commission should be calculated as 10% of salary.
For the Laborer class the commission should be calculated as 15% of salary, if hrsworked is more than 50. If hrsworked is less than 50 then the commission is 8% of salary.
All these subclasses will have a display() method to display the name and salary. Additionally these display() methods will display business_amount, publication and hrsworked for the classes Manager, Scientist, and Laborer respectively.
Lời giải: [You must be registered and logged in to see this link.]
Similar topics
» CHAPTER 7 ASSIGNMENT - LEARN JAVA BY EXAMPLE
» CHAPTER 5 ASSIGNMENT - LEARN JAVA BY EXAMPLE
» CHAPTER 4 ASSIGNMENT - LEARN JAVA BY EXAMPLE
» CHAPTER 2&3 ASSIGNMENT - LEARN JAVA BY EXAMPLE
» CHAPTER 1 ASSIGNMENT - LEARN JAVA BY EXAMPLE
» CHAPTER 5 ASSIGNMENT - LEARN JAVA BY EXAMPLE
» CHAPTER 4 ASSIGNMENT - LEARN JAVA BY EXAMPLE
» CHAPTER 2&3 ASSIGNMENT - LEARN JAVA BY EXAMPLE
» CHAPTER 1 ASSIGNMENT - LEARN JAVA BY EXAMPLE
Trang 1 trong tổng số 1 trang
Permissions in this forum:
Bạn không có quyền trả lời bài viết
|
|
Fri Jan 10, 2014 5:08 pm by trangan
» Luvina - Tuyển sinh Luvina Academy IX/2013
Tue Apr 09, 2013 2:21 pm by trangan
» LUVINA ACADEMY VIII TUYỂN SINH 2012
Mon Sep 17, 2012 3:16 pm by trangan
» Tuyển sinh khóa học lập trình viên_Luvina Academy VII (Hệ sơ cấp)
Tue Jul 10, 2012 7:01 pm by trangan
» Xin đề thi thực hành,lý thuyết và đáp án của môn Developing Web Services with Java
Tue Jan 10, 2012 12:58 pm by JinHoVN
» Nhờ các PRO vào làm giúp kái đề PCS này với
Fri Jan 06, 2012 1:06 pm by phongvan1991
» Đề cương ôn tập môn CF
Thu Nov 10, 2011 8:20 pm by thanhnc_b01392
» xin slide môn C
Sun Sep 04, 2011 5:33 pm by anhchang064
» Drugs In Japan
Tue Aug 02, 2011 5:58 am by Khách viếng thăm