First question: Why am having an error pop up when running my program that says: "Editor does not contain main type" on my TestVehicle program? Second question: Does the program follow what my professor wants in his instructions? I have gone over them but would like another opinion. Instructions: Design and save your Motor class before you make Vehicle, so you can specify Motor as a Vehicle data attribute. Class Motor (make this class first because Motor is an attribute of class Vehicle) Attributes (all private) int cylinders int hp String type (possible values being gas, deisel, electric etc) Methods (all public) a constructor that can assign values to all attributes getters and for each attribute (setters not needed) a toString method that returns the status of a Motor instance, all attributes. Class Vehicle Attributes (all private) String make String model int year double price Motor motor (see below) Methods (public) a constructor that can assign values to all attributes a setter for the price a getter for the price a toString method that returns the status of a Vehicle instance, all attributes. Class TestVehicle This is the executable class. In the main method, make an arraylist of five or six Vehicle instances and then use a foreach loop to display them. My code for all three files: Motor: private int cylinders; private int hp; private String type; public Motor (int cylinders, int hp, String type) { this.cylinders = cylinders; this.hp = hp; this.type = type; } public int getCylinders() { return cylinders; } public int getHp() { return hp; } public String getType() { return type; } @Override public String toString() { return "Motor (" + "Cylinders: " + cylinders + "HP: " + hp + "Type: " + type + ')'; } } Vehicle: private String make; private String model; private int year; private double price; private Motor motor; public Vehicle (String make, String model, int year, double price, Motor motor) { this.make = make; this.model = model; this.year = year; this.price = price; this.motor = motor; } public double getPrice() { return price; } public void setPrice(double price) { this.price = price; } @Override public String toString() { return "Vehicle: " + "Make = " + make + "Model = " + model + "Year = " + year + "Price = " + price + "Motor = " + motor; } } TestVehicle: import java.util.ArrayList; public static void main(String[] args) { Vehicle veh1 = new Vehicle ("Nissan", "GT-R", 2018, 80000.0, new Motor(6, 565, "Gasoline Fuel")); Vehicle veh2 = new Vehicle ("Nissan", "350z", 2009, 14279.0, new Motor(6, 306, "Gasoline Fuel")); Vehicle veh3 = new Vehicle ("Nissan", "370z", 2018, 43349.0, new Motor(6, 332, "Gasoline Fuel")); Vehicle veh4 = new Vehicle ("Nissan", "Z", 2023, 42990.0, new Motor(6, 400, "Electric or Gasoline Fuel")); Vehicle veh5 = new Vehicle ("Lamborghini", "Aventador S", 2018, 418000.0, new Motor(12, 691, "Gasoline Fuel")); Vehicle veh6 = new Vehicle ("Chevrolet", "Camaro", 2022, 43845.0, new Motor(8, 650, "Gasoline Fuel")); ArrayList vehicleType = new ArrayList() { { add(veh1); add(veh2); add(veh3); add(veh4); add(veh5); add(veh6); } }; for (Vehicle eachVeh: vehicleType) { System.out.println(eachVeh); } } }

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

First question:

Why am having an error pop up when running my program that says: "Editor does not contain main type" on my TestVehicle program?

Second question:

Does the program follow what my professor wants in his instructions? I have gone over them but would like another opinion. 

Instructions: 

Design and save your Motor class before you make Vehicle, so you can specify Motor as a Vehicle data attribute.

Class Motor (make this class first because Motor is an attribute of class Vehicle)
Attributes (all private)

  • int cylinders
  • int hp
  • String type (possible values being gasdeiselelectric etc)

Methods (all public)

  • constructor that can assign values to all attributes
  • getters and for each attribute (setters not needed)
  • toString method that returns the status of a Motor instance, all attributes.

Class Vehicle
Attributes (all private)

  • String make
  • String model
  • int year
  • double price
  • Motor motor (see below)

Methods (public)

  • a constructor that can assign values to all attributes
  • a setter for the price
  • a getter for the price
  • a toString method that returns the status of a Vehicle instance, all attributes.

Class TestVehicle
This is the executable class. In the main method, make an arraylist of five or six Vehicle instances and then use a foreach loop to display them.

My code for all three files:

Motor: 


        private int cylinders;
        private int hp;
        private String type;
        
        public Motor (int cylinders, int hp, String type) {
            this.cylinders = cylinders;
            this.hp = hp;
            this.type = type;
    }
        public int getCylinders() {
            return cylinders;
        }
        public int getHp() {
            return hp;
        }
        public String getType() {
            return type;
        }
        @Override
        public String toString() {
            return "Motor (" + "Cylinders: " + cylinders + "HP: " + hp + "Type: " + type + ')';
        }

}

Vehicle:

    private String make;
    private String model;
    private int year;
    private double price;
    private Motor motor;
    
    public Vehicle (String make, String model, int year, double price, Motor motor) {
        this.make = make;
        this.model = model;
        this.year = year;
        this.price = price;
        this.motor = motor;
    }
    
    public double getPrice() {
        return price;
    }
    public void setPrice(double price) {
        this.price = price;
    }
    
    @Override
    public String toString() {
        return "Vehicle: " + "Make = " + make + "Model = " + model + "Year = " + year + "Price = " + price + "Motor = " + motor;
    }
}

TestVehicle: 

import java.util.ArrayList;

public static void main(String[] args) {
        Vehicle veh1 = new Vehicle ("Nissan", "GT-R", 2018, 80000.0, new Motor(6, 565, "Gasoline Fuel"));
        Vehicle veh2 = new Vehicle ("Nissan", "350z", 2009, 14279.0, new Motor(6, 306, "Gasoline Fuel"));
        Vehicle veh3 = new Vehicle ("Nissan", "370z", 2018, 43349.0, new Motor(6, 332, "Gasoline Fuel"));
        Vehicle veh4 = new Vehicle ("Nissan", "Z", 2023, 42990.0, new Motor(6, 400, "Electric or Gasoline Fuel"));
        Vehicle veh5 = new Vehicle ("Lamborghini", "Aventador S", 2018, 418000.0, new Motor(12, 691, "Gasoline Fuel"));
        Vehicle veh6 = new Vehicle ("Chevrolet", "Camaro", 2022, 43845.0, new Motor(8, 650, "Gasoline Fuel"));
        
        ArrayList<Vehicle> vehicleType = new ArrayList<Vehicle>() {
            {
                add(veh1);
                add(veh2);
                add(veh3);
                add(veh4);
                add(veh5);
                add(veh6);
            }
        };
        for (Vehicle eachVeh: vehicleType) {
            System.out.println(eachVeh);
        }
    }

}

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 4 images

Blurred answer
Knowledge Booster
Class
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education