Starting from:

$30

Object Oriented Programming Assignment 3 Solution

Exercise 1

    A) Write a class called SportsCar containing the two instance variables maxSpeed and horsepower of type int. Both these instance variables must, in any SportsCar object hold values that are greater than certain pre-specified values; otherwise, they do not qualify as proper SportsCar objects. In our case, the minimum value for maxSpeed is 200 km/hour, and the minimum value for horsepower is 250hp. Include suitable member variables in the SportsCar class to hold these values (maxSpeedRequirement and horsepowerRequirement) and write a method called SportsCheck that returns true if both of the maxSpeed and horsepower for a particular SportsCar object are above the minimum requirements; otherwise false.

Write accessor and mutator methods for maxSpeed, horsepower, maxSpeedRequirement and horsepowerRequirement.

Exercise 2

    A) Write a class called Robot with the following three instance variables: name (String), age (int), isOn (bool). The program should initialize the instance variables to “unknown”, 0, and false, respectively. Include accessor and mutator methods to assign and retrieve the values of these instance variables.

    B) Allow the users of the Robot class to set the initial values of the three instance variables when a Robot object is created. To this end declare one constructor with three formal parameters and one default constructor.

    C) Include a member variable called robotsCreated that keeps track of the number of Robot objects created. Make the constructors update the robotsCreated variable so it is always up to date. Implement the following logic: If robotsCreated is less than 5 when the constructor is called, set isOn to true; otherwise false.




Dr. Ward    Updated: 04/09/20    Page 1 of 1

More products