Advertisement
pexea12

Stupid Car

Feb 19th, 2016
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. package bai3;
  7.  
  8. import java.util.ArrayList;
  9. import java.util.Scanner;
  10.  
  11. /**
  12.  *
  13.  * @author pc
  14.  */
  15. public class Main {
  16.    
  17.     public static Car f3(ArrayList<SUV> cars)
  18.     {
  19.         for (int i = 0; i < cars.size(); ++i){
  20.             for (int j = i + 1; j < cars.size(); ++j) {
  21.                 if (cars.indexOf(i).getTax() < cars.indexOf(j).getTax()) {
  22.                     SUV temp = (SUV)cars.indexOf(i);
  23.                     cars.indexOf(i) = cars.indexOf(j);
  24.                     cars.indexOf(j) = temp;
  25.                 }
  26.             }
  27.         }
  28.         if (cars.size() <= 1) return null;
  29.         return cars.indexOf(1);
  30.     }
  31.    
  32.     public static void main(String[] args)
  33.     {
  34.         int numcar = 0;
  35.         Scanner scanner = new Scanner(System.in);
  36.         String input;
  37.         System.out.println("Enter the number of car:");
  38.         input = scanner.nextLine();
  39.         numcar = Integer.parseInt(input);
  40.         ArrayList<SUV> cars = new ArrayList<>();
  41.         for (int i = 0; i < numcar; i++) {
  42.             SUV car = new SUV();
  43.             System.out.println("Car serial number:");
  44.             car.serialNumber =scanner.nextLine();
  45.             System.out.println("Car price:");
  46.             car.price = Float.parseFloat(scanner.nextLine());
  47.             System.out.println("Car tax:");
  48.             car.ptax = Float.parseFloat(scanner.nextLine());
  49.             cars.add(car);
  50.         }
  51.         Car secondExpCar = f3(cars);
  52.         System.out.println(secondExpCar.display());
  53.     }
  54.            
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement