Advertisement
Guest User

Untitled

a guest
Jan 20th, 2020
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. public class CreditCard {
  2.  
  3. public static void main(String[] args) {
  4. double[] list = {20.00, 40.00,45.34,9.00,3.00};
  5.  
  6. String cardHolder = "Shai";
  7. String number = "93462396734634";
  8. int exp_month = 9;
  9. int exp_year = 2021;
  10. double limit = 50000;
  11. double balance = 20.00;
  12.  
  13. while(limit>=balance) {
  14. double item = Math.random()*10000;
  15. if (balance + item > limit) {
  16. System.out.println("Card limit reached. Cannot purchase item");
  17. break;
  18. } else {
  19. balance += Math.random()*10000;;
  20. }
  21. }
  22. /*
  23. for (double itemCost : list) {
  24.  
  25. if (balance + itemCost > limit) {
  26. System.out.println("Card limit reached. Cannot purchase item");
  27. } else {
  28. balance += itemCost;
  29. }
  30. }
  31. */
  32.  
  33. if (balance > 0) {
  34. System.out.println("Credit card bill paid: $" +balance);
  35. balance = 0;
  36. }
  37. printInfo(cardHolder,number,exp_month,exp_year,limit,balance);
  38. }
  39.  
  40. public static void printInfo(String cardHolder, String number, int exp_month, int exp_year, double limit, double balance) {
  41. System.out.println(cardHolder + "'s credit card number " + number + " expires on " + exp_month + "/" + exp_year + ".");
  42. System.out.println("The card limit is $" +limit+ " and the current balance is $" +balance);
  43.  
  44. }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement