Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package gameStore;
- public class Games {
- private String title;
- public Games(String inTitle){
- setTitle(inTitle);
- }
- public int hashCode() {
- return title.hashCode();
- }
- public boolean equals(Object obj) {
- if (!(obj instanceof Games)) {
- return false;
- }
- Games other = (Games)obj;
- return title.equals(other.title);
- }
- // private String getTitle() {
- // return title;
- // }
- //
- //
- private void setTitle(String title) {
- this.title = title;
- }
- }
- _____________________________________________________________________________
- package gameStore;
- public class LocalStores {
- private String nameOfStore;
- public LocalStores(String inNameOfStore){
- setNameOfStore(inNameOfStore);
- }
- private void setNameOfStore(String nameOfStore){
- this.nameOfStore = nameOfStore;
- }
- public int hashCode() {
- return nameOfStore.hashCode();
- }
- public boolean equals(Object obj) {
- if (!(obj instanceof LocalStores)) {
- return false;
- }
- LocalStores other = (LocalStores)obj;
- return nameOfStore.equals(other.nameOfStore);
- }
- }
- __________________________________________________________________________
- package gameStore;
- import java.io.*;
- import java.util.*;
- import java.util.concurrent.atomic.*;
- public class GameStoreApp {
- static HashMap<LocalStores, HashMap<Games, AtomicInteger>> inStock = new HashMap<LocalStores, HashMap<Games, AtomicInteger>>();
- static HashMap<LocalStores, HashMap<Games, AtomicInteger>> rentedOut = new HashMap<LocalStores, HashMap<Games, AtomicInteger>>();
- static HashMap<LocalStores, HashMap<Games, AtomicInteger>> overDue = new HashMap<LocalStores, HashMap<Games, AtomicInteger>>();
- static HashMap<Games, AtomicInteger> stockMap = new HashMap<Games, AtomicInteger>();
- static HashMap<Games, AtomicInteger> rentedMap = new HashMap<Games, AtomicInteger>();
- static HashMap<Games, AtomicInteger> dueMap = new HashMap<Games, AtomicInteger>();
- static void populateHashMaps(){
- goInStock();
- goOverDue();
- goRentedOut();
- }
- public static void main(String[] args) {
- populateHashMaps();
- }
- private static void goInStock() {
- try{
- Scanner in = new Scanner (new FileReader("inStockFile.txt"));
- try {
- String line = in.nextLine();
- while (in.hasNextLine()) {
- String[] fields = line.split("[\\t]");
- if (fields.length == 3) {
- addToInStockMap(new Games(fields[0]), new LocalStores(fields[1]), new AtomicInteger(Integer.parseInt(fields[2])));
- }
- line = in.nextLine();
- }
- }
- finally {
- in.close();
- }
- }
- catch (Exception ex){
- System.out.println("In Stock File Exception error: " + ex);
- }
- }
- private static void goRentedOut() {
- try{
- Scanner in = new Scanner (new FileReader("rentedOutFile.txt"));
- try {
- String line = in.nextLine();
- while (in.hasNextLine()) {
- String[] fields = line.split("[\\t]");
- if (fields.length == 3) {
- addToRentedOutMap(new Games(fields[0]), new LocalStores(fields[1]), new AtomicInteger(Integer.parseInt(fields[2])));
- }
- line = in.nextLine();
- }
- }
- finally {
- in.close();
- }
- }
- catch (Exception ex){
- System.out.println("Rented Out File Exception error: " + ex);
- }
- }
- private static void goOverDue() {
- try{
- Scanner in = new Scanner (new FileReader("overDueFile.txt"));
- try {
- String line = in.nextLine();
- while (in.hasNextLine()) {
- String[] fields = line.split("[\\t]");
- if (fields.length == 3) {
- addToOverDueMap(new Games(fields[0]), new LocalStores(fields[1]), new AtomicInteger(Integer.parseInt(fields[2])));
- }
- line = in.nextLine();
- }
- }
- finally {
- in.close();
- }
- }
- catch (Exception ex){
- System.out.println("Over Due File Exception error: " + ex);
- }
- }
- static void addToInStockMap (Games games, LocalStores store, AtomicInteger value){
- stockMap.put(games, value);
- inStock.put(store, stockMap);
- }
- static void addToRentedOutMap (Games games, LocalStores store, AtomicInteger value){
- stockMap.put(games, value);
- inStock.put(store, rentedMap);
- }
- static void addToOverDueMap (Games games, LocalStores store, AtomicInteger value){
- stockMap.put(games, value);
- inStock.put(store, dueMap);
- }
- static void checkStock(){
- // new AtominInteger k = inStock.get(stockMap).get(AtomicInteger);
- // int ko = inStock.get(stockMap).get(AtomicInteger);
- // String ke = inStock.get(stockMap).get(LocalStores);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement