Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- import java.util.Scanner;
- public class Program {
- public static void main(String[] args) {
- Scanner scan = new Scanner (System.in);
- ArrayList<Car> cars = new ArrayList<Car>();
- while (true) {
- System.out.println("1. Enter data for object");
- System.out.println("2. Print");
- System.out.println("3. Find max/min price");
- System.out.println("4. Exit");
- int op = Integer.parseInt(scan.nextLine());
- if (op == 1) {
- System.out.print("Enter car make: ");
- String make = scan.nextLine();
- System.out.print("Enter car price: ");
- double price = Double.parseDouble(scan.nextLine());
- System.out.print("Enter car max speed: ");
- int maxSpeed = Integer.parseInt(scan.nextLine());
- cars.add(new Car(make, price, maxSpeed));
- } else if (op == 2) {
- for (Car c : cars) {
- System.out.println(c);
- }
- } else if (op == 3) {
- int maxIndex = 0;
- for (int i = 1; i < cars.size(); i++) {
- if (cars.get(i).getPrice() > cars.get(maxIndex).getPrice()) {
- maxIndex = i;
- }
- }
- System.out.println(cars.get(maxIndex));
- } else if (op == 4) {
- break;
- } else {
- System.out.println("invalid input");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement