[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.
JAVA 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.
Trending now
This is a popular solution!
Step by step
Solved in 7 steps with 2 images
Programming Problem 3 – CycleFileInput
Revisit the Cycle class in Module 3. Modify your application such that the properties will be read from a text file called “Cycle.txt”.
Directions
Examine your application for the class called Cycle.
- Add an appropriate throws statement in the main method.
- Create a reference to a File class with the appropriate name of a text file (Cycle.txt). Note: Cycle.txt was created in the previous assignment, CycleFileOutput.
- In your code, check that the text file does exist.
- Input the values from the file to memory.
- Close the file.
Programming Problem 1 – CycleThrowTryCatch
Revisit the Cycle class in Module 3. Modify your application such that the properties, numberOfWheels and weightare entered as double values interactively (at the keyboard). Exception handling will be used to determine whether a type mismatch occurs.
Edit your application such that, in addition to [A], the values for numberOfWheels and weight, entered interactively, will throw a new exception “Values cannot be less than or equal to zero” only If the values are less than or equal to zero. Add or use the appropriate try and/or catch blocks.
Directions
Examine your application for the class called Cycle.
- Add Try and Catch blocks appropriately.
- Add the throw statement for the new exception.
- Display an appropriate message if an exception occurs.
- Display the properties of the object.