Answer to Question #307722 in Java | JSP | JSF for Manoj

Question #307722

Design a Car model class under package :package6 with the following attributes:




Member Field Name



Type



licenceNumber



String



Model



String



currentMileage



Double



engineSize



Intege



Mark all the attributes as private & create appropriate Getters & Setters




Design another class as Main under package :package6, where you need to implement logic as follows:



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 current Mileage & engine Size



Current Mileage & engine Size values 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 class as follows

1
Expert's answer
2022-03-10T07:15:17-0500


import java.util.*;


class Car {
	private String licenceNumber;
	private String model;
	private double currentMileage;
	private int engineSize;


	public Car() {
	}


	/***
	 * Constructor
	 * 
	 * @param licenceNumber
	 * @param model
	 * @param currentMileage
	 * @param engineSize
	 */
	public Car(String licenceNumber, String model, double currentMileage, int engineSize) {
		this.licenceNumber = licenceNumber;
		this.model = model;
		this.currentMileage = currentMileage;
		this.engineSize = engineSize;
	}


	/**
	 * @return the licenceNumber
	 */
	public String getLicenceNumber() {
		return licenceNumber;
	}


	/**
	 * @param licenceNumber the licenceNumber to set
	 */
	public void setLicenceNumber(String licenceNumber) {
		this.licenceNumber = licenceNumber;
	}


	/**
	 * @return the model
	 */
	public String getModel() {
		return model;
	}


	/**
	 * @param model the model to set
	 */
	public void setModel(String model) {
		this.model = model;
	}


	/**
	 * @return the currentMileage
	 */
	public double getCurrentMileage() {
		return currentMileage;
	}


	/**
	 * @param currentMileage the currentMileage to set
	 */
	public void setCurrentMileage(double currentMileage) {
		this.currentMileage = currentMileage;
	}


	/**
	 * @return the engineSize
	 */
	public int getEngineSize() {
		return engineSize;
	}


	/**
	 * @param engineSize the engineSize to set
	 */
	public void setEngineSize(int engineSize) {
		this.engineSize = engineSize;
	}
}


class App {


	private static void findCarList(Car cars[]) {


		for (int i = 0; i < 10; i++) {
			System.out.println("The car licence number " + (i + 1) + ": " + cars[i].getLicenceNumber());
			System.out.println("The car model " + (i + 1) + ": " + cars[i].getModel());
			System.out.println("The car current mileage " + (i + 1) + ": " + cars[i].getCurrentMileage());
			System.out.println("The car engine size " + (i + 1) + ": " + cars[i].getEngineSize() + "\n");
		}
	}


	public static void main(String[] args) {


		Scanner keyboard = new Scanner(System.in);


		Car cars[] = new Car[10];
		String licenceNumber;
		String model;
		double currentMileage;
		int engineSize;


		for (int i = 0; i < 10; i++) {
			System.out.print("Enter car licence number " + (i + 1) + ": ");
			licenceNumber = keyboard.nextLine();
			System.out.print("Enter car model " + (i + 1) + ": ");
			model = keyboard.nextLine();
			System.out.print("Enter car current mileage " + (i + 1) + ": ");
			currentMileage = keyboard.nextDouble();
			System.out.print("Enter car engine size " + (i + 1) + ": ");
			engineSize = keyboard.nextInt();
			keyboard.nextLine();
			cars[i] = new Car(licenceNumber, model, currentMileage, engineSize);
		}
		findCarList(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