Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In Java complete the following 3 steps by using the credit card class program be

ID: 3641685 • Letter: I

Question

In Java complete the following 3 steps by using the credit card class program below:

CreditCard PROGRAM:

public class CreditCard
{
private String cardType;
private long cardNumber;
private float limit;//Max amount you can spend.
private float currentBalance;//The amount you have spent. It should be called amountUsed ???

//Constructors
CreditCard(){}
CreditCard(String cardType, long cardNumber, float limit, float currentBalance)
{
this.cardType = cardType;
this.cardNumber = cardNumber;
this.limit = limit;
this.currentBalance = currentBalance;
}

//Setters
public void setCardType(String cardType){ this.cardType = cardType;}
public void setCardNumber(long cardNumber){this.cardNumber = cardNumber;}
public void setLimit(float limit){this.limit = limit;}
public void setCurrentBalance(float currentBalance){this.currentBalance = currentBalance;}

//Getters
public String setCardType(){ return this.cardType;}
public long setCardNumber(){return this.cardNumber;}
public float setLimit(){return this.limit;}
public float setCurrentBalance(){return this.currentBalance;}

//Other methods
public boolean createCharge(float price)
{
if(price <= limit - currentBalance)
{
makePayment(price);
System.out.println("Transaction Successful !");
return true;//
}else
{
System.out.println("Transaction Faailure: Insufficient funds !");
return false;
}

}

public boolean makePayment(float amount)
{
if(amount <= limit-currentBalance && amount > 0)
{
currentBalance = currentBalance + amount;
return true;//That is, transaction succeeded and a payment was made.
}else{return false;}

}

}


Step 1

1. Write a program that uses your credit card class. Demonstrate all methods.
2. Create two objects of data type credit card.
3. Ask the user for type of card, card number, and limit for each card.
4. Set the beginning balance to 0 for each card.

Step 2

1. Create a menu to add a charge or make a payment to card 1.
2. Update the balance for card 1, calling the appropriate method.
3. Display the original balance, the charge or payment, and the new balance to the screen. Keep in mind these are dollar and cents amounts, so use the correct formatting.
4. Repeat for card 2.

Step 3

1. Repeat the program until the user chooses to quit.

Explanation / Answer

import java.util.Scanner; public class CreditCard { private String cardType; private long cardNumber; private float limit;//Max amount you can spend. private float currentBalance;//The amount you have spent. It should be called amountUsed ??? //Constructors CreditCard(){} CreditCard(String cardType, long cardNumber, float limit, float currentBalance) { this.cardType = cardType; this.cardNumber = cardNumber; this.limit = limit; this.currentBalance = currentBalance; } //Setters public void setCardType(String cardType){ this.cardType = cardType;} public void setCardNumber(long cardNumber){this.cardNumber = cardNumber;} public void setLimit(float limit){this.limit = limit;} public void setCurrentBalance(float currentBalance){this.currentBalance = currentBalance;} //Getters public String getCardType(){ return this.cardType;} public long getCardNumber(){return this.cardNumber;} public float getLimit(){return this.limit;} public float getCurrentBalance(){return this.currentBalance;} //Other methods public boolean createCharge(float price) { if(price 0) { currentBalance = currentBalance + price; System.out.println("Transaction Successful !"); return true; }else { System.out.println("Transaction Failure: Insufficient funds !"); return false; } } public boolean makePayment(float price) { if(price>0) { currentBalance = currentBalance - price; System.out.println("Transaction Successful !"); return true; }else { System.out.println("Transaction Failure: Insufficient funds !"); return false; } } public String display(float price) { StringBuffer st1=new StringBuffer(); int d=(int)price; int c=(int)(currentBalance-d)*100; st1.append('$'); st1.append(d); st1.append(" cents"); st1.append(c); return st1.toString(); } } class TestCreditCard { public static void main(String args[]) { CreditCard c1,c2; Scanner sc=new Scanner("System.in"); System.out.println("enter type of card, card number, and limit for c1 card"); String s1=sc.nextLine(); long no1=sc.nextLong(); float limit1=sc.nextFloat(); String s2=sc.nextLine(); long no2=sc.nextLong(); float limit2=sc.nextFloat(); c1=new CreditCard(s1,no1,limit1,0); c2=new CreditCard(s2,no2,limit2,0); char ch='n'; do { float price; for(int i=1;i
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote