Question
Due: In Lab, the week of October 30th Main topics: Inheritance & Polymorphism Abstract & Protected Exercise This week we will be practicing writing an
Due: In Lab, the week of October 30th
Main topics: Inheritance & Polymorphism Abstract & Protected
Exercise
This week we will be practicing writing an extended class for a numerous class project. Getting Started To start this exercise, you should:
Open eclipse and start a new Java project named Lab07
Add a Class (named Number) to this project, and copy the contents of the Number.java file
provided into it.
Add a Class (named MyDouble) to this project, and copy the contents of the MyDouble.java file provided into it.
Add a Class (named MyInteger) to this project, the contents of which you will be writting from scratch.
Add a Class (named Driver) to this project, the contents of which you will be writting from scratch.
Requirements
Number.java A very simple class which models some of the functionality of a number. This class is complete and must not be modified.
1. Why is setSet(boolean value) protected? 2. Why is Number division(Number guest) a method of this class? 3. Why is Number division(Number guest) an abstract method?
MyDouble.java A very simple class which extends the Number class to also model some of the function- ality of a floating point number. This class is complete and must not be modified.
Why does the overriding Number division(Number guest) method receive and return Numbers instead of MyDoubles?
Is Polymorphism occurring in the method Number division(Number guest)?
MyInteger.java A very simple class which extends the Number class to also model some of the function-
ality of a 2s complement number. This class you must write, such that:
You write the default and specifying constructors, and in doing so utilize the superclass default and specifying constructors respectively.
You write the standard accessor and mutator.
You override Numbers equals method
You override Numbers toString method
5. You override Numberss division method - note: this is not really an option since it is abstract in Number.
Driver.java A simple driver class to test all of the above classes. This class is complete and must not be modified. Answer the following questions with regard to it:
Identify how Polymorphism is being utilized.
Explain why both the correct division is being performed as well as the correct type re- turned.
If you wrote your MyInteger class correctly then your output will look like:
num1 = Undefined val1 = Undefined num1 = -4 num2 = 8
val1 = 2.4 val2 = 3.6 gen1 = -2 gen2 = -1.6666666666666667 gen3 = -0.6
gen4 = 1.5
public static ingl String uaSet-Undefined protecied idtataidouble value thla data vaue; protected tral vod Saubokan value Number cent num2.dMisionnumi Number cen2 numtdiviaianal Number gana = val 1 .elvisianInum1; Numbec gend val2.diviionall public boonan ltyDauble guest publia final boolea0 isSato reourn hs gues public Number divikiNumber guest double al: public abatract Number diiaceNumber guea: public class Moubla extends Numor public statie void mainisoal ams) Mulaoow.rum1 = ose M intoad. public static ingl String uaSet-Undefined protecied idtataidouble value thla data vaue; protected tral vod Saubokan value Number cent num2.dMisionnumi Number cen2 numtdiviaianal Number gana = val 1 .elvisianInum1; Numbec gend val2.diviionall public boonan ltyDauble guest publia final boolea0 isSato reourn hs gues public Number divikiNumber guest double al: public abatract Number diiaceNumber guea: public class Moubla extends Numor public statie void mainisoal ams) Mulaoow.rum1 = ose M intoad
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started