Created
December 12, 2013 04:05
-
-
Save russjr08/7923038 to your computer and use it in GitHub Desktop.
My entry to Challenge #144 on /r/DailyProgrammer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.ArrayList; | |
import java.util.Scanner; | |
/** | |
* User: russjr08 | |
* Date: 12/11/13 | |
* Time: 9:40 PM | |
*/ | |
public class Challenge { | |
public static void main(String... args){ | |
ArrayList<Item> items = new ArrayList<Item>(); | |
ArrayList<Item> secondItemList = new ArrayList<Item>(); | |
int numItems; | |
Scanner input = new Scanner(System.in); | |
System.out.println("How many items?"); | |
numItems = input.nextInt(); | |
input.nextLine(); | |
System.out.println("Enter First List"); | |
for(int i = 0; i < numItems; i++){ | |
String data = input.nextLine(); | |
items.add(new Item(data.split(" ")[0], Integer.valueOf(data.split(" ")[1]))); | |
} | |
System.out.println("Enter Second List"); | |
for(int i = 0; i < numItems; i++){ | |
String data = input.nextLine(); | |
secondItemList.add(new Item(data.split(" ")[0], Integer.valueOf(data.split(" ")[1]))); | |
} | |
for(Item item : items){ | |
for(Item second : secondItemList){ | |
if(item.name.equalsIgnoreCase(second.name)){ | |
if(item.price > second.price){ | |
System.out.println(String.format("%s -%s", item.name, item.price - second.price)); | |
}else if(item.price < second.price){ | |
System.out.println(String.format("%s +%s", item.name, second.price - item.price)); | |
} | |
} | |
} | |
} | |
} | |
} | |
class Item{ | |
public String name; | |
public int price; | |
public Item(String name, int price){ | |
this.name = name; | |
this.price = price; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment