Answer to Question #293954 in Java | JSP | JSF for sai

Question #293954

· Declare an array as Car with size 10.

· Take 10 Car’s information from user and store them in specified array.

· Call findCarList method from Main class to get all cars information related to a given model name and display then within this method.

· Model name should be taken from Main class and pass to findCarList method as argument as well as Car array (with size 10).

Design findCarList method in Car classas follows:

· it will take a model(car model) as parameter and array of cars (with size 10)

· displays List of cars for the given model from the list .

· If there are no cars, then shows “No cars found”.


1
Expert's answer
2022-02-04T14:49:43-0500
import java.util.Scanner;


class App {


	static void findCarList(String model, String cars[]) {
		int c = 0;
		for (int i = 0; i < cars.length; i++) {
			if (model.compareToIgnoreCase(cars[i]) == 0) {
				System.out.print(model);
				c++;
			}
		}
		if (c == 0) {
			System.out.println("No cars found");
		}
	}


	public static void main(String[] args) {
		Scanner keyBoard = new Scanner(System.in);
		String cars[] = new String[10];


		for (int i = 0; i < cars.length; i++) {
			System.out.print("Enter model name " + (i + 1) + ": ");
			cars[i] = keyBoard.nextLine();
		}


		System.out.print("Enter model name to search: ");
		String model = keyBoard.nextLine();
		findCarList(model, cars);
		keyBoard.close();
	}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS