Question

In: Computer Science

CS Using the following UML outline, create the following abstract parent class along with the 4...

CS

Using the following UML outline, create the following abstract parent class along with the
4 subclasses and Driver class. Implement the Classes, listed attributes and methods along with any additional things that you may need.

Add a driver class that utilizes the methods/attributes in the classes to output the following based on the vehicle type (therefore, you must create an instance for all 4 subclasses in your driver):

1. Vehicle Type (i.e., Car, Airplane, etc.)
2. Transportation method (wheels, wings, etc.)
3. Whether your vehicle transports passengers or not.
4. Whether your vehicle is a passenger vehicle or Cargo Vehicle
5. Whether your vehicle travels on land, water or air.

Implement the following UML:

UML

Vehicle Class (Abstract)

Attributes:

-vehicleType:String
-passengers:boolean

Behaviors:

+Vehicle(vehicleType:String, passengers:boolean):void
+Abstract travelMethod(vehicleType:String):String
+getPassengers():boolean //returns passengers value
+getVehicleType():String

Child Class1:

Car

Attributes:

-travelMethod:String

Behaviors:

+travelMethod(vehicleType:String):String //Returns travelMethod based on vehicleType
for instance if helicopter, the travelMethod = Blades/Propellers, if car then
travelMethod = wheels, if airplane then wings, etc.

+isVehicle():void. //Outputs vehicle type, transportation method, whether it is a passenger vehicle or cargo vehicle and whether it rolls with wheels, flies with wings or flies with blades, or travels on water.

Child Class2:

Airplane

Attributes:

-travelMethod:String

Behaviors:

+travelMethod(vehicleType:String):String //Returns travelMethod based on vehicleType
for instance if helicopter, the travelMethod = Blades/Propellers, if car then
travelMethod = wheels, if airplane then wings, etc.

+isVehicle():void. //Outputs vehicle type, transportation method, whether it is a passenger vehicle or cargo vehicle and whether it rolls with wheels, flies with wings or flies with blades, or travels on water.

Child Class3:

Helicoptor

Attributes:

-travelMethod:String

Behaviors:

+travelMethod(vehicleType:String):String //Returns travelMethod based on vehicleType
for instance if helicopter, the travelMethod = Blades/Propellers, if car then
travelMethod = wheels, if airplane then wings, etc.

+isVehicle():void. //Outputs vehicle type, transportation method, whether it is a passenger vehicle or cargo vehicle and whether it rolls with wheels, flies with wings or flies with blades, or travels on water.

Child Class4:

Boat

Attributes:

-travelMethod:String

Behaviors:

+travelMethod(vehicleType:String):String //Returns travelMethod based on vehicleType
for instance if helicopter, the travelMethod = Blades/Propellers, if car then
travelMethod = wheels, if airplane then wings, etc.

+isVehicle():void. //Outputs vehicle type, transportation method, whether it is a passenger vehicle or cargo vehicle and whether it rolls with wheels, flies with wings or flies with blades, or travels on water.

Deliverables:

1. Parent Class for Vehicle, 4 child classes and 1 Driver class.

2. Screenshots of output

3. Place your name, class, date and assignment in comments at top of each .java file. (Points off for files with no name)

Solutions

Expert Solution

Code for all 5 classes is given below. Code is explained thoroughly in the code comments.5 Classes are : Vehicle , Car, Helicoptor , Airplane , Boat , Driver . The code runs smoothly. As you have not given the Driver class, i have made it on my own to test the program You can run the program according to your liking by giving different values to vehicles in Driver class objects. I have attached the output screenshot in the last.

If need any further clarification please ask in comments.

###########################################################################

CODE-->>>

Vehicle Class

//Abstract super class Vehicle
abstract class Vehicle
{
        //private data members
        private String vehicleType;
        private boolean passengers;
        //public constructor
        public Vehicle(String vehicleType, boolean passengers) {
                this.vehicleType = vehicleType;
                this.passengers = passengers;
        }
        //abstract method
        abstract String  travelMethod(String vehicleType);
        //Accessor functions
        public String getVehicleType() {
                return vehicleType;
        }

        public boolean isPassengers() {
                return passengers;
        }
        
}

Car class

//child class Car
class Car extends Vehicle
{
        //private data member
        private String travelMethod;
        //constructor
        public Car(String vehicleType, boolean passengers)
        {
                //Calling super class Constructor
                super(vehicleType,passengers);
                this.travelMethod="Wheels"; //setting value of travelmethod
        }
        //defining abstract method
        public String travelMethod(String vehicleType)
        {
                return travelMethod;
        }
        //function to display info
        public void isVehicle()
        {
                System.out.println("\nVehicle Type: "+super.getVehicleType());
                if(super.isPassengers()) //if it is passenger vehicle
                        System.out.println("It is a Passenger Vehicle");
                else //if it is cargo
                        System.out.println("It is a Cargo Vehicle");
                System.out.println("Transportation Method: "+travelMethod);
                System.out.println("It rolls with Wheels");
        }
}

Airplane Class

//child class Airplane
class Airplane extends Vehicle
{
        private String travelMethod;
        //constructor
        public Airplane(String vehicleType, boolean passengers)
        {
                super(vehicleType,passengers); //calling super class constructor
                this.travelMethod="Wings";
        }
        //defining abstract method
        public String travelMethod(String vehicleType)
        {
                return travelMethod;
        }
        //function to display info
        public void isVehicle()
        {
                System.out.println("\nVehicle Type: "+super.getVehicleType());
                if(super.isPassengers()) //if passenger vehicle
                        System.out.println("It is a Passenger Vehicle");
                else //if cargo
                        System.out.println("It is a Cargo Vehicle");
                System.out.println("Transportation Method: "+travelMethod);
                System.out.println("It Flies with Wings");
        }
}

Helicoptor Class

//child class Helicoptor
class Helicoptor extends Vehicle
{
        private String travelMethod;
        //constructor
        public Helicoptor(String vehicleType, boolean passengers)
        {
                super(vehicleType,passengers); //super class constructor
                this.travelMethod="Blades";
        }
        public String travelMethod(String vehicleType)
        {
                return travelMethod;
        }
        //function to display info
        public void isVehicle()
        {
                System.out.println("\nVehicle Type: "+super.getVehicleType());
                if(super.isPassengers())
                        System.out.println("It is a Passenger Vehicle");
                else //if cargo
                        System.out.println("It is a Cargo Vehicle");
                System.out.println("Transportation Method: "+travelMethod);
                System.out.println("It flies with Blades");
        }
}

Boat class

//child class boat
class Boat extends Vehicle
{
        private String travelMethod;
        //constructor
        public Boat(String vehicleType, boolean passengers)
        {
                super(vehicleType,passengers); //calling super class constructor
                this.travelMethod="Propeller"; //setting value of travelMethod
        }
        //defining abstract method
        public String travelMethod(String vehicleType)
        {
                return travelMethod;
        }
        //function to display info
        public void isVehicle()
        {
                System.out.println("\nVehicle Type: "+super.getVehicleType());
                if(super.isPassengers()) //if passenger vehicle
                        System.out.println("It is a Passenger Vehicle");
                else //if cargo vehicle
                        System.out.println("It is a Cargo Vehicle");
                System.out.println("Transportation Method: "+travelMethod);
                System.out.println("It travels on Water");
        }
}

Driver Class

*Name:
 * Class:
 * Date:
 */

//driver class
public class Driver {

        public static void main(String[] args) 
        {
                //creating object of each class
                Car car=new Car("Car", true);
                Helicoptor helicoptor=new Helicoptor("Helicoptor", true);
                Airplane airplane=new Airplane("Airplane", false);
                Boat boat=new Boat("Boat", false);
                //calling isVehicle() method to display info
                car.isVehicle();
                helicoptor.isVehicle();
                airplane.isVehicle();
                boat.isVehicle();
                
        }

}

####################################################################

OUTPUT


Related Solutions

Implement the Shape hierarchy -- create an abstract class called Shape, which will be the parent...
Implement the Shape hierarchy -- create an abstract class called Shape, which will be the parent class to TwoDimensionalShape and ThreeDimensionalShape. The classes Circle, Square, and Triangle should inherit from TwoDimensionalShape, while Sphere, Cube, and Tetrahedron should inherit from ThreeDimensionalShape. Each TwoDimensionalShape should have the methods getArea() and getPerimeter(), which calculate the area and perimeter of the shape, respectively. Every ThreeDimensionalShape should have the methods getArea() and getVolume(), which respectively calculate the surface area and volume of the shape. Every...
Here I'm using "person" as an abstract superclass or parent class, and "Student" as a derived/child...
Here I'm using "person" as an abstract superclass or parent class, and "Student" as a derived/child class. // File name: Person.h // Person is the base, or parent for chapter11 #pragma once #include <iostream> #include <string> using namespace std; class Person { private:    string fName;    string lName;    int areaCode;    int phone; public:    Person();    Person(string, string);    void setFirst(string);    void setLast(string);    void setPhoneNumber(int, int);    string getFirstlast();    string getLastFirst();    string getPhoneNumber();...
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...
create the UML Diagram to model a Movie/TV viewing site. Draw a complete UML class diagram...
create the UML Diagram to model a Movie/TV viewing site. Draw a complete UML class diagram which shows: Classes (Only the ones listed in bold below) Attributes in classes (remember to indicate privacy level, and type) No need to write methods Relationships between classes (has is, is a, ...) Use a program like Lucid Cart and then upload your diagram. Each movie has: name, description, length, list of actors, list of prequals and sequals Each TV Show has: name, description,...
Create an abstract class DiscountPolicy. It should have a single abstract method computeDiscount that will return...
Create an abstract class DiscountPolicy. It should have a single abstract method computeDiscount that will return the discount for the purchase of a given number of a single item. The method has two parameters, count and itemCost. Derive a class BulkDiscount from DiscountPolicy. It should have a constructor that has two parameters minimum and percent. It should define the method computeDiscount so that if the quantity purchased of an item is more then minimum, the discount is percent percent.
Follow the UML diagram and directions on the attached file to create a RectangularPrism class and...
Follow the UML diagram and directions on the attached file to create a RectangularPrism class and a RectangularPrismDemo class. --------------------------------------------------------------------------------------------------------------------------------------- RectangularPrism            - length: double       - width: double       - height: double + RectangularPrism() + RectangularPrism(l:double,w:double, h:double) + setLength(l:double):void + setWidth(w:double):void + setHeight(h:double):void +getLength():double +getWidth():double +getHeight():double +getVolume():double +getSurfaceArea():double +toString():String --------------------------------------------------------------------------------------------------------------------- Create a RectangularPrism class in its own file based on the UML Create a separate RectangularPrismDemo Class file to demonstrate your class by doing the following: Create two prisms,...
(Using Date Class) The following UML Class Diagram describes the java Date class: java.util.Date +Date() +Date(elapseTime:...
(Using Date Class) The following UML Class Diagram describes the java Date class: java.util.Date +Date() +Date(elapseTime: long) +toString(): String +getTime(): long +setTime(elapseTime: long): void Constructs a Date object for the current time. Constructs a Date object for a given time in milliseconds elapsed since January 1, 1970, GMT. Returns a string representing the date and time. Returns the number of milliseconds since January 1, 1970, GMT. Sets a new elapse time in the object. The + sign indicates public modifer...
(Using Random Class) The following UML Class Diagram describes the java Random class: java.util.Random +Random() +Random(seed:...
(Using Random Class) The following UML Class Diagram describes the java Random class: java.util.Random +Random() +Random(seed: long) +nextInt(): int +nextInt(n: int): int +nextLong(): long +nextDouble(): double +nextFloat(): float +nextBoolean(): boolean Constructs a Random object with the current time as its seed. Constructs a Random object with a specified seed. Returns a random int value. Returns a random int value between 0 and n (exclusive). Returns a random long value. Returns a random double value between 0.0 and 1.0 (exclusive). Returns...
Write a Java application that implements the following: Create an abstract class called GameTester. The GameTester...
Write a Java application that implements the following: Create an abstract class called GameTester. The GameTester class includes a name for the game tester and a boolean value representing the status (full-time, part-time). Include an abstract method to determine the salary, with full-time game testers getting a base salary of $3000 and part-time game testers getting $20 per hour. Create two subclasses called FullTimeGameTester, PartTimeGameTester. Create a console application that demonstrates how to create objects of both subclasses. Allow the...
Write in C++ Abstract/Virtual Rock Paper Scissors Create an abstract Player class that consists of private...
Write in C++ Abstract/Virtual Rock Paper Scissors Create an abstract Player class that consists of private data for name, selection, wins, and losses. It must have a non-default constructor that requires name. It may not contain a default constructor. Create overloaded functions for the ++ and - - operator. The overloaded ++operator will add to the number of wins, while the - - operator will add to the losses. You will create two different child classes of player, Human and...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT