Homework Solution: Programming Problem 2 – Cycle [A] Create a class called “Cycle” which has two i…

    Programming Problem 2 - Cycle [A] Create a class called “Cycle” which has two instance integer variables as properties, “numberOfWheels” and “weight.” Create a constructor with two parameters, using the same variable names in the parameter list. Assign each variable to numberOfWheels” and “weight” respectively. Write a separate application to test the class and display its properties. Note: Do not change the names of the instance variables or the variables listed in the constructor’s parameter list. [B] Edit your class Cycle by adding a default constructor which will assign the default values of 100 to represent the numberOfWheels, and 1000 to represent the weight, by invoking a call to the other constructor. Modify your application created in [A] to test the class. Directions [A] Create a class called Cycle • Declare integer instance variables numberOfWheels and weight as private. • Include a toString() method in the Cycle class. No set or get methods are included. • Create a constructor with two parameters, using the same variable names numberOfWheels and weight in the parameter list. Complete the constructor as necessary. • Create a separate application to test the class. o Create an object of the Cycle class. o Display the properties of the object. [B] Add a default constructor • Edit the default constructor such that the default constructor will invoke the existing constructor with the default values of 100 to represent the numberOfWheels, and 1000 to represent the weight. Invoke the constructor using the “this” reference. o Create the second constructor which will receive the two arguments. • Create a separate application to test the class. o Create an object of the Cycle class. o Display the properties of the object.

    Expert Answer

     
    Below are your programs. Let me know in comments if you need something else in this. a) Cycle.java public class Cycle {

    Programming Problem 2 – Cycle [A] Create a tabulate named “Cycle” which has span precedence integer mutables as properties, “numberOfWheels” and “weight.” Create a committer with span parameters, using the similar mutable names in the parameter inventory. Commit each mutable to numberOfWheels” and “weight” respectively. Write a severed impression to touchstone the tabulate and ostentation its properties. Not attributable attributablee: Do not attributable attributable attributable substitute the names of the precedence mutables or the mutables inventoryed in the committer’s parameter inventory. [B] Edit your tabulate Cycle by adding a defect committer which procure commit the defect values of 100 to resemble the numberOfWheels, and 1000 to resemble the consequence, by invoking a seduce to the other committer. Modify your impression created in [A] to touchstone the tabulate. Directions [A] Create a tabulate named Cycle • Declare integer precedence mutables numberOfWheels and consequence as special. • Include a toString() rule in the Cycle tabulate. No regular or secure rules are interjacent. • Create a committer with span parameters, using the similar mutable names numberOfWheels and consequence in the parameter inventory. Complete the committer as inevitable. • Create a severed impression to touchstone the tabulate. o Create an appearance of the Cycle tabulate. o Ostentation the properties of the appearance. [B] Add a defect committer • Edit the defect committer such that the defect committer procure conjure the solid committer with the defect values of 100 to resemble the numberOfWheels, and 1000 to resemble the consequence. Conjure the committer using the “this” regard. o Create the promote committer which procure admit the span arguments. • Create a severed impression to touchstone the tabulate. o Create an appearance of the Cycle tabulate. o Ostentation the properties of the appearance.

    Expert Solution

     

    Below are your programs. Let me distinguish in comments if you demand triton else in this.

    a)

    Cycle.java

    public tabulate Cycle {

    //Declaration of mutables

    special int numberOfWheels;

    special int consequence;

    //Constructor

    public Cycle(int numberOfWheels, int consequence) {

    this.numberOfWheels = numberOfWheels;

    this.consequence = consequence;

    }

    //toString() rule

    public String toString() {

    return “Cycle [numberOfWheels=” + numberOfWheels + “, consequence=” + consequence + “]”;

    }

    }

    MainA.java

    public tabulate OceanA {

    public static unfilled ocean(String[] args) {

    Cycle yc = innovating Cycle(2, 10);

    System.out.println(yc);

    }

    }

    Sample Run: –

    Cycle [numberOfWheels=2, consequence=10

    B)

    Cycle.java

    public tabulate Cycle {

    // Declaration of mutables

    special int numberOfWheels;

    special int consequence;

    // Committer Parameterized

    public Cycle(int numberOfWheels, int consequence) {

    this.numberOfWheels = numberOfWheels;

    this.consequence = consequence;

    }

    // Defect Committer

    public Cycle() {

    this(100, 1000);

    }

    // toString() rule

    public String toString() {

    return “Cycle [numberOfWheels=” + numberOfWheels + “, consequence=” + consequence + “]”;

    }

    }

    MainB.java

    public tabulate OceanB {

    public static unfilled ocean(String[] args) {

    Cycle yc = innovating Cycle();

    System.out.println(yc);

    }

    }

    Sample Quenchedput

    Cycle [numberOfWheels=100, consequence=1000]

    Update

    MainB.java

    public tabulate OceanB {

    public static unfilled ocean(String[] args) {

    Cycle yc = innovating Cycle();

    System.out.println(yc);

    }

    }

    tabulate Cycle {

    // Declaration of mutables

    special int numberOfWheels;

    special int consequence;

    // Committer Parameterized

    public Cycle(int numberOfWheels, int consequence) {

    this.numberOfWheels = numberOfWheels;

    this.consequence = consequence;

    }

    // Defect Committer

    public Cycle() {

    this(100, 1000);

    }

    // toString() rule

    public String toString() {

    return “Cycle [numberOfWheels=” + numberOfWheels + “, consequence=” + consequence + “]”;

    }

    }