Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package VehicleCatalogue;
- import java.util.ArrayList;
- import java.util.List;
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- String i = sc.nextLine();
- String type = "";
- String model = "";
- String color = "";
- Double horsePower = 0.0;
- List <Vehicle> vehicles = new ArrayList<>();
- double sum = 0;
- double sum1 = 0;
- double counter = 0;
- double counter1 = 0.0;
- while (!i.equals("End")){
- String [] input = i.split("\\s+");
- type = input [0];
- model = input [1];
- color = input [2];
- horsePower = Double.parseDouble(input [3]);
- Vehicle vehicle = new Vehicle(type, model, color, horsePower);
- if (vehicle.getType().equals("truck")){
- sum += horsePower;
- counter++;
- }
- else if (vehicle.getType().equals("car")){
- sum1 += horsePower;
- counter1++;
- }
- vehicles.add(vehicle);
- i = sc.nextLine();
- }
- String m = sc.nextLine();
- while (!m.equals("Close the Catalogue")){
- for (Vehicle v: vehicles) {
- if (v.getModel().equals(m)){
- if (v.getType().equals("car")){
- v.setType("Car");
- }
- else if (v.getType().equals("truck")){
- v.setType("Truck");
- }
- System.out.print(v);
- }
- }
- m = sc.nextLine();
- }
- double print = sum/counter;
- double print1 = sum1/counter1;
- String cars = "Cars";
- String truck = "Trucks";
- System.out.printf("%s have average horsepower of: %.2f.", cars, print1);
- System.out.println();
- System.out.printf("%s have average horsepower of: %.2f.", truck, print);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement