Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Go to Java Online Compiler (Click it). Copy all provided code and requirements below. Finish all TODOs and test your code at the online compiler.

Go to Java Online Compiler (Click it). Copy all provided code and requirements below. Finish all TODOs and test your code at the online compiler. Do NOT modify any provided code. IMPORTANT When completed, copy all code back to the box below for submission. import java.util.*;

//A provided class representing vehicle, do NOT modify it class Vehicle { private double price; public Vehicle(double price) { this.price = price; } }

public class Main { public static void main(String[] args) { /** Expected Output: * >>Number1 = 0 * >>Number2 = 0 * >>Number3 = 3 */ System.out.println(">>Number1 = " + countCarsInModel(null, null)); System.out.println(">>Number2 = " + countCarsInModel(new ArrayList(), "BMW")); List vehicles = new ArrayList<>(Arrays.asList( null, new Vehicle(3.3), new Car(4.4, null), new Car(5.5, "Benz"), new Car(6.6, "BMW"), new Car(7.7, "Benz"), new Car(8.8, new String("Benz")), new Vehicle(9.9), null )); System.out.println(">>Number3 = " + countCarsInModel(vehicles, "Benz")); }

/* ==== Do NOT modify any code above this line ==== */

/** * TODO #2: write a public static method named countCarsInModel that * - accepts two arguments, a list of vehicle and a String requiredModel * - return the number of cars of the specified model or return 0 if there is no such car * - NOTE: the given list can be null or empty; the given requiredModel can be null and is considered invalid * - NOTE: vehicles in the given list can be null or not a car * - NOTE: the model of a car can be null and is considered invalid */ }

/** * TODO #1: write a subclass of Vehicle named Car that * - has one private field named model of String type * - has an all-argument constructor that accepts a double price and a String model * - has the get and set methods for model */

// IMPORTANT: When completed, copy all code back to the text box in the quiz for submission.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions