Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In the A5 project (question 1 package) you are given object classes for Frames a

ID: 3531114 • Letter: I

Question

In the A5 project (question 1 package) you are given object classes for Frames and Wheels. Your job is to create a new Object class Unicycle that has as data field a Frame object and a Wheel object. It also has a String data field which represents the customer for whom the Unicycle is being built. I suggest taking a few minutes to look over Frame and Wheel to see what they do. Your Unicycle class should have the following: A default, no argument constructor that creates a unicycle with your name as the customer and a frame/wheel combination of your choice. A fully-argumented constructor that takes in a wheel, frame and customer name. A copy constructor that creates a new Unicycle that has the same properties as the incoming argument Unicycle. Get and set methods for all of the data fields. An appropriate to String method. The idea here it so practice deep-copy for your constructors, set methods and return methods. Wherever appropriate you must avoid using shallow copy. Write a hard coded tester to make sure that your objects are working properly and that there are no "data leaks" (this is what happens when one object changes and those changes are reflected in another). (5 marks) Create an interactive tester class that collects from the user all of the information required to create their own custom Unicycle and allows them to modify if they choose to. My hard-coded tester output: Creating Unicycle using default constructor: Unicycle[Aaron Langille, Frane[16, blue], Wheel[12, learner]] Creating new frame and wheel for another unicycle: Frame [18, green] Wheel [16, mountain] Creating new custom unicycle from the parts for Peter Parker (aka Spiderman): Unicycle[Peter Parker, Frame[18, green], Wheel[16, mountain]] Pete changed his mind and wants to alter the unicycle to be a red and blue learner: Unicycle[Peter Parker, Frame[18, red and blue]. Wheel[16, learner]]

Explanation / Answer


public class Unicycle {
private Frame frame;
private Wheel wheel;
private String name;
public Unicycle() {
super();

this.name = "XYZ";
frame = new Frame(16, "blue");
wheel = new Wheel(12, "learner");

}

public Unicycle(Frame frames, Wheel wheels, String name) {
super();
this.frame = frames;
this.wheel = wheels;
this.name = name;
}
public Frame getFrames() {
return frame;
}
public void setFrames(Frame frames) {
this.frame = frames;
}
public Wheel getWheels() {
return wheel;
}
public void setWheels(Wheel wheels) {
this.wheel = wheels;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}

@Override
public String toString() {
return "Unicycle [name=" + name + ", " + frame.toString() + ", " + wheel.toString() + " ]";
}


}



public class Frame {
private int number;

private String color;
public Frame(int number, String color) {
super();
this.number = number;
this.color = color;
}
public int getNumber() {
return number;
}
public void setNumber(int number) {
this.number = number;
}
public String getColor() {
return color;
}
public void setColor(String color) {
this.color = color;
}
@Override
public String toString() {
return "Frame [number=" + number + ", color=" + color + "]";
}

}



public class Wheel {
private int count;
private String type;

public Wheel(int count, String type) {
super();
this.count = count;
this.type = type;
}
public int getCount() {
return count;
}
public void setCount(int count) {
this.count = count;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
@Override
public String toString() {
return "Wheel [count=" + count + ", type=" + type + "]";
}

}





public class Test {


public static void main(String[] args) {
System.out.println("Creating unicycle using default constructor");
Unicycle uc = new Unicycle();
System.out.println(uc.toString());
System.out.println("Creating new frame and wheel for another unicycle");
Frame newFrame = new Frame(18, "green");
Wheel newWheel = new Wheel(16, "mountain");
System.out.println(newFrame.toString());
System.out.println(newWheel.toString());
System.out.println("Creating new custom unicycle from peter parker");
Unicycle uc2 = new Unicycle( newFrame, newWheel, "Peter Parker");
System.out.println(uc2.toString());
System.out.println("Pete changed is mind wants to alter the unicycle to be red and blue learner");
newFrame.setColor("red and blue");
newWheel.setType("learner");
Unicycle uc3 = new Unicycle( newFrame, newWheel, "Peter Parker");
System.out.println(uc3.toString());

}


}

output:

Creating unicycle using default constructor
Unicycle [name=XYZ, Frame [number=16, color=blue], Wheel [count=12, type=learner] ]
Creating new frame and wheel for another unicycle
Frame [number=18, color=green]
Wheel [count=16, type=mountain]
Creating new custom unicycle from peter parker
Unicycle [name=Peter Parker, Frame [number=18, color=green], Wheel [count=16, type=mountain] ]
Pete changed is mind wants to alter the unicycle to be red and blue learner
Unicycle [name=Peter Parker, Frame [number=18, color=red and blue], Wheel [count=16, type=learner] ]