diff --git a/create java file b/create java file new file mode 100644 index 0000000..625a431 --- /dev/null +++ b/create java file @@ -0,0 +1,71 @@ +import java.io.FileInputStream; +import java.io.FileWriter; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.Scanner; +class Item { + String name; + int price; + + public Item(String name, int price) { + this.name = name; + this.price = price; + } + + public String toString() { + return this.name + ": " + this.price; + } +} + +//Starts main class +public class Main { + public static void main(String[] args) throws Exception { + //Passing Input file + FileInputStream fis=new FileInputStream("C:\\Users\\Joshna\\eclipse-workspace\\Main\\src\\input.txt"); + Scanner sc=new Scanner(fis); + int number_of_employees = Integer.parseInt(sc.nextLine().split(": ")[1]); + sc.nextLine(); + sc.nextLine(); + sc.nextLine(); + + ArrayList goodies_items = new ArrayList(); + + while(sc.hasNextLine()) + { + String current[] = sc.nextLine().split(": "); + goodies_items.add(new Item(current[0], Integer.parseInt(current[1]))); + } + sc.close(); + + Collections.sort(goodies_items, new Comparator(){ + public int compare(Item a, Item b) { + return a.price - b.price; + } + }); + + int min_diff = goodies_items.get(goodies_items.size()-1).price; + int min_index = 0; + for(int i=0;i