In main:  create at least six Car instances, ensuring that at least three have model years less than 2018. create at least four Car instances using the parameterized constructor. create at least two more Car instances with the no-arg constructor use the Car class setter methods to assign values to all data members of these two cars. use the "array initializer" syntax to make an array to hold all Car objects. call the method named carsValue with the array as its sole argument. print the value returned by carsValue and the value in the unitsSold data member.  In carsValue use a foreach loop to process the array passed into the method as follows: reduce the price of all vehicles with model years less than 2018 by 25%. print the state of each Car object using the toString method. calculate the total value of the Car objects in the array. return the total value to main.

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

 I have the first program file. It's called Cars, I have 6 cars all set up. I'm missing the 25% off of 2018 year and older cars, and everything looks fine but I have alot of errors popping up. This is what my professor wants: 

  • code a main method and another value-returning method named carsValue
  • In main: 
    • create at least six Car instances, ensuring that at least three have model years less than 2018.
    • create at least four Car instances using the parameterized constructor.
    • create at least two more Car instances with the no-arg constructor
    • use the Car class setter methods to assign values to all data members of these two cars.
    • use the "array initializer" syntax to make an array to hold all Car objects.
    • call the method named carsValue with the array as its sole argument.
    • print the value returned by carsValue and the value in the unitsSold data member. 
  • In carsValue
    • use a foreach loop to process the array passed into the method as follows:
    • reduce the price of all vehicles with model years less than 2018 by 25%.
    • print the state of each Car object using the toString method.
    • calculate the total value of the Car objects in the array.
    • return the total value to main.

my code:

public static void main(String[] args) {
        Cars car1 = new Cars ("Nissan", "GT-R", 2018, 80000.0, "Matte Black");
        Cars car2 = new Cars ("Nissan", "350z", 2009, 14279.0, "Black");
        
        Cars car3 = new Cars();
        car3.setMake("Nissan");
        car3.setModel("370z");
        car3.setYear(2018);
        car3.setPrice(43349.0);
        car3.setColor("Black");
        
        Cars car4 = new Cars();
        car4.setMake("Nissan");
        car4.setModel("Z");
        car4.setYear(2023);
        car4.setPrice(42990.0);
        car4.setColor("Black");
        
        Cars car5 = new Cars();
        car5.setMake("Lamborghini");
        car5.setModel("Aventador S");
        car5.setYear(2018);
        car5.setPrice(418000.0);
        car5.setColor("Matte Black");
        
        Cars car6 = new Cars();
        car6.setMake("Chevrolet");
        car6.setModel("Camaro");
        car6.setYear(2022);
        car6.setPrice(43845.0);
        car6.setColor("Black");
    
        Cars tot[] = {car1,car2,car3,car4,car5,car6};
        
        carsValue(tot);
    }
        private static double carsValue(Cars[] tot) {
            double totalValue = 0;
            
                for (Cars tot2: tot) {
                    Cars.unitsSold++;
                    totalValue = totalValue + tot2.getPrice();
                    System.out.println(tot2);
                }
                System.out.println("Your " + Cars.unitsSold + "cars are worth " + String.format("$%.,2", totalValue));
                
                return totalValue;
        }
    

}

Expert Solution
steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
Unreferenced Objects
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