NAME__________________________________________
INFO3134 InClass Coding Assignment 1 (20 marks)
“Your program must compile or a mark of 0 will be assigned”
In this exercise you will be writing a super class and two sub classes and then write a test class.
NOTE: Two marks of the 20 are allocated for “Compile and Style”. All classes must have a complete documentation header. Any utility methods must have a full method documentation header.
Specifications for Drill Class (4 Marks)
– type: String
– brand: String
______________________________________________________________
+Drill(String: type)
+Drill(String: type, String: brand)
+getBrand( ): String
+getType(): String
+setBrand( String: make):void
+setType(String: type): void
+getInstructions( ): String
+toString(): String |
|
Step One: Examine the UML diagram for the super class Drill that is shown below. This diagram shows what data variables and what methods will be found within the class. Using the information from the diagram write the code for the super class. NOTE: do not include any data members or methods in any class that are not in the UML diagram.
Details:
For the one argument constructor set the default value for brand to “Dewalt”
The getInstructions( ) method will be abstract and will be over-ridden in the sub classes.
For the toString( ) method, have the method return a String that reads “This is a type goes here drill .
The Sub Class Cordless (4 marks)
Extend the super class Drill to make a sub-class called Cordless.java. See the UML diagram below.
– batteryType: String ______________________________________________________________
+Cordless( )
+Cordless(String: brand, String: batteryType)
+getBatteryType( ): String
+setBatteryType(String batteryType): void
+getInstructions(): String
+toString( ): String |
|
Details:
For the no-argument constructor, set the batteryType to Nickle Cadmium. This will call the one argument constructor from the parent class.
You need to implement the abstract method getInstructions( ) in this sub class. This method will return the operating instructions for the cordless drill. Use your own words to describe how the drill will function.
For the toString( ) method of the Cordless class, have the method make a call to the super class toString( ) method, and then concatenate onto the string from the super class this string :
This drill will run for 3 hours on a single charge.
So, if you had a Cordless object called cordlessDrill and it called it’s toString( ) method, the string returned should read
This is a cordless drill. This drill will run for 3 hours on a single charge.
The Sub Class Electric (4 marks)
Extend the super class Drill to make a sub-class called Electric.java.
Check the UML diagram below.
– amps; double
______________________________________________________________
+Electric( )
+Electric(String: brand, double amps)
+getAmps: double
+setAmps(double: amps) :void
+getInstructions( ): String
+toString( ): String |
|
Details
For the no-argument constructor, set the amps to 11.9.
You need to implement the getInstruction( ) method of the Electric class. Again you will use your own words to describe how to go about using an electric drill.
For the toString( ) method of the Electric class, have it call the super class toString( ) method and then concatenate onto its return value this added string.
This drill has a power rating of 11.9 amps.
If the electric object was created from the no argument constructor, the toString() method would return this:
This is a(n) electric drill.. This drill has a power rating of 11.9 amps.
The Test Program DrillTest.java 6 marks
Write a test program called DrillTest.java.
Do the following steps in the exact order shown:
1) Create a cordless drill object with the no argument constructor.
2) Create a second cordless drill object using the two arg constructor with the brand as Mastercraft and batteryType as lithium.
3) Create an electric drill using the no argument constructor.
4) Create a second electric drill using the two argument constructor. The brand will be “Black and Decker” and the amps will be 7.5.
3) Have each object call all of its available getter methods and print out the results to the screen.
4) Have each object call its toString( ) method and print the results to the screen.
5) Change the brand on the second Cordless drill object to “Rigid”.
6) Now have that cordless object call its getter method to show the change to the brand and
print that result to the screen
7) Have each object call its getInstructions() method and print the results to the screen.
Submitting your files:
1) When ready to submit your files, locate them and zip the four java files together.
2) Upload the zipped file to the dropbox.
MAKE SURE IT IS THE .JAVA FILES THAT YOU UPLOAD AND NOT THE .CLASS FILES. I CANNOT GIVE YOU ANY MARKS FOR THE .CLASS FILES!
Marking Scheme for INFO3134 INClass 1
Item |
Marks |
Awarded |
Your program must compile or a mark of 0 will be assigned |
Compile and Style:
- documentation headers on all classes and on methods that should have them.
- naming convention followed.
- following instructions to the letter.
|
2 |
|
Drill Class
|
|
|
Data members properly declared with appropriate modifiers
|
1 |
|
Constructor methods done to specs:
|
1 |
|
All other methods done to specs: |
2 |
|
Cordless Class
|
|
|
Data members properly declared with appropriate modifiers
|
1 |
|
Constructor methods done to specs:-
|
1 |
|
All other methods done to specs:
|
2 |
|
Electric Class
|
|
|
Data members properly declared with appropriate modifiers
|
1 |
|
Constructor methods done to specs:-
|
1 |
|
All other methods done to specs:
|
2 |
|
DrillTest Class
|
|
|
Objects created as specified. |
2 |
|
All available getters tested for each object |
1 |
|
Calls to toString() produce proper output for each object |
1 |
|
setBrand() is used and the appropriate getter is re-called |
1 |
|
All objects call getInstructions() method and proper results are returned. |
1 |
|
Total Marks
|
20 |
|