Disc 2
May 19, 2020
concepts of criminology
May 19, 2020
Show all

java program

Exercise 1A) Write a class called SportsCar containing the two instance variables maxSpeed and horsepowerof 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 SportsCarobjects. 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 2A) Write a class called Robot with the following three instance variables: name (string), age (ushort), isOn (bool). Make the program initialize the instance variables to unknown, 0, and false, respectively (without using constructors). 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.

Leave a Reply

Your email address will not be published. Required fields are marked *