Question

In: Computer Science

Create a class called “Cycle” which has two instance integer variables as properties, “numberOfWheels” and “weight.”

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.

    • Create an object of the Cycle class.

    • 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.

    • Create the second constructor which will receive the two arguments.

  • Create a separate application to test the class.

    • Create an object of the Cycle class.

    • Display the properties of the object.

Grading Rubric

Task

Points

Class created and named

2

Constructor(s) completed correctly

2

toString() methods written correctly

1

Successful invocation (constructor to constructor)

2

Properties output correctly

1

Proper documentation / Pseudocode

1

Program works effectively

1

Total

10

Solutions

Expert Solution

Here is the first part of the question

"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. ​"

Here is the code

------------------------------------------------------------------------------------------------------------------------------------

//Create a class called “Cycle”

public class Cycle {

//two instance integer variables as properties,

int numberOfWheels;

double weight;

//Create a constructor with two parameters, using the same variable names in the parameter list.

public Cycle(int numberOfWheels, double weight) {

//Assign each variable to numberOfWheels” and “weight” respectively.

this.numberOfWheels=numberOfWheels;

this.weight=weight;

}

}

----------------------------------------------------------------------------------------------------------------------------------------

"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. "

here is the code below :

-------------------------------------------------------------------------------------------------------------------------------------

//Create a class called “Cycle”

public class Cycle {

//two instance integer variables as properties,

int numberOfWheels;

double weight;

//Create a constructor with two parameters, using the same variable names in the parameter list.

public Cycle(int numberOfWheels, double weight) {

//Assign each variable to numberOfWheels” and “weight” respectively.

this.numberOfWheels=numberOfWheels;

this.weight=weight;

}

//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.

// we call another constructor using the this keyword and passing the parameter values

public Cycle() {

this(100,1000.00);

}

}

---------------------------------------------------------------------------------------------------------------------------------------

" 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."

here is the java class

---------------------------------------------------------------------------------------------------------------------------------

//Create a class called “Cycle”

public class Cycle {

//two instance integer variables as properties,

private int numberOfWheels; // we are marking the instance variable as private

private double weight; // we are marking the instance variable as private

//Create a constructor with two parameters, using the same variable names in the parameter list.

public Cycle(int numberOfWheels, double weight) {

//Assign each variable to numberOfWheels” and “weight” respectively.

this.numberOfWheels=numberOfWheels;

this.weight=weight;

}

//Include a toString() method in the Cycle class.

public String toString() {

return "";

}

}

---------------------------------------------------------------------------------------------------------------------------------------

" 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. •"

here is the java class

--------------------------------------------------------------------------------------------------------------------------------------

//Create a class called “Cycle”

public class Cycle {

//two instance integer variables as properties,

private int numberOfWheels; // we are marking the instance variable as private

private double weight; // we are marking the instance variable as private

//Create a constructor with two parameters, using the same variable names in the parameter list.

public Cycle(int numberOfWheels, double weight) {

//Assign each variable to numberOfWheels” and “weight” respectively.

this.numberOfWheels=numberOfWheels;

this.weight=weight;

}

//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.

// we call another constructor using the this keyword and passing the parameter values

public Cycle() {

this(100,1000.00);

}

//Include a toString() method in the Cycle class.

public String toString() {

return "";

}

}

---------------------------------------------------------------------------------------------------------------------------------------

You can test all the above classes using a driver class as below -

public class TestCycle {

public static void main(String[] args) {

Cycle bicycle = new Cycle();

Cycle tricycle = new Cycle(3,3000);

}

}


Related Solutions

Programming Problem 2 - Cycle [A] Create a class called “Cycle” which has two instance integer...
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...
Create a class called employee which has the following instance variables: Employee ID number Salary Years...
Create a class called employee which has the following instance variables: Employee ID number Salary Years at the company Your class should have the following methods: New employee which reads in an employee’s ID number, salary and years of service Anniversary which will up the years of service by 1 You got a raise which will read in how much the raise was (a percent) and then calculate the new salary You get a bonus which gives a yearly bonus...
This is python #Create a class called Rectangle. Rectangle should #have two attributes (instance variables): length...
This is python #Create a class called Rectangle. Rectangle should #have two attributes (instance variables): length and #width. Make sure the variable names match those words. #Both will be floats. # #Rectangle should have a constructor with two required #parameters, one for each of those attributes (length and #width, in that order). # #Rectangle should also have a method called #find_perimeter. find_perimeter should calculate the #perimeter of the rectangle based on the current values for #length and width. # #perimeter...
in Java, Create a class called EMPLOYEE that includes three instance variables – a first name...
in Java, Create a class called EMPLOYEE that includes three instance variables – a first name (type String), a last name (type String) and a monthly salary (double). Provide a constructor that initializes the three instance variables. Provide a set and a get method for each instance variable. If the monthly salary is not positive, do not set its value. Write a test app names EmployeeTest that demonstrates class EMLOYEE’s capabilities. Create two EMPLOYEE objects and display each object’s yearly...
Create a class called Vehicle that includes four instance variables:      name, type,     tank size and...
Create a class called Vehicle that includes four instance variables:      name, type,     tank size and average petrol consumption. Provide 2 constructors, the first takes name and type as parameter, the second takes four parameters for the four instance variables. (2 pt) Provide also a method called distancePerTank that calculate the average distance that a vehicle can travel if the tank is full (multiplies the tank size by the average petrol consumption), then returns the value. (2 pt) Provide a...
Using C# Create a class called Artist that contains 4 pieces of information as instance variables:...
Using C# Create a class called Artist that contains 4 pieces of information as instance variables: name (datatype string), specialization – i.e., music, pottery, literature, paintings (datatype string), number of art items (datatype int), country of birth (datatype string). Create a constructor that initializes the 4 instance variables. The Artist class must contain a property for each instance variable with get and set accessors. The property for number should verify that the Artist contributions is greater than zero. If a...
Create a class called Student. Include the following instance variables: name, address, phone, gpa Create all...
Create a class called Student. Include the following instance variables: name, address, phone, gpa Create all of the methods required for a standard user defined class: constructors, accessors, mutators, toString, equals Create the client for testing the Student class Create another class called CourseSection Include instance variables for: course name, days and times course meets (String), description of course, student a, student b, student c (all of type Student) Create all of the methods required for a standard user defined...
with PHP Create a class called Employee that includes three instance variables—a first name (type String),...
with PHP Create a class called Employee that includes three instance variables—a first name (type String), a last name (type String) and a monthly salary int). Provide a constructor that initializes the three instance data member. Provide a set and a get method for each instance variable. If the monthly salary is not positive, do not set its 0. Write a test app named EmployeeTest that demonstrates class Employee’s capabilities. Create two Employee objects and display each object’s yearly salary....
Code in Java Write a Student class which has two instance variables, ID and name. This...
Code in Java Write a Student class which has two instance variables, ID and name. This class should have a two-parameter constructor that will set the value of ID and name variables. Write setters and getters for both instance variables. The setter for ID should check if the length of ID lies between 6 to 8 and setter for name should check that the length of name should lie between 0 to 20. If the value could not be set,...
Details: Create a class called CompareArrays that determines if two specified integer arrays are equal. The...
Details: Create a class called CompareArrays that determines if two specified integer arrays are equal. The class should have one static methods: public static boolean compare(int[] arrayOne, int[] arrayTwo) – Which compares the two arrays for equality. The two arrays are considered equal if they are the same size, and contain the same elements in the same order. If they are equal, the method should return true. Otherwise, the method should return false. NOTE: You are not allowed to use...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT