Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class CreditCard {
- public static void main(String[] args) {
- double[] list = {20.00, 40.00,45.34,9.00,3.00};
- String cardHolder = "Shai";
- String number = "93462396734634";
- int exp_month = 9;
- int exp_year = 2021;
- double limit = 50000;
- double balance = 20.00;
- while(limit>=balance) {
- double item = Math.random()*10000;
- if (balance + item > limit) {
- System.out.println("Card limit reached. Cannot purchase item");
- break;
- } else {
- balance += Math.random()*10000;;
- }
- }
- /*
- for (double itemCost : list) {
- if (balance + itemCost > limit) {
- System.out.println("Card limit reached. Cannot purchase item");
- } else {
- balance += itemCost;
- }
- }
- */
- if (balance > 0) {
- System.out.println("Credit card bill paid: $" +balance);
- balance = 0;
- }
- printInfo(cardHolder,number,exp_month,exp_year,limit,balance);
- }
- public static void printInfo(String cardHolder, String number, int exp_month, int exp_year, double limit, double balance) {
- System.out.println(cardHolder + "'s credit card number " + number + " expires on " + exp_month + "/" + exp_year + ".");
- System.out.println("The card limit is $" +limit+ " and the current balance is $" +balance);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement