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...
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....
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
JAVA PROBLEM Part 1: Create a Car class in accordance with the following specifications. I will...
JAVA PROBLEM Part 1: Create a Car class in accordance with the following specifications. I will provide the CarClassTester class as a test driver to test your Car class for its basic structure. Do not change the CarClassTester class source code. After you get your Car class working correctly using this test driver, proceed to part 2 below. Car Class Specifications: The Car class must be in a separate package from any driver/tester program. The Car class will contain, at...
Part C (25 pts) Coding question Create a Java class name Store_XXXXX with last 5 digits...
Part C (25 pts) Coding question Create a Java class name Store_XXXXX with last 5 digits of your student ID and write your code in there. A PC store sells many types of computers. The PC can have either 16 or 8 gigabytes of memory. The quality of the PCs can be either New, Refurbished, or Dented. The price list is given as follows: Memory size/Status New Refurbished Dented 16 gigabytes 849.99 729.99 609.99 8 gigabytes 699.99 579.99 439.99 Determine...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT