Advertisement
Guest User

Untitled

a guest
Apr 7th, 2019
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.80 KB | None | 0 0
  1. import java.util.Scanner;
  2. import java.text.SimpleDateFormat;
  3. import java.util.Date;
  4. import java.util.Random;
  5. import java.io.FileNotFoundException;
  6. import java.io.PrintWriter;
  7. import java.text.DecimalFormat;
  8. import java.nio.file.Files;
  9.  
  10.  
  11.  
  12. public class CreditCard {
  13.  
  14. public static void main(String[] args) throws FileNotFoundException {
  15. Scanner scan = new Scanner(System.in);
  16. Random rand = new Random();
  17. SimpleDateFormat dateFormat = new
  18. SimpleDateFormat("MM/dd/yyyy");
  19. Date dateObj = new Date();
  20. String date = dateFormat.format(dateObj);
  21.  
  22. int task = 90;
  23. int value2 = rand.nextInt(10000) + 1000;
  24. int value3 = rand.nextInt(10000) + 1000;
  25. int value4 = rand.nextInt(10000) + 1000;
  26. int value5 = rand.nextInt(10000) + 1000;
  27.  
  28.  
  29. String name = null, cardNumber, phoneNumber, ssNumber, address;
  30. String username = null;
  31. String password = null;
  32. double creditLine, availableCredit, balance, minPay, intrate;
  33.  
  34. //setting the constants for this lab
  35. cardNumber = "" + value2 + value3 + value4 + value5;
  36. availableCredit = 2000;
  37. creditLine = 2000;
  38. intrate = .1699;
  39. balance = 0;
  40. minPay = 0;
  41.  
  42. //use while loop to retrieve the outputs and reenter switch statement
  43. while (task!=0)
  44. {
  45.  
  46.  
  47. System.out.println("CREDIT CARD SERVICE MENU");
  48. System.out.println("1. Open new credit card");
  49. System.out.println("2. One transaction");
  50. System.out.println("3. Print statement");
  51. System.out.println("4. Payment");
  52. System.out.println("5. Get Available credit amount");
  53. System.out.println("6. Get Interest Rate");
  54.  
  55. task = scan.nextInt();
  56. scan.nextLine();
  57.  
  58. //switch statement to handle cases
  59. switch (task)
  60. {
  61. //open new credit card
  62. case 1:
  63. System.out.println("Enter your name.");
  64. name = scan.nextLine();
  65. System.out.println("Enter your SS number.");
  66. ssNumber = scan.nextLine();
  67. System.out.println("Enter your phone number.");
  68. phoneNumber = scan.nextLine();
  69. System.out.println("Enter your address.");
  70. address = scan.nextLine();
  71. System.out.println("Enter your username.");
  72. username = scan.nextLine();
  73. System.out.println("Enter your password.");
  74. password = scan.nextLine();
  75.  
  76.  
  77. DecimalFormat ft = new DecimalFormat("####");
  78.  
  79. System.out.println("Credit Card is available for you.");
  80. System.out.println("Name: \t \t " + name);
  81. System.out.println("Card number: \t " + cardNumber);
  82. System.out.println("Credit Line: \t " + creditLine);
  83. System.out.println("Available Credit: " + availableCredit);
  84. System.out.println("Current Balance: " + balance);
  85. System.out.println("Interest Rate: \t " + intrate);
  86. System.out.println("Minimum payment amount Due: " + minPay);
  87. break;
  88.  
  89. // one transaction
  90. case 2:
  91. System.out.println("Enter username.");
  92. String usernameUser = scan.nextLine();
  93. System.out.println("Enter password.");
  94. String passwordUser = scan.nextLine();
  95.  
  96. //verify user/password
  97. if (username.contentEquals(usernameUser) && password.contentEquals(passwordUser))
  98. {
  99. //getting transaction
  100. System.out.println("Description of Transaction?");
  101. String transaction = scan.nextLine();
  102. System.out.println("Type?");
  103. String type = scan.nextLine();
  104. System.out.println("Enter amount.");
  105. double amount = scan.nextDouble();
  106. if (amount > availableCredit)
  107. {
  108. System.out.println("Transaction is denied.");
  109. break;
  110. }
  111. else
  112. {
  113. balance = balance + amount;
  114. availableCredit = availableCredit - amount;
  115. PrintWriter fileName = new
  116. PrintWriter("statement_2438371220124047.txt");
  117.  
  118. fileName.println("date " + dateObj + " " + type + " $" + amount);
  119. fileName.close();
  120. }
  121. }
  122. else
  123. System.out.println("The username or password does not match.");
  124. break;
  125.  
  126. case 3:
  127. PrintWriter fileName2 = new
  128. PrintWriter("statement_512941322288144_1002017.txt");
  129.  
  130. fileName2.println("Name: \t \t " + name);
  131. fileName2.println("Card number: \t " + cardNumber);
  132. fileName2.println("Credit Line: \t " + creditLine);
  133. fileName2.println("Available Credit: " + availableCredit);
  134. fileName2.println("Current Balance: " + balance);
  135. fileName2.println("Interest Rate: \t " + intrate);
  136. fileName2.println("Minimum payment amount Due: " + minPay);
  137. fileName2.println("Payment Due date:" + dateObj);
  138.  
  139.  
  140. break;
  141. case 4:
  142. break;
  143. case 5:
  144. System.out.println("Current availalbe credit amount:" + availableCredit);
  145. break;
  146. case 6:
  147. System.out.println("Current interest rate: " + intrate);
  148. break;
  149.  
  150.  
  151. }
  152.  
  153.  
  154.  
  155.  
  156.  
  157. }
  158. }
  159. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement