Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

CS 101: Intro to Computer Science

Homework 8  [10 Marks]

Part 1 : Programming Question [7 Marks]

Question 1 : [5 Marks]

●   Design a class named Person and its two subclasses named Student and Employee.

●   Make Faculty and Staff subclasses of Employee.

●   A person has a name, address, phone number, and email address. A student has a class status (freshman, sophomore, junior, or senior).

●   Define the status as a constant.

●   An employee has an office, salary, and date hired(Keep the data type of Date as String).

●    A faculty member has office hours and a rank.

●   A staff member has a title.

●   Override the toString method in each class to display the class name and the person’s name.

Draw the UML diagram  for the classes and implement them.

Write a test program that creates a Person, Student, Employee, Faculty, and Staff, and invokes their toString() methods.


Question 2:[2 Marks]

 

Design a class named Triangle that extends GeometricObject.

The Triangle class contains:

●  Three double data fields named side1, side2, and side3 with default values 1.0 to denote three sides of the triangle.

 A no-arg constructor that creates a default triangle.

●  A constructor that creates a triangle with the specified side1, side2, and side3.

  The accessor methods for all three data fields.

●  A method named getPerimeter() that returns the perimeter of this triangle.

●  A method named toString() that returns a string description for the triangle. The toString() method is implemented as follows:

 


Part 2 : Theoretical Question [3 Marks]

Question 1: [1 Marks]

If a method in a subclass has the same signature as a method in its superclass with a different return type, will this be a problem?

If a method in a subclass has the same signature as a method in its superclass with the same return type, is the method overridden or   overloaded?

 

Question 2: [1 Mark]

 

Assume the following code is given :

 

Answer the following questions :

(a) Is fruit instanceOf Apple?

(b) Is the statement Orange p = new Apple() legal ?

(c) Is the statement McIntosh p = new Apple() legal ?

(d) Suppose the method makeAppleCider is defined in the Apple class. Can fruit invoke this method? Can orange invoke this method?


Question 3: [1 Mark]

How do you prevent a class from being extended? State one reason why a class should be prevented from being extended.


Submission Details :

1.  Write the answers of UML Diagrams of Part1 : Programming Questions and Part2: Theoretical Question  in a single PDF document and name it as        netID_CS101_HW8_pdf.pdf (For Example: dd3053_CS101_HW8_pdf.pdf).      Submit the pdf file on Gradescope : Homework 8

2.   Create 2 .java files :

a.   Question1.java

b.   Question2.java

3.  Zip Question1.java and Question2.java to a common file :                                FirstName_LastName_netID_HW8.zip (Devesh_Devendra_dd3053_HW8.zip)

4.   Submit the zip file on the Coding Assignment on the following Assignment on GradeScope : Homework 8 - Programming Questions

5.   Submit both the zip and the pdf file on Gradescope before the deadline: April 12th, 11:59 pm EST.

6.   In case of any questions or clarifications, please reach out to [email protected].