Advertisement
Ivan_Bochev

Main-House

Dec 18th, 2019 (edited)
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.73 KB | None | 0 0
  1. package h;
  2.  
  3. import java.util.*;
  4.  
  5. public class App {
  6.  
  7.     public static void main(String[] args) {
  8.         Scanner sc=new Scanner(System.in);
  9.         House h=new House("Jo","Sofia",22,456);
  10.         House h1=new House("Bobo","Sofia",34,765);
  11.         Apartment ap=new Apartment("Koko","Plovdiv",55,800);
  12.         Apartment ap1=new Apartment("Ivan","Razgrad",80,1000);
  13.        
  14.         ArrayList<GetPrice> list=new ArrayList<>(Arrays.asList(h,h1,ap,ap1));
  15.         GetPrice result=getMaxPrice(list);
  16.         result.print();
  17.     }
  18.  
  19.     private static GetPrice getMaxPrice(ArrayList<GetPrice> list) {
  20.         double maxPrice=list.get(0).getPrice();
  21.         int index=0;
  22.         for(int i=0;i<list.size();i++) {
  23.             if(maxPrice<list.get(i).getPrice()) {
  24.                 index=i;
  25.             }
  26.         }
  27.         return list.get(index);
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement