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

Programming Logic & Design Comprehensive
9th Edition
ISBN:9781337669405
Author:FARRELL
Publisher:FARRELL
Chapter11: More Object-oriented Programming Concepts
Section: Chapter Questions
Problem 5PE
icon
Related questions
Question

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.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 7 steps with 2 images

Blurred answer
Follow-up Questions
Read through expert solutions to related follow-up questions below.
Follow-up Question

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.
Solution
Bartleby Expert
SEE SOLUTION
Follow-up Question

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.
Solution
Bartleby Expert
SEE SOLUTION
Knowledge Booster
Running Time of Application
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,
Programming with Microsoft Visual Basic 2017
Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:
9781337102124
Author:
Diane Zak
Publisher:
Cengage Learning