Advertisement
Guest User

Untitled

a guest
Apr 28th, 2017
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.60 KB | None | 0 0
  1. import java.io.FileNotFoundException;
  2. import java.io.FileReader;
  3. import java.io.FileWriter;
  4. import java.io.IOException;
  5. import java.util.List;
  6. import java.util.Scanner;
  7. import java.util.regex.Pattern;
  8.  
  9. import com.opencsv.CSVReader;
  10. import com.opencsv.CSVWriter;
  11.  
  12. public class Buyer{
  13.  
  14. private Scanner input;
  15. private CSVReader reader;
  16. private String currentUsername = "";
  17. private Scanner updater;
  18. private Scanner passGetter;
  19. private Scanner emailGetter;
  20. private CSVReader reader3;
  21.  
  22. public Buyer(){
  23. try {
  24. login();
  25. } catch (IOException e) {
  26. // TODO Auto-generated catch block
  27. e.printStackTrace();
  28. }
  29. }
  30.  
  31. public Buyer(String username){
  32. try {
  33. login();
  34. currentUsername = username;
  35. } catch (IOException e) {
  36. // TODO Auto-generated catch block
  37. e.printStackTrace();
  38. }
  39. }
  40.  
  41. private void register(){
  42.  
  43. }
  44.  
  45. private void login() throws IOException{
  46.  
  47. System.out.println("\nLogged in as Buyer\n\n");
  48.  
  49. String help = "Enter a command below (without the quotes) to continue.\n\n";
  50.  
  51.  
  52. help += "\"view\" to view items for sale\n";
  53. help += "\"cart\" to view your cart\n";
  54. help += "\"search\" to search for items\n";
  55. help += "\"buy\" to buy items in cart\n";
  56. help += "\"history\" to view purchase history\n";
  57. help += "\"update\" to update credentials\n";
  58. help += "\"logout\" to logout\n\n";
  59. help += "\"help\" anytime to see this message again\n";
  60.  
  61. System.out.println(help);
  62.  
  63. Scanner buyInput = new Scanner(System.in);
  64. String input = buyInput.next().toLowerCase();
  65.  
  66. if(input.equals("view")){
  67. viewMarketPlaceItems();
  68.  
  69. }else if(input.equals("cart")){
  70. //viewCart();
  71.  
  72. }else if(input.equals("search")){
  73. search();
  74.  
  75. }else if(input.equals("buy")){
  76. buy();
  77. login();
  78.  
  79. }else if(input.equals("history")){
  80. //history();
  81.  
  82. }else if(input.equals("update")){
  83. updateCreds();
  84.  
  85. }else if(input.equals("logout")){
  86.  
  87. }else if (input.equals("help")){
  88. login();
  89.  
  90. }else{
  91. System.out.println("Sorry, I cannot recognize your command, please try again\n");
  92. login();
  93. }
  94. }
  95.  
  96.  
  97. private void buy() throws IOException {
  98. System.out.println("What do you want to buy?");
  99. Scanner buying = new Scanner(System.in);
  100. String itemToBuy = buying.next();
  101. int quantity = 0;
  102. String sellerOfItem = "";
  103. int amountToBuy = 0;
  104.  
  105. reader = new CSVReader(new FileReader("bin/items.csv"), ',');
  106. List<String[]> csvBody = reader.readAll();
  107. for (String[] items : csvBody) {
  108. if (itemToBuy.equals(items[1])) {
  109. quantity = Integer.parseInt(items[4]);
  110. sellerOfItem = items[0];
  111. if (quantity > 0) {
  112. while (true) {
  113. System.out.println("How many would you like to buy?");
  114. amountToBuy = buying.nextInt();
  115. if (amountToBuy <= quantity) {
  116. items[4] = String.valueOf(quantity - amountToBuy);
  117. System.out.println("You bought " + amountToBuy + " " + itemToBuy);
  118. break;
  119. }
  120. }
  121. }
  122. }
  123. }
  124. CSVWriter writer = new CSVWriter(new FileWriter("bin/items.csv"), ',', CSVWriter.NO_QUOTE_CHARACTER);
  125. writer.writeAll(csvBody);
  126. writer.flush();
  127. quantity = quantity - amountToBuy;
  128. notifySeller(sellerOfItem, itemToBuy, quantity, amountToBuy);
  129. }
  130.  
  131.  
  132. private String viewMarketPlaceItems(){
  133. return null;
  134.  
  135. }
  136. public void updateCreds() {
  137. String userResponse;
  138.  
  139. String username;
  140.  
  141. boolean pass = false;
  142. boolean email = true;
  143. CSVReader reader = null;
  144.  
  145. try {
  146. reader = new CSVReader(new FileReader("bin/creds.csv"), ',');
  147. List<String[]> csvBody = reader.readAll();
  148. updater = new Scanner(System.in);
  149.  
  150. while (true) {
  151. System.out.println("What would you like to update, Password or Email?");
  152. userResponse = updater.next();
  153. userResponse = toTitleCase(userResponse);
  154. if (userResponse.equals("Password")) {
  155. pass = true;
  156. break;
  157. } else if (userResponse.equals("Email")) {
  158. email = true;
  159. break;
  160. } else {
  161. System.out.println("Invalid Response");
  162. }
  163. }
  164. System.out.println("Current Username: " + currentUsername);
  165. for (String[] creds : csvBody) {
  166. if (currentUsername.equals(creds[1])) {
  167. if (pass) {
  168. System.out.println("Changing Password here");
  169. creds[2] = newPassword();
  170. } else if (email) {
  171. System.out.println("Changing Email here");
  172. creds[3] = newEmail();
  173. }
  174. }
  175. }
  176.  
  177.  
  178.  
  179. CSVWriter writer = new CSVWriter(new FileWriter("bin/creds.csv"), ',', CSVWriter.NO_QUOTE_CHARACTER);
  180. writer.writeAll(csvBody);
  181. writer.flush();
  182.  
  183.  
  184. } catch (FileNotFoundException e) {
  185. e.printStackTrace();
  186. } catch (IOException e) {
  187. e.printStackTrace();
  188. }
  189.  
  190.  
  191. }
  192. private static String toTitleCase(String input) {
  193. StringBuilder titleCase = new StringBuilder();
  194. boolean nextTitleCase = true;
  195.  
  196. for (char c : input.toCharArray()) {
  197. if (Character.isSpaceChar(c)) {
  198. nextTitleCase = true;
  199. } else if (nextTitleCase) {
  200. c = Character.toTitleCase(c);
  201. nextTitleCase = false;
  202. }
  203.  
  204. titleCase.append(c);
  205. }
  206.  
  207. return titleCase.toString();
  208. }
  209. private String newPassword(){
  210. String newPassword;
  211. String confimationPassword;
  212.  
  213. passGetter = new Scanner(System.in);
  214.  
  215. while(true){
  216. System.out.print("\nPlease enter a password: ");
  217. newPassword = passGetter.next();
  218.  
  219. System.out.print("Please enter your password again: ");
  220. confimationPassword = passGetter.next();
  221.  
  222. if (newPassword.equals(confimationPassword)) break;
  223. else System.out.print("Passwords did not match, try again!\n");
  224. }
  225.  
  226. return newPassword;
  227. }
  228. private String newEmail(){
  229. String newEmail;
  230. String confimationEmail;
  231.  
  232. emailGetter = new Scanner(System.in);
  233.  
  234. //RFC822 compliant regex for email
  235. Pattern ptr = Pattern.compile("(?:(?:\\r\\n)?[ \\t])*(?:(?:(?:[^()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\\[\\]]))|\\[([^\\[\\]\\r\\\\]|\\\\.)*\\](?:(?:\\r\\n)?[ \\t])*)(?:\\.(?:(?:\\r\\n)?[ \\t])*(?:[^()<>@,;:\\\\\".\\[\\] \\000-\\031]+(?:(?:(?:\\r\\n)?[ \\t])+|\\Z|(?=[\\[\"()<>@,;:\\\\\".\\[\\]]))|\\[([^\\[\\]\\r\\\\]|\\\\.)*\\](?:(?:\\r\\n)?[ \\t])*))*)*:(?:(?:\\r\\n)?[ \\t])*)?(?:[^()<>@,;:\\\\\".\\[\\] \\000-\\031]+(?:(?:(?:\\r\\n)?[ \\t])+|\\Z|(?=[\\[\"()<>@,;:\\\\\".\\[\\]]))|\"(?:[^\\\"\\r\\\\]|\\\\.|(?:(?:\\r\\n)?[ \\t]))*\"(?:(?:\\r\\n)?[ \\t])*)(?:\\.(?:(?:\\r\\n)?[ \\t])*(?:[^()<>@,;:\\\\\".\\[\\] \\000-\\031]+(?:(?:(?:\\r\\n)?[ \\t])+|\\Z|(?=[\\[\"()<>@,;:\\\\\".\\[\\]]))|\"(?:[^\\\"\\r\\\\]|\\\\.|(?:(?:\\r\\n)?[ \\t]))*\"(?:(?:\\r\\n)?[ \\t])*))*@(?:(?:\\r\\n)?[ \\t])*(?:[^()<>@,;:\\\\\".\\[\\] \\000-\\031]+(?:(?:(?:\\r\\n)?[ \\t])+|\\Z|(?=[\\[\"()<>@,;:\\\\\".\\[\\]]))|\\[([^\\[\\]\\r\\\\]|\\\\.)*\\](?:(?:\\r\\n)?[ \\t])*)(?:\\.(?:(?:\\r\\n)?[ \\t])*(?:[^()<>@,;:\\\\\".\\[\\] \\000-\\031]+(?:(?:(?:\\r\\n)?[ \\t])+|\\Z|(?=[\\[\"()<>@,;:\\\\\".\\[\\]]))|\\[([^\\[\\]\\r\\\\]|\\\\.)*\\](?:(?:\\r\\n)?[ \\t])*))*\\>(?:(?:\\r\\n)?[ \\t])*))*)?;\\s*)");
  236.  
  237. while(true){
  238. System.out.print("\nPlease enter an email: ");
  239. newEmail = emailGetter.next();
  240.  
  241. System.out.print("Please enter your email again: ");
  242. confimationEmail = emailGetter.next();
  243.  
  244. if (newEmail.equals(confimationEmail) && ptr.matcher(newEmail).matches()) break;
  245. else if (!(ptr.matcher(newEmail).matches())) System.out.print("Not a legal email!\n");
  246. else System.out.print("Emails did not match, try again!\n");
  247. }
  248.  
  249. return newEmail;
  250. }
  251.  
  252.  
  253.  
  254. private String search(){
  255. return null;
  256.  
  257. }
  258.  
  259. private void notifySeller(String seller, String item, int quantity, int amountToBuy) throws IOException{
  260. try {
  261. reader3 = new CSVReader(new FileReader("bin/creds.csv"), ',');
  262. List<String[]> csvBody = reader3.readAll();
  263. for (String[] cred : csvBody){
  264. if(cred[1].equals(seller)){
  265. cred[5] += (" " + amountToBuy + " " + item + "s has been sold! "+ quantity + " " + item + "s remain! ");
  266. }
  267. }
  268.  
  269. CSVWriter writer = new CSVWriter(new FileWriter("bin/creds.csv"), ',', CSVWriter.NO_QUOTE_CHARACTER);
  270. writer.writeAll(csvBody);
  271. writer.flush();
  272. } catch (FileNotFoundException e) {
  273. e.printStackTrace();
  274. } catch (IOException e) {
  275. e.printStackTrace();
  276. }
  277.  
  278.  
  279. }
  280.  
  281.  
  282.  
  283. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement