Java Program You have been assigned to create a program that

Java Program:

You have been assigned to create a program that can be used by dealers. The following table gives the available cars in the dealership and their features.

You must create a program that it is easy to maintain, to add new cars in the future. This is a good task for using Java and its OOP features!

As a developer you must:

1.Create an overall class named Car and place in it all the common variables (class fields) and methods that are shared by all the cars.

2.After doing that, create classes for each car type, such as Corolla and Yaris. Use the Inheritance in those classes.

3.You shall create getters(accessors) and setters(mutators) for car colors. The user can only change a car color that is available for a given car. Different cars have difference color choices!

4.You shall provide a way to add new (the optional) accessories to the standard cars (see last column of the table). Please remember to update the final car price based on the additional accessories.

5.Create a method to print the car info, containing their description, final price, color, and accessories (standard and optional ones if requested by the user).

6.Create a program that creates all these cars, change the color of some, change the accessories of others and print car info for all of them in a terminal window.

Notes:

1.No need to use Scanner input. Just hardcode the creation of the cars in your main program just to check if all your functionality has been correctly implemented by you.

power windows ($500)

Power lockers ($300),

power windows($700)

($1000.00),

Power lockers ($300)

Power lockers,

power windows

Toyota Models Description Price Available Colors Standard Accessories Allowed optional Accessories
Corolla Toyota Corolla debuts at the 2016 New York Auto Show celebrating its golden anniversary with a new 50th anniversary trim package 18500.00 Blue, green Air-conditioning Power lockers ($300)

power windows ($500)

Yaris the new compact Toyota vehicle will be available in the mid 2016 20000.00 Red, Yellow, White None Air-conditioning ($1000.00),

Power lockers ($300),

power windows($700)

Camry for those who dare to be bold, and with its striking hood lines this is one ride that commands attention 23000.00 Black, Silver Power lockers None
RAV4 Toyota has upped the RAV4’s safety features game for 2017 by adding pre-collision braking, lane departure warning with steering assist 25000.00 Green, White power windows Air-conditioning

($1000.00),

Power lockers ($300)

Prius Prius Prime encompasses this vision, where a vehicle can be as inspiring to the human spirit as it is mindful of the world around us 30000.00 White, Silver Air-conditioning,

Power lockers,

power windows

Manual stick

Solution

Car.java

import java.util.ArrayList;

public class Car{
    public String model;
    public String description;
    public double price;
    public String color;
    ArrayList<String> colors;
    ArrayList<String> standardAccessories;
    ArrayList<String> allowedOptionalAccessories;
    ArrayList<String> optionalAccessories;

    public ArrayList<String> getColor(){
        return colors;
    }

    public void setColor(String color){
        if (colors.contains(color)){
            this.color = color;
        }
        else{
            System.out.println(\"This color is not available for this model\");
        }
    }

    public void addOptionalAccessories(String accessory){
        if (allowedOptionalAccessories.contains(accessory)){
            optionalAccessories.add(accessory);
            if (accessory == \"Power lockers\"){
                price += 300;
            }
            else if (accessory == \"Power Windows\"){
                price += 500;
            }
            else if (accessory == \"Air Conditioning\"){
                price += 1000;
            }
        }
        else{
            System.out.println(\"This accessory is not available with this model\");
        }
    }

    public void printCar(){
        System.out.println(model+\"\ \");
        System.out.println(description+\"\ \");
        System.out.println(price+\"\ \");
        System.out.println(colors+\"\ \");
        System.out.println(standardAccessories+\"\ \");
        System.out.println(allowedOptionalAccessories+\"\ \");
    }
}

Main.java

import java.util.ArrayList;

public class Main{
    static Corolla corolla;
    static Yaris yaris;
    static Camry camry;
    static RAV4 rav4;
    static Prius prius;
    class Corolla extends Car{
        Corolla(){
            model = \"Corolla\";
            description = \"Toyota Corolla debuts at the 2016 New York Auto Show celebrating its golden anniversary with a new 50th anniversary trim package\";
            price = 18500.00;
            colors = new ArrayList<String>();
            colors.add(\"blue\");
            colors.add(\"green\");
            standardAccessories = new ArrayList<String>();
            standardAccessories.add(\"Air Conditioning\");
            allowedOptionalAccessories = new ArrayList<String>();
            allowedOptionalAccessories.add(\"Power lockers ($300)\");
            allowedOptionalAccessories.add(\"power windows ($500)\");
        }
    }

    class Yaris extends Car{
        Yaris(){
            model = \"Yaris\";
            description = \"the new compact Toyota vehicle will be available in the mid 2016\";
            price = 20000.00;
            colors = new ArrayList<String>();
            colors.add(\"Red\");
            colors.add(\"Yellow\");
            colors.add(\"White\");
            //standardAccessories = new ArrayList<String>();
            allowedOptionalAccessories = new ArrayList<String>();
            allowedOptionalAccessories.add(\"Air-conditioning\");
            allowedOptionalAccessories.add(\"Power lockers\");
            allowedOptionalAccessories.add(\"power windows\");
        }
    }

    class Camry extends Car{
        Camry(){
            model = \"Camry\";
            description = \"for those who dare to be bold, and with its striking hood lines this is one ride that commands attention\";
            price = 23000.00;
            colors = new ArrayList<String>();
            colors.add(\"Black\");
            colors.add(\"Silver\");
            standardAccessories = new ArrayList<String>();
            standardAccessories.add(\"Power lockers\");
            //allowedOptionalAccessories = new ArrayList<String>();
        }
    }


    class RAV4 extends Car{
        RAV4(){
            model = \"RAV4\";
            description = \" Toyota has upped the RAV4’s safety features game for 2017 by adding pre-collision braking, lane departure warning with steering assist\";
            price = 25000.00;
            colors = new ArrayList<String>();
            colors.add(\"Green\");
            colors.add(\"White\");
            standardAccessories = new ArrayList<String>();
            standardAccessories.add(\"power windows\");
            allowedOptionalAccessories = new ArrayList<String>();
            allowedOptionalAccessories.add(\"Air-conditioning\");
            allowedOptionalAccessories.add(\"Power lockers\");
        }
    }

    class Prius extends Car{
        Prius(){
            model = \"Prius\";
            description = \"Prius Prime encompasses this vision, where a vehicle can be as inspiring to the human spirit as it is mindful of the world around us\";
            price = 30000.00;
            colors = new ArrayList<String>();
            colors.add(\"White\");
            colors.add(\"Silver\");
            standardAccessories = new ArrayList<String>();
            standardAccessories.add(\"Power Windows\");
            standardAccessories.add(\"Power Lockers\");
            standardAccessories.add(\"Air Conditioning\");
            allowedOptionalAccessories = new ArrayList<String>();
            allowedOptionalAccessories.add(\"Manual Stick\");
        }
    }

    public static void main(String[] args) {
        corolla = new Corolla();
        yaris = new Yaris();
        camry = new Camry();
        rav4 = new RAV4();
        prius = new Prius();
    }
}

Java Program: You have been assigned to create a program that can be used by dealers. The following table gives the available cars in the dealership and their f
Java Program: You have been assigned to create a program that can be used by dealers. The following table gives the available cars in the dealership and their f
Java Program: You have been assigned to create a program that can be used by dealers. The following table gives the available cars in the dealership and their f
Java Program: You have been assigned to create a program that can be used by dealers. The following table gives the available cars in the dealership and their f

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site