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

Simple Java class. Create a class Sportscar that inherits from the Car class includes the following:...
Simple Java class. Create a class Sportscar that inherits from the Car class includes the following: a variable roof that holds type of roof (ex: convertible, hard-top,softtop) 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 its called add exception handling to the changespeed method to keep soeed under 65 implement the sound method to print "brooom" to the screen. create one constructor that accepts the...
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....
Create a class to represent a Mammal object that inherits from (extends) the Animal class. View...
Create a class to represent a Mammal object that inherits from (extends) the Animal class. View javadoc for the Mammal class and updated Animal class in homework 4 http://comet.lehman.cuny.edu/sfakhouri/teaching/cmp/cmp326/s19/hw/hw4/ Use the description provided below in UML. Mammal - tailLength : double - numLegs : int + Mammal() + Mammal(double, int) + Mammal(String, int, double, double, char, double, int) //pass values to parent’s overloaded constructor //and assign valid values to tailLength, numLegs or -1 if invalid + setTailLength(double) : void //if...
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 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
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT