Question

In: Computer Science

JAVA CODING PLEASE Create a class SportsCar that inherits from the Car class (CAR CLASS LISTED...

JAVA CODING PLEASE

Create a class SportsCar that inherits from the Car class (CAR CLASS LISTED BELOW THIS QUESTION).

Include the following:

  • A variable Roof that holds the type of roof (Ex: Convertible, Hard-Top, Soft-Top)
  • A variable Doors that holds the car’s number of doors (Ex: 2, 4)
  • Implement the ChangeSpeed method to add 20 to the speed each time it is called.
  • Add exception handling to the ChangeSpeed method to keep the speed under 65.
  • Implement the sound method to print, “brooooom,” to the screen.
  • Create one constructor that accepts the car’s roof, doors, year and make as arguments and assigns the values appropriately. Do not create any other constructors.
  • The interface methods should print simple messages to the screen using System.out.println()

CAR CLASS:

interface Vehicle{
        void Start();
        void Stop();
        void ChangeSpeed();
}
abstract class Car implements Vehicle{
        private int year;
        private int speed;
        private String make;
        private static int count=0;
        public Car(int aYear, String aMake) {
                year = aYear;
                make = aMake;
                speed=0;
                count++;
        }
        abstract void sound();
        public static int getCount() {
                return count;
        }
        
}

Solutions

Expert Solution

class SportsCar extends Car{
   private String roof;
   private int doors;
   public SportsCar(String r,int d,String m) {
       super(0,m);
       roof=r;
       doors=d;
   }
   public void ChangeSpeed() {
       speed+=20;
       if(speed>65) {
           throw new IllegalArgumentException("Invalid Speed");
       }
      
   }
   public void sound() {
       System.out.println("broooom");
   }
   @Override
   public void Start() {
      
   }
   @Override
   public void Stop() {
   }
}

Note : Please comment below if you have concerns. I am here to help you

If you like my answer please rate and help me it is very Imp for me


Related Solutions

In Java, create an abstract vehicle class. Create a Truck Class that Inherits from Vehicle Class....
In Java, create an abstract vehicle class. Create a Truck Class that Inherits from Vehicle Class. The vehicle class should contain at least 2 variables that could pertain to ANY vehicle and two methods. The truck class should contain 2 variables that only apply to trucks and one method. Create a console program that will instantiate a truck with provided member information then call one method from the truck and one method contained from the inherited vehicle class. Have these...
In java Create a class named CellPhoneCase that extends your Case class – it inherits all...
In java Create a class named CellPhoneCase that extends your Case class – it inherits all the fields and methods from the Case class. It should also contain:  One field for a CellPhone object. Be sure to put in the appropriate access modifier. (private, public)  A constructor with 3 parameters – owner’s name, Case color, the phone number of the cell phone that will be in the Case. This constructor MUST call the super class’s constructor. Then set...
JAVA Create an HourlyEmployee class that inherits from Employee and has two new instance variables: hours,...
JAVA Create an HourlyEmployee class that inherits from Employee and has two new instance variables: hours, which represents the hours worked, and wage, which represents the employee's pay per hour. (Both are doubles.) Create a constructor that takes the arguments first name, last name, social security number, hourly wage, and the number of hours worked. Also create accessors, mutators, an earnings method that returns the money earned by the employee this week, and a toString method that returns information about...
Create a Class with Data Fields and Methods in Java. Provide a Java coding solution for...
Create a Class with Data Fields and Methods in Java. Provide a Java coding solution for the following: 1. Name the class SalonServices 2. Add private data fields: a. salonServiceDescription – This field is a String type b. price - This field is a double type 3. Create two methods that will set the field values. a. The first method setSalonServiceDescription() accepts a String parameter defined as service and assigns it to the salonServiceDescription. The method is not static b....
Java Coding Background You will create a Java class that simulates a water holding tank. The...
Java Coding Background You will create a Java class that simulates a water holding tank. The holding tank can hold volumes of water (measured in gallons) that range from 0 (empty) up to a maximum. If more than the maximum capacity is added to the holding tank, an overflow valve causes the excess to be dumped into the sewer system. Assignment The class will be named HoldingTank. The class attributes will consist of two int fields – current and maxCapacity....
Using the Java programming language: Create and implement a class Car that models a car. A...
Using the Java programming language: Create and implement a class Car that models a car. A Car is invented to have a gasoline tank that can hold a constant max of 12.5 gallons, and an odometer that is set to 0 for a new car. All cars have an original fuel economy of 23.4 miles per gallon, but the value is not constant. Provide methods for constructing an instance of a Car (one should be zero parameter, and the other...
Java- Write a class called Rectangle that inherits from Shape. Write a constructor that has length,...
Java- Write a class called Rectangle that inherits from Shape. Write a constructor that has length, width and colour as arguments. Define enough functions to make the class not abstract
Create a Java class file for a Car class. In the File menu select New File......
Create a Java class file for a Car class. In the File menu select New File... Under Categories: make sure that Java is selected. Under File Types: make sure that Java Class is selected. Click Next. For Class Name: type Car. For Package: select csci2011.lab7. Click Finish. A text editor window should pop up with the following source code (except with your actual name): csci1011.lab7; /** * * @author Your Name */ public class Car { } Implement the Car...
Java Coding Part A Create a class Employee. Employees have a name.   Also give Employee a...
Java Coding Part A Create a class Employee. Employees have a name.   Also give Employee a method paycheck() which returns a double. For basic employees, paycheck is always 0 (they just get health insurance). Give the class a parameterized constructor that takes the name; Add a method reportDeposit. This method prints a report for the employee with the original amount of the paycheck, the amount taken out for taxes (we will do a flat 17%), and the final amount (for...
This code in java: Create a class named car. A car has color, model, company, registration...
This code in java: Create a class named car. A car has color, model, company, registration number. You can stear a car. A car can move forward. A car has a gear box. A typical gear decide weather car is moving forward or backward. A person owns a car. Kindly add some other functionalities like refuel
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT