Advertisement
Guest User

Untitled

a guest
May 22nd, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.63 KB | None | 0 0
  1. package s3656260_A2;
  2.  
  3. import java.util.*;
  4.  
  5. public class RealEstateSystem {
  6. private static Scanner y = new Scanner(System.in);
  7.  
  8. private static ArrayList<Sale> arrayL = new ArrayList<Sale>();
  9.  
  10. public static void main(String args[]) {
  11. mainMenu();
  12.  
  13. }
  14.  
  15. public static void mainMenu() {
  16. System.out.printf("%-25s %s\n", "Add New Sale", "A");
  17. System.out.printf("%-25s %s\n", "Submit Offer", "B");
  18. System.out.printf("%-25s %s\n", "Display Sales Summary", "C");
  19. System.out.printf("%-25s %s\n", "Add New Auction", "D");
  20. System.out.printf("%-25s %s\n", "Close Auction", "E");
  21. System.out.printf("%-25s %s\n", "Exit Program", "X");
  22.  
  23. String choose = y.next();
  24.  
  25. switch (choose.toLowerCase()) {
  26. case "a":
  27. addNewSale();
  28. break;
  29. case "b":
  30. submitOffer();
  31. break;
  32. case "c":
  33. displaySales();
  34. break;
  35. case "d":
  36. addNewAuction();
  37. }
  38. }
  39.  
  40. private static void addNewSale() {
  41. System.out.println("Enter Sale ID for new PropertySale:");
  42. String SaleIdInput = (y.next());
  43.  
  44. System.out.println("Enter Property Adddress for new PropertySale:");
  45. String propertyAddressInput = (y.next());
  46.  
  47. System.out.println("Enter Reserve Price for new PropertySale: ");
  48. int reservePriceInput = (y.nextInt());
  49.  
  50. for (int x = 0; x < arrayL.size(); x++) {
  51. if (SaleIdInput.equals(arrayL.get(x).getsaleID())) {
  52. System.out.println("This SaleId already exists");
  53. mainMenu();
  54. }
  55.  
  56. }
  57.  
  58. Sale saleObject = new Sale(SaleIdInput, propertyAddressInput, reservePriceInput);
  59.  
  60. arrayL.add(saleObject);
  61.  
  62. System.out.print("New Property Sale added successfully for property at " + propertyAddressInput + '\n');
  63. mainMenu();
  64.  
  65. }
  66.  
  67. private static void submitOffer() {
  68. System.out.printf("%-25s %s", "Enter sale ID:", "");
  69. String SaleIdInput = (y.next());
  70. for (int x = 0; x < arrayL.size(); x++) {
  71. if (!SaleIdInput.equals(arrayL.get(x).getsaleID())) {
  72. System.out.println("This SaleId does not exist" + '\n');
  73. mainMenu();
  74. }
  75. System.out.printf("%-25s %s\n", "Current offer:", "0");
  76. System.out.printf("%-25s %s", "Enter new offer:", "");
  77. int offer = (y.nextInt());
  78. arrayL.get(x).makeOffer(offer);
  79. if (offer <= arrayL.get(x).getcurrentOffer()) {
  80. System.out.println("Error - New offer must be higher than current offer! Offer rejected!");
  81. }
  82. if (offer > arrayL.get(x).getreservePrice()) {
  83. System.out.print("Offer accepted! (this offer is above reserve price)" + '\n');
  84. }
  85. if (offer <= arrayL.get(x).getreservePrice()) {
  86. System.out.print("Offer accepted! (this offer is below reserve price)" + '\n');
  87.  
  88. }
  89.  
  90. }
  91. mainMenu();
  92.  
  93. }
  94.  
  95. private static void displaySales() {
  96. for (int x = 0; x < arrayL.size(); x++) {
  97. System.out.println(arrayL.get(x).getSalesDetails());
  98.  
  99. }
  100. mainMenu();
  101.  
  102. }
  103.  
  104. private static void addNewAuction() {
  105. System.out.println("Enter Sale ID for new Auction Sale:");
  106. String auctionSaleIdInput = (y.next());
  107.  
  108. System.out.println("Enter Property Address for new Auction Sale:");
  109. String auctionPropertyInput = (y.next());
  110.  
  111. System.out.println("Enter Reserve Price for new Auction Sale: ");
  112. int auctionReservePriceInput = (y.nextInt());
  113.  
  114. for (int x = 0; x < arrayL.size(); x++) {
  115. if (auctionSaleIdInput.equals(arrayL.get(x).getsaleID())) {
  116. System.out.println("SaleId: " + auctionSaleIdInput + " already exist");
  117. mainMenu();
  118. }
  119.  
  120. }
  121.  
  122. Sale saleObject = new Sale(auctionSaleIdInput, auctionPropertyInput, auctionReservePriceInput);
  123.  
  124. arrayL.add(saleObject);
  125.  
  126. System.out.print("New Property Sale added successfully for property at " + auctionPropertyInput + '\n');
  127. mainMenu();
  128. }
  129. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement