Advertisement
ledafaze

Untitled

Mar 14th, 2012
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package gameStore;
  2.  
  3. public class Games {
  4.  
  5. private String title;
  6.  
  7. public Games(String inTitle){
  8. setTitle(inTitle);
  9. }
  10.  
  11. public int hashCode() {
  12. return title.hashCode();
  13. }
  14.  
  15. public boolean equals(Object obj) {
  16. if (!(obj instanceof Games)) {
  17. return false;
  18. }
  19. Games other = (Games)obj;
  20. return title.equals(other.title);
  21. }
  22.  
  23.  
  24.  
  25. // private String getTitle() {
  26. // return title;
  27. // }
  28. //
  29. //
  30. private void setTitle(String title) {
  31. this.title = title;
  32. }
  33.  
  34. }
  35. _____________________________________________________________________________
  36. package gameStore;
  37.  
  38. public class LocalStores {
  39.  
  40. private String nameOfStore;
  41.  
  42. public LocalStores(String inNameOfStore){
  43. setNameOfStore(inNameOfStore);
  44. }
  45.  
  46. private void setNameOfStore(String nameOfStore){
  47. this.nameOfStore = nameOfStore;
  48. }
  49.  
  50. public int hashCode() {
  51. return nameOfStore.hashCode();
  52. }
  53.  
  54. public boolean equals(Object obj) {
  55. if (!(obj instanceof LocalStores)) {
  56. return false;
  57. }
  58. LocalStores other = (LocalStores)obj;
  59. return nameOfStore.equals(other.nameOfStore);
  60. }
  61.  
  62. }
  63. __________________________________________________________________________
  64.  
  65. package gameStore;
  66.  
  67. import java.io.*;
  68. import java.util.*;
  69. import java.util.concurrent.atomic.*;
  70.  
  71.  
  72. public class GameStoreApp {
  73.  
  74. static HashMap<LocalStores, HashMap<Games, AtomicInteger>> inStock = new HashMap<LocalStores, HashMap<Games, AtomicInteger>>();
  75. static HashMap<LocalStores, HashMap<Games, AtomicInteger>> rentedOut = new HashMap<LocalStores, HashMap<Games, AtomicInteger>>();
  76. static HashMap<LocalStores, HashMap<Games, AtomicInteger>> overDue = new HashMap<LocalStores, HashMap<Games, AtomicInteger>>();
  77. static HashMap<Games, AtomicInteger> stockMap = new HashMap<Games, AtomicInteger>();
  78. static HashMap<Games, AtomicInteger> rentedMap = new HashMap<Games, AtomicInteger>();
  79. static HashMap<Games, AtomicInteger> dueMap = new HashMap<Games, AtomicInteger>();
  80.  
  81. static void populateHashMaps(){
  82. goInStock();
  83. goOverDue();
  84. goRentedOut();
  85. }
  86.  
  87. public static void main(String[] args) {
  88. populateHashMaps();
  89. }
  90.  
  91. private static void goInStock() {
  92. try{
  93. Scanner in = new Scanner (new FileReader("inStockFile.txt"));
  94. try {
  95. String line = in.nextLine();
  96. while (in.hasNextLine()) {
  97. String[] fields = line.split("[\\t]");
  98. if (fields.length == 3) {
  99. addToInStockMap(new Games(fields[0]), new LocalStores(fields[1]), new AtomicInteger(Integer.parseInt(fields[2])));
  100. }
  101. line = in.nextLine();
  102. }
  103. }
  104. finally {
  105. in.close();
  106. }
  107. }
  108.  
  109. catch (Exception ex){
  110. System.out.println("In Stock File Exception error: " + ex);
  111. }
  112. }
  113.  
  114. private static void goRentedOut() {
  115. try{
  116. Scanner in = new Scanner (new FileReader("rentedOutFile.txt"));
  117. try {
  118. String line = in.nextLine();
  119. while (in.hasNextLine()) {
  120. String[] fields = line.split("[\\t]");
  121. if (fields.length == 3) {
  122. addToRentedOutMap(new Games(fields[0]), new LocalStores(fields[1]), new AtomicInteger(Integer.parseInt(fields[2])));
  123. }
  124. line = in.nextLine();
  125. }
  126. }
  127. finally {
  128. in.close();
  129. }
  130. }
  131.  
  132. catch (Exception ex){
  133. System.out.println("Rented Out File Exception error: " + ex);
  134. }
  135. }
  136.  
  137. private static void goOverDue() {
  138. try{
  139. Scanner in = new Scanner (new FileReader("overDueFile.txt"));
  140. try {
  141. String line = in.nextLine();
  142. while (in.hasNextLine()) {
  143. String[] fields = line.split("[\\t]");
  144. if (fields.length == 3) {
  145. addToOverDueMap(new Games(fields[0]), new LocalStores(fields[1]), new AtomicInteger(Integer.parseInt(fields[2])));
  146. }
  147. line = in.nextLine();
  148. }
  149. }
  150. finally {
  151. in.close();
  152. }
  153. }
  154.  
  155. catch (Exception ex){
  156. System.out.println("Over Due File Exception error: " + ex);
  157. }
  158. }
  159.  
  160. static void addToInStockMap (Games games, LocalStores store, AtomicInteger value){
  161. stockMap.put(games, value);
  162. inStock.put(store, stockMap);
  163. }
  164.  
  165. static void addToRentedOutMap (Games games, LocalStores store, AtomicInteger value){
  166. stockMap.put(games, value);
  167. inStock.put(store, rentedMap);
  168. }
  169.  
  170. static void addToOverDueMap (Games games, LocalStores store, AtomicInteger value){
  171. stockMap.put(games, value);
  172. inStock.put(store, dueMap);
  173. }
  174.  
  175. static void checkStock(){
  176. // new AtominInteger k = inStock.get(stockMap).get(AtomicInteger);
  177. // int ko = inStock.get(stockMap).get(AtomicInteger);
  178. // String ke = inStock.get(stockMap).get(LocalStores);
  179. }
  180. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement