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

In this program you will use classes to process credit card payments and charges

ID: 3566770 • Letter: I

Question

In this program you will use classes to process credit card payments and charges. The program will consist of at least two files: the class file and the driver file. More class files may be used if desired.

First, the program checks the name-password of the customer. Access is allowed if there is a match with credentials predefined in the driver. Multiple attempts are allowed. The program quits if access is denied.

Eclipse does not allow use of the console in such a way that the password is not echoed. Therefore this program is developed using command line and a text editor.

Upon customer validation the program accepts commands from the customer. Commands specify the type of transaction (payment, charge, balance check, etc.) and the amount of the transaction, where appropriate. Customer commands also include a help and quit command. Help should display the possible commands and their syntax.

Credit card information consists of: name, number, current balance, available credit limit, and customer rating (good or bad).

Processing includes payments, charges, and balance checks which show account information.

Sample interaction (no enhancements):

Welcome to the Credit Card Program

Enter your request: help

Commands for credit card program:

      charge - charge the , no $ please

      payment - payment of , no $ please

      balance - print current account information

      help - this list of commands!

      q - quit program

Enter your request: balance

Account Information for Susan #1256 8002 0034 8765

Balance:                $    0.00

Limit:                  $ 5000.00

Credit Line Available: $ 5000.00

Rating:           good

Enter your request: charge 5001

*** this charge puts balance over the limit but is allowed ***

Enter your request: charge 20

*** Charge Denied ***

Enter your request: balance

Account Information for Susan #1256 8002 0034 8765

Balance:                $ 5001.00

Limit:                  $ 5000.00

Credit Line Available: $    1.00-

Rating:           bad

Enter your request: payment 6000

Thank you for your payment of $6000.00

Balance: $999.00CR

Enter your request: balance

Account Information for Susan #1256 8002 0034 8765

Balance:                $ 999.00CR

Limit:                  $ 5000.00

Credit Line Available: $ 5999.00

Rating:           good

Enter your request: charge 2000

Charge Approved

Enter your request: balance

Account Information for Susan #1256 8002 0034 8765

Balance:                $ 1001.00

Limit:                  $ 5000.00

Credit Line Available: $ 3999.00

Rating:           good

Enter your request: payment 1000

Thank you for your payment of $1000.00

Balance: $ 1.00

Enter your request: charge 2000

Charge Approved

Enter your request: payment 1500.00

Thank you for your payment of $1500.00

Balance: $501.00

Enter your request: balance

Account Information for Susan #1256 8002 0034 8765

Balance:                $ 501.00

Limit:                  $ 5000.00

Credit Line Available: $ 4499.00

Rating:           good

Enter your request: q

Goodbye!

You should have a class file and a driver file

Explanation / Answer

Program Code:

//class UserLoginInfo

public class UserLoginInfo

{

     String name;

     String password;

     double balance;

     double limit;

     double climitAvailable;

     String rating;

     String accountnum;

     public UserLoginInfo()

     {

          name=null;

          password=null;

     }

     public UserLoginInfo(String uname, String uPassword)

     {

          name=uname;

          password=uPassword;

          balance=0.0;

          limit=5000;

          climitAvailable=5000;

          rating="good";

          setAccountNum();

     }

   

     public void setUname(String uname)

     {

          name=uname;

     }

     public void setUPassword(String uPassword)

     {

          password=uPassword;

     }

     public void setBalance(double bal)

     {

          balance=bal;

     }

     public void setCreditLimit(double credit)

     {

          climitAvailable=credit;

     }

     public double getBalance()

     {

          return balance;

     }

     public double getLimit()

     {

          return limit;

     }

     public double getCreditLimit()

     {

          return climitAvailable;

     }

     public String getUname()

     {

          return name;

     }

     public String getUPassword()

     {

          return password;

     }

     public void setAccountNum()

     {

          accountnum="";

          for(int i=0;i<4;i++)

          {

              for(int j=0;j<4;j++)

              {

                   accountnum+=""+(int)(Math.random()*10);

              }

              accountnum+=" ";

          }

        

     }

     public String getAccountNum()

     {

          return accountnum;

     }

   

     public String getRating()

     {       

          if(climitAvailable <0)

              rating="bad";

          else

              rating="good";

          return rating;

     }

   

}

//VerifyLogin

public class VerifyLogin

{

     String name;

     String password;

     double balance;

     double creditLimit;

     //ArrayList<UserLoginInfo> login=new ArrayList<UserLoginInfo>();

     static UserLoginInfo login;

     public VerifyLogin()

     {  

          login=new UserLoginInfo("Susan", "abcd1234");

     }  

     public static boolean verify(String uname, String password)

     {

          boolean bool=false;

          if(login.getUname().equals(uname)&&

                   login.getUPassword().equals(password))

          {

              bool=true;

          }

          else

              bool=false;

          return bool;

     }  

     public void Credits()

     {

          System.out.print("Account information of "+login.getUname());

          System.out.println(" #"+login.getAccountNum());

          System.out.println("Balance: "+login.getBalance());

          System.out.println("Limit: "+login.getLimit());

          System.out.println("Credit Line Available: $"+login.getCreditLimit());

          System.out.println("Rating: "+login.getRating());       

     }

     public void processCharge(double amount)

     {

          if(login.getCreditLimit() < 0 )

          {

              System.out.println("Then charge is denied");

          }

          else

          {

              if(login.getBalance()<=0){

                   balance=amount+login.getBalance();

              login.setBalance(balance);

              creditLimit=login.getCreditLimit()-amount;

              login.setCreditLimit(creditLimit);

              System.out.println("Charge Approved.");

              }

              else

              {

                   balance=amount-login.getBalance();

                   login.setBalance(balance);

                   creditLimit=login.getCreditLimit()-amount;

                   login.setCreditLimit(creditLimit);

                   System.out.println("Charge Approved.");

              }

          }

     }

     public void processBalance(double amount)

     {  

          balance=amount-login.getBalance();

          login.setBalance(balance);

          creditLimit=login.getCreditLimit()+amount;

          login.setCreditLimit(creditLimit);

          System.out.println("Thank you for your payment of $"+amount);

          System.out.println("Balance: $"+login.getBalance());

     }  

}

//implementation class

import java.util.*;

public class CreditImplementation

{

     public static void main(String args[])

     {

          Scanner input=new Scanner(System.in);

          String name;

          String password;

          int count=5;

          boolean verify;

          double amount;

          String type;

          VerifyLogin vlogin=new VerifyLogin();

          do{

              System.out.println("Enter User name: ");

              name=input.next();

              System.out.println("Enter Password: ");

              password=input.next();

              verify=VerifyLogin.verify(name, password);

              if(!verify)

              {

                   count--;

              }

              else

              {

                   break;

              }

          }while(count>0 );

          if(count==0)

          {

              System.exit(0);

          }

          else

          {

              System.out.println("Welcome to the Credit Card Program ");

              do

              {                

                   System.out.println("Enter your request: ");

                   type=input.next();

                 

                   if(type.equals("charge"))

                   {

                        amount=input.nextDouble();

                        vlogin.processCharge(amount);

                   }

                   else if(type.equals("payment"))

                   {

                        amount=input.nextDouble();

                        vlogin.processBalance(amount);

                   }

                   else if(type.equals("balance"))

                   {

                        vlogin.Credits();

                   }

                   else if(type.equals("help"))

                   {

                        System.out.println("Commands for credit card program:");

                        System.out.println("charge - charge the , no $ please ");

                        System.out.println("payment - payment of , no $ please");

                        System.out.println("balance - print current account information");

                        System.out.println("help - this list of commands!");

                        System.out.println("q - quit program");

                   }

                   else if(type.equals("q"))

                   {

                        System.exit(0);

                   }

              }while(true);

            

          }

        

     }

}

Sample Output:

Enter User name:

Susan

Enter Password:

abcd1234

Welcome to the Credit Card Program

Enter your request:

help

Commands for credit card program:

charge - charge the , no $ please

payment - payment of , no $ please

balance - print current account information

help - this list of commands!

q - quit program

Enter your request:

balance

Account information of Susan #9425 7783 1199 4808

Balance: 0.0

Limit: 5000.0

Credit Line Available: $5000.0

Rating: good

Enter your request:

charge 5001

Charge Approved.

Enter your request:

payment 6000

Thank you for your payment of $6000.0

Balance: $999.0

Enter your request:

balance

Account information of Susan #9425 7783 1199 4808

Balance: 999.0

Limit: 5000.0

Credit Line Available: $5999.0

Rating: good

Enter your request:

q

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