Question
1. Create a subclass of the class you created in Assignment 2. (10 point) 2. Create at least 1 instance field (attribute) for your subclass
1. Create a subclass of the class you created in Assignment 2. (10 point)
2. Create at least 1 instance field (attribute) for your subclass (10 point)
3. Create getter (accessor) and setter (mutator) methods for the new instance field (10 point)
4. Create a Method to display your data (15 point)
Create a method called display, that simply prints out the values of all instance variables of your object
It must display all the fields from the super class, along with the new field that belongs to the subclass
This method will have no parameters and not return a value
5. Create 2 Constructors
Create a default constructor (no parameters) that assigns all your instance variables to default values. It should also set the fields for the super class as well. (10 point)
Create a parameterized constructor that takes all instance variables (from both superclass and subclass) as parameters, and sets the instance variables to the values provided by the parameters (15 point)
6. Testing your program. In the main method of Demo.java:
Create an instance of your new subclass (an object) by using the default constructor.
Call all your objects setter (mutator) methods to assign values to your object (5 point)
Call the objects display method, to print out it's values (5 point)
Create another instance of your class (another object) by using the parameterized constructor (10 point)
Call the objects display method, to print out it's values
7. Write Javadoc style comments for ALL of your methods. Including the methods in your super class. (10 point)
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Assignment 2 codes a.k.a superclass code
Shoes.java
public class Shoes {
// Declaring instance variables private int size; private String brand; private double price;
// Zero argumented constructor public Shoes() { this.size = 7; this.brand = "Red Tape"; this.price = 50; }
// Parameterized constructor public Shoes(int size, String brand, double price) { super(); this.size = size; this.brand = brand; this.price = price; }
// getters and setters
/* * This method will get the price of instance variable * * @params void * * @return double */ public int getSize() { return size; }
/* * This method will set the size of instance variable * * @params int * * @return void */ public void setSize(int size) { this.size = size; }
/* * This method will get the brand name of instance variable * * @params void * * @return String */ public String getBrand() { return brand; }
/* * This method will set the brand of instance variable * * @params String * * @return void */ public void setBrand(String brand) { this.brand = brand; }
/* * This method will return the price of instance variable * * @params void * * @return double */ public double getPrice() { return price; }
/* * This method will set the price of instance variable * * @params double * * @return void */ public void setPrice(double price) { this.price = price; }
/* * This method will display the values of instance variables * * @params void * * @return void */ void display() { System.out.println("Size :" + size); System.out.println("Brand :" + brand); System.out.println("Price :$" + price); }
}
_______________________________________
Demo.java
public class Demo {
public static void main(String[] args) { //Creating an instance of Shoes class object using Default constructor Shoes s1 = new Shoes();
//Calling the setter methods by putting the values in the arguments s1.setSize(9); s1.setBrand("Reebok"); s1.setPrice(75);
//calling the display() method on the Shoes class s1.display();
/* Creating an instance of Shoes class object using Parameterized * constructor by putting the values as arguments */ Shoes s2 = new Shoes(6, "Puma", 60);
//calling the display() method on the Shoes class s2.display();
}
}
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