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

Please modify the code below, thanks in advance! import java.util.ArrayList; imp

ID: 3571283 • Letter: P

Question

Please modify the code below, thanks in advance!

import java.util.ArrayList;

import java.util.List;

import java.util.Scanner;

public class ExpAcct{

  public static void main(String args[]){

     

      List<ExpressAccount> ealist = new ArrayList<ExpressAccount>();

     

      while(true){

          System.out.println("Welcome to the Express Account Company");

          System.out.println("MAIN MENU");

          System.out.println("1) Create a new account");

          System.out.println("2) Log into an existing account");

          System.out.println("3) Exit the system");

          System.out.println("Please enter your selection: ");

          Scanner s = new Scanner(System.in);

          int choice = s.nextInt();

          if(choice == 1){

              //create a account

              //instantiates a object of the class ExpressAccount

              ExpressAccount ea = new ExpressAccount(ealist.size()+1,0,0);

              while(true){                  

                  System.out.println("EXPRESS ACCOUNT #"+ea.getAccountNumber()+", Balance: $"+ea.getAccountBalance()+", Number of Meals: "+ea.getNumberOfMeals());

                  System.out.println("1) Make a deposit");

                  System.out.println("2) Purchase Meals");

                  System.out.println("3) Have Meal");

                  System.out.println("4) Log out");

                  System.out.println("Please enter your selection: ");

                  Scanner s1 = new Scanner(System.in);

                  int choice1 = s.nextInt();

                  if(choice1 == 1){

                      double depositVal = 0.0;

                      System.out.println("Enter deposit amount: ");

                      depositVal = s1.nextDouble();

                      //negative deposit value checking

                      if(depositVal < 0.0)

                          System.out.println("The deposit must be a positive amount.");

                      else{

                          //check the value of the deposit less than the minimbaseamount

                          if(depositVal < ea.getBaseAmtForBonus())

                          {

                              ea.setAccountBalance(ea.getAccountBalance()+depositVal);

                          }

                          // deposit value greater than the base amount for bonus

                          else{

                              ea.setAccountBalance(ea.getAccountBalance()+depositVal+ea.getRewardAmt());

                          }

                          System.out.println("Deposit $"+depositVal+" New Balance $"+ea.getAccountBalance());

                      }

                  }else if(choice1 == 2){

                      int numMeals = 0;

                      System.out.println("Enter the number of meals you want to purchase: ");

                      numMeals = s1.nextInt();

                      //negative meals value checking

                      if(numMeals < 0)

                          System.out.println("The number of meals to purchase must be a positive value.");

                      else{

                          //check if there is sufficient balance in account

                          if(ea.getAccountBalance()>=numMeals*ea.getPricePerMeal()){

                              ea.setAccountBalance(ea.getAccountBalance()-numMeals*ea.getPricePerMeal());

                              ea.setNumberOfMeals(ea.getNumberOfMeals()+numMeals);

                              System.out.println("Purchased "+numMeals+" meals, New Balance $"+ea.getAccountBalance());

                          }

                          else{

                              //calculate the number of meals that can be purchased with the available balance

                              int final_num_meals = 0;

                              for(int k = 1; k <=numMeals; k++){

                                  if(ea.getAccountBalance()>=k*ea.getPricePerMeal())

                                      final_num_meals = k;

                              }

                              ea.setAccountBalance(ea.getAccountBalance()-final_num_meals*ea.getPricePerMeal());

                              ea.setNumberOfMeals(ea.getNumberOfMeals()+final_num_meals);

                              System.out.println("Not enough balance for "+numMeals+" meals");

                              System.out.println("Purchased "+final_num_meals+" meals, New Balance $"+ea.getAccountBalance());

                          }

                      }

                     

                  }else if(choice1 == 3){

                      if(ea.getNumberOfMeals()<=0)

                          System.out.println("No meals left on your account. Please purchase first");

                      else{

                          ea.setNumberOfMeals(ea.getNumberOfMeals()-1);

                      }

                  }

                  else{

                      System.out.println("GoodBye! ");

                      break;

                  }

              }

              //add the newly created express account into the list

              ealist.add(ea);

             

          }else if(choice == 2){

              System.out.println("Enter Account Number:");

              int ac = s.nextInt();

              ExpressAccount ea = null;

              //Based on the account number given, retrieve the student express account details from the list

              for(int i = 0; i < ealist.size(); i++){

                  ea = ealist.get(i);

                  if(ea.getAccountNumber()==ac)

                      break;

              }

              System.out.println("Welcome back Student Express Account #"+ac+", balance: $"+ea.getAccountBalance()+", number of meals: "+ea.getNumberOfMeals());

         

              while(true){

                 

                  System.out.println("EXPRESS ACCOUNT #"+ea.getAccountNumber()+", Balance: $"+ea.getAccountBalance()+", Number of Meals: "+ea.getNumberOfMeals());

                  System.out.println("1) Make a deposit");

                  System.out.println("2) Purchase Meals");

                  System.out.println("3) Have Meal");

                  System.out.println("4) Log out");

                  System.out.println("Please enter your selection: ");

                  Scanner s1 = new Scanner(System.in);

                  int choice1 = s.nextInt();

                  if(choice1 == 1){

                      double depositVal = 0.0;

                      System.out.println("Enter deposit amount: ");

                      depositVal = s1.nextDouble();

                      //negative deposit value checking

                      if(depositVal < 0.0)

                          System.out.println("The deposit must be a positive amount.");

                      else{

                          //check the value of the deposit less than the minimbaseamount

                          if(depositVal < ea.getBaseAmtForBonus())

                          {

                              ea.setAccountBalance(ea.getAccountBalance()+depositVal);

                          }

                          // deposit value greater than the base amount for bonus

                          else{

                              ea.setAccountBalance(ea.getAccountBalance()+depositVal+ea.getRewardAmt());

                          }

                          System.out.println("Deposit $"+depositVal+" New Balance $"+ea.getAccountBalance());

                      }

                  }else if(choice1 == 2){

                      int numMeals = 0;

                      System.out.println("Enter the number of meals you want to purchase: ");

                      numMeals = s1.nextInt();

                      //negative meals value checking

                      if(numMeals < 0)

                          System.out.println("The number of meals to purchase must be a positive value.");

                      else{

                          //check if there is sufficient balance in account

                          if(ea.getAccountBalance()>numMeals*ea.getPricePerMeal()){

                              ea.setAccountBalance(ea.getAccountBalance()-numMeals*ea.getPricePerMeal());

                              ea.setNumberOfMeals(ea.getNumberOfMeals()+numMeals);

                              System.out.println("Purchased "+numMeals+" meals, New Balance $"+ea.getAccountBalance());

                          }

                          else{

                              //calculate the number of meals that can be purchased with the available balance

                              int final_num_meals = 0;

                              for(int k = 1; k <=numMeals; k++){

                                  if(ea.getAccountBalance()>=k*ea.getPricePerMeal())

                                      final_num_meals = k;

                              }

                              ea.setAccountBalance(ea.getAccountBalance()-final_num_meals*ea.getPricePerMeal());

                              ea.setNumberOfMeals(ea.getNumberOfMeals()+final_num_meals);

                              System.out.println("Not enough balance for "+numMeals+" meals");

                              System.out.println("Purchased "+final_num_meals+" meals, New Balance $"+ea.getAccountBalance());

                          }

                      }

                     

                  }else if(choice1 == 3){

                      if(ea.getNumberOfMeals()<=0)

                          System.out.println("No meals left on your account. Please purchase first");

                      else{

                          ea.setNumberOfMeals(ea.getNumberOfMeals()-1);

                      }

                  }

                  else{

                      System.out.println("GoodBye! ");

                      break;

                  }

              }

          }else{

              System.out.println("Please enter a valid input ");

          }

         

      }

     

     

  }

}

public class ExpressAccount {

  private int accountNumber; // creates account number variable

  private double accountBalance; // creates account balance variable

  private int numberOfMeals; // creates number of meals variable

  private double pricePerMeal=10; // creates price of meals

  private double baseAmtForBonus=200; // creates bonus amount

  private int rewardLevel = 200; // creates reward level

  private int rewardAmt = 2; // creates reward amount

  public ExpressAccount(int accountNum,int accountBal,int numMeals){

      accountNumber = accountNum;

      accountBalance = accountBal;

      numberOfMeals = numMeals;

        

  }

  public int getAccountNumber() {

      return accountNumber;

  }

  public void setAccountNumber(int accountNumber) {

      this.accountNumber = accountNumber;

  }

  public double getAccountBalance() {

      return accountBalance;

  }

  public void setAccountBalance(double accountBalance) {

      this.accountBalance = accountBalance;

  }

  public int getNumberOfMeals() {

      return numberOfMeals;

  }

  public void setNumberOfMeals(int numberOfMeals) {

      this.numberOfMeals = numberOfMeals;

  }

  public double getPricePerMeal() {

      return pricePerMeal;

  }

  public void setPricePerMeal(double pricePerMeal) {

      this.pricePerMeal = pricePerMeal;

  }

  public double getBaseAmtForBonus() {

      return baseAmtForBonus;

  }

  public void setBaseAmtForBonus(int baseAmtForBonus) {

      this.baseAmtForBonus = baseAmtForBonus;

  }

  public int getRewardLevel() {

      return rewardLevel;

  }

  public void setRewardLevel(int rewardLevel) {

      this.rewardLevel = rewardLevel;

  }

  public int getRewardAmt() {

      return rewardAmt;

  }

  public void setRewardAmt(int rewardAmt) {

      this.rewardAmt = rewardAmt;

  }

}

This project extends the previous one and is designed for you to practice inheritance and abstract Same as the last project, you will write a program that allows a user to repeatedly create and manage express card accounts. However, we will add a type for each express card account. There are two types of express card accounts a student express account or a faculty express account. All express account have fields accountNumber account Balance numberof Meals, pricePerMeal base Amt For Bonus. and account TypeName Some changes for an express account are listed belo The criteria of receiving bonus for these two types of express accounts are different The baseAmtForBonus is set to $500.0 for a student express account. base AmtForBonus is set to $0.0 for a faculty express account i the corresponding The constructor are two variables only for a student express account for bonus reward Level and rewardAmt receiving bonus. Same as in the previous project, for every deposit that is greater than the baseAmt For Bonus for each rewardLevel, a student account receives rewardAmt amount of money. For example, if rewardLevel is set to 200.0 and rewardAmt is set to 2.0, then a deposit of $500 to a $0 balance student express account will result $4.0 bonus and a new balance of $504.0. However, a deposit of $499 to a $100 balance student express account will not obtain any bonus and final balance is $599.0. The variable rewardLevel should be set to $200.0 and rewardAmt to $2.0. While we won't change the value of them in this project, they must be variables A faculty express account has only one extra variable for bonus: rewardPct, the percentage of deposit that will become the bonus. In this project, it is set to 0.01. For example, since the baseAmtForBonus is $0.0 for a faculty, a $50 deposit to a $0 balance faculty express account will result $0.5 bonus and a new balance of $50.5 The pricePerMeal is $8.00 for a faculty account and $10.0 for a student With the above changes, when creating a new account, your program should ask the use to choose which type of the new account s/h wants to create. If the user chooses a student express account, then e all the headers displayed in the sub-menu should be of the form "STUDENT EXPRESS ACCOUNT #0 BALANCE: $0.0, NUMBER OF MEALS: 0". Otherwise, the headers displayed in the sub-menu should be of the form "FACULTY EXPRESS ACCOUNT #0, BALANCE: $0.0, NUMBER OF MEALS: 0 Implementation Hints Start from the ExpressAccount class that you have written from the previous project, remove rewardLevel and rewardAmt fields and corresponding methods from this class Implement classes for the student and faculty express accounts that extend the ExpressAccount and implement the appropriate behavior for each type of account. These subclasses should reuse as much as possible from the base ExpressAccount class. If functionality is shared between

Explanation / Answer

1. ExpAcct.java

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class ExpAcct {
   public static void main(String args[]) {

       List<ExpressAccount> ealist = new ArrayList<ExpressAccount>();

       while (true) {

           System.out.println("Welcome to the Express Account Company");

           System.out.println("MAIN MENU");
           System.out.println("1) Create a new account");
           System.out.println("2) Log into an existing account");
           System.out.println("3) Exit the system");
           System.out.println("Please enter your selection: ");
           Scanner s = new Scanner(System.in);
           int choice = s.nextInt();
           if (choice == 1) {
               // create a account
               // instantiates a object of the class ExpressAccount
               System.out
                       .println("Which kind of account you want to create: ");
               System.out.println("1) Student Express Account");
               System.out.println("2) Faculty Express Account");
               s = new Scanner(System.in);
               int c = s.nextInt();
               ExpressAccount ea = null;
               if (c == 1) {
                   ea = new StudentExpressAccount(ealist.size() + 1, 0, 0);
                   System.out.println("STUDENT EXPRESS ACCOUNT #"
                           + ea.getAccountNumber() + ", Balance: $"
                           + ea.getAccountBalance() + ", Number of Meals: "
                           + ea.getNumberOfMeals());
               } else {
                   ea = new FacultyExpressAccount(ealist.size() + 1, 0, 0);
                   System.out.println("FACULTY EXPRESS ACCOUNT #"
                           + ea.getAccountNumber() + ", Balance: $"
                           + ea.getAccountBalance() + ", Number of Meals: "
                           + ea.getNumberOfMeals());
               }

               while (true) {

                   System.out.println("1) Make a deposit");
                   System.out.println("2) Purchase Meals");
                   System.out.println("3) Have Meal");
                   System.out.println("4) Log out");
                   System.out.println("Please enter your selection: ");
                   Scanner s1 = new Scanner(System.in);
                   int choice1 = s.nextInt();
                   if (choice1 == 1) {
                       double depositVal = 0.0;
                       System.out.println("Enter deposit amount: ");
                       depositVal = s1.nextDouble();
                       // negative deposit value checking
                       if (depositVal < 0.0)
                           System.out
                                   .println("The deposit must be a positive amount.");
                       else {
                           // check the value of the deposit less than the
                           // minimbaseamount
                           if (depositVal < ea.getBaseAmtForBonus()) {
                               ea.setAccountBalance(ea.getAccountBalance()
                                       + depositVal);
                           }
                           // deposit value greater than the base amount for
                           // bonus
                           else {
                               if (ea instanceof StudentExpressAccount) {
                                   ea.setAccountBalance(ea.getAccountBalance()
                                           + depositVal
                                           + ((int )(depositVal / ((StudentExpressAccount) ea)
                                                   .getRewardLevel()))
                                           * (((StudentExpressAccount) ea)
                                                   .getRewardAmt()));
                               } else {
                                   ea.setAccountBalance(ea.getAccountBalance()
                                           + depositVal
                                           + +depositVal
                                           * (((FacultyExpressAccount) ea)
                                                   .getRewardPct()) / 100);

                               }
                           }
                           System.out
                                   .println("Deposit $" + depositVal
                                           + " New Balance $"
                                           + ea.getAccountBalance());
                       }
                   } else if (choice1 == 2) {
                       int numMeals = 0;
                       System.out
                               .println("Enter the number of meals you want to purchase: ");
                       numMeals = s1.nextInt();
                       // negative meals value checking
                       if (numMeals < 0)
                           System.out
                                   .println("The number of meals to purchase must be a positive value.");
                       else {
                           // check if there is sufficient balance in account
                           if (ea.getAccountBalance() >= numMeals
                                   * ea.getPricePerMeal()) {
                               ea.setAccountBalance(ea.getAccountBalance()
                                       - numMeals * ea.getPricePerMeal());
                               ea.setNumberOfMeals(ea.getNumberOfMeals()
                                       + numMeals);
                               System.out.println("Purchased " + numMeals
                                       + " meals, New Balance $"
                                       + ea.getAccountBalance());
                           } else {
                               // calculate the number of meals that can be
                               // purchased with the available balance
                               int final_num_meals = 0;
                               for (int k = 1; k <= numMeals; k++) {
                                   if (ea.getAccountBalance() >= k
                                           * ea.getPricePerMeal())
                                       final_num_meals = k;
                               }
                               ea.setAccountBalance(ea.getAccountBalance()
                                       - final_num_meals
                                       * ea.getPricePerMeal());
                               ea.setNumberOfMeals(ea.getNumberOfMeals()
                                       + final_num_meals);
                               System.out.println("Not enough balance for "
                                       + numMeals + " meals");
                               System.out.println("Purchased "
                                       + final_num_meals
                                       + " meals, New Balance $"
                                       + ea.getAccountBalance());
                           }
                       }

                   } else if (choice1 == 3) {
                       if (ea.getNumberOfMeals() <= 0)
                           System.out
                                   .println("No meals left on your account. Please purchase first");
                       else {
                           ea.setNumberOfMeals(ea.getNumberOfMeals() - 1);
                       }
                   } else {
                       System.out.println("GoodBye! ");
                       break;
                   }
               }
               // add the newly created express account into the list
               ealist.add(ea);

           } else if (choice == 2) {
               System.out.println("Enter Account Number:");
               int ac = s.nextInt();
               ExpressAccount ea = null;
               // Based on the account number given, retrieve the student
               // express account details from the list
               for (int i = 0; i < ealist.size(); i++) {
                   ea = ealist.get(i);
                   if (ea.getAccountNumber() == ac)
                       break;
               }
               System.out.println("Welcome back Student Express Account #"
                       + ac + ", balance: $" + ea.getAccountBalance()
                       + ", number of meals: " + ea.getNumberOfMeals());

               while (true) {

                   System.out.println("EXPRESS ACCOUNT #"
                           + ea.getAccountNumber() + ", Balance: $"
                           + ea.getAccountBalance() + ", Number of Meals: "
                           + ea.getNumberOfMeals());
                   System.out.println("1) Make a deposit");
                   System.out.println("2) Purchase Meals");
                   System.out.println("3) Have Meal");
                   System.out.println("4) Log out");
                   System.out.println("Please enter your selection: ");
                   Scanner s1 = new Scanner(System.in);
                   int choice1 = s.nextInt();
                   if (choice1 == 1) {
                       double depositVal = 0.0;
                       System.out.println("Enter deposit amount: ");
                       depositVal = s1.nextDouble();
                       // negative deposit value checking
                       if (depositVal < 0.0)
                           System.out
                                   .println("The deposit must be a positive amount.");
                       else {
                           // check the value of the deposit less than the
                           // minimbaseamount
                           if (depositVal < ea.getBaseAmtForBonus()) {
                               ea.setAccountBalance(ea.getAccountBalance()
                                       + depositVal);
                           }
                           // deposit value greater than the base amount for
                           // bonus
                           else {
                               if (ea instanceof StudentExpressAccount) {
                                   ea.setAccountBalance(ea.getAccountBalance()
                                           + depositVal
                                           + ((int )(depositVal / ((StudentExpressAccount) ea)
                                                   .getRewardLevel()))
                                           * (((StudentExpressAccount) ea)
                                                   .getRewardAmt()));
                               } else {
                                   ea.setAccountBalance(ea.getAccountBalance()
                                           + depositVal
                                           + +depositVal
                                           * (((FacultyExpressAccount) ea)
                                                   .getRewardPct()) / 100);

                               }
                           }
                           System.out
                                   .println("Deposit $" + depositVal
                                           + " New Balance $"
                                           + ea.getAccountBalance());
                       }
                   } else if (choice1 == 2) {
                       int numMeals = 0;
                       System.out
                               .println("Enter the number of meals you want to purchase: ");
                       numMeals = s1.nextInt();
                       // negative meals value checking
                       if (numMeals < 0)
                           System.out
                                   .println("The number of meals to purchase must be a positive value.");
                       else {
                           // check if there is sufficient balance in account
                           if (ea.getAccountBalance() > numMeals
                                   * ea.getPricePerMeal()) {
                               ea.setAccountBalance(ea.getAccountBalance()
                                       - numMeals * ea.getPricePerMeal());
                               ea.setNumberOfMeals(ea.getNumberOfMeals()
                                       + numMeals);
                               System.out.println("Purchased " + numMeals
                                       + " meals, New Balance $"
                                       + ea.getAccountBalance());
                           } else {
                               // calculate the number of meals that can be
                               // purchased with the available balance
                               int final_num_meals = 0;
                               for (int k = 1; k <= numMeals; k++) {
                                   if (ea.getAccountBalance() >= k
                                           * ea.getPricePerMeal())
                                       final_num_meals = k;
                               }
                               ea.setAccountBalance(ea.getAccountBalance()
                                       - final_num_meals
                                       * ea.getPricePerMeal());
                               ea.setNumberOfMeals(ea.getNumberOfMeals()
                                       + final_num_meals);
                               System.out.println("Not enough balance for "
                                       + numMeals + " meals");
                               System.out.println("Purchased "
                                       + final_num_meals
                                       + " meals, New Balance $"
                                       + ea.getAccountBalance());
                           }
                       }

                   } else if (choice1 == 3) {
                       if (ea.getNumberOfMeals() <= 0)
                           System.out
                                   .println("No meals left on your account. Please purchase first");
                       else {
                           ea.setNumberOfMeals(ea.getNumberOfMeals() - 1);
                       }
                   } else {
                       System.out.println("GoodBye! ");
                       break;
                   }
               }
           } else {
               System.out.println("Please enter a valid input ");
           }

       }

   }
}

---------------------------------------------------

2. ExpressAccount.java

public abstract class ExpressAccount {
   private int accountNumber; // creates account number variable
   private double accountBalance; // creates account balance variable
   private int numberOfMeals; // creates number of meals variable
   private double pricePerMeal = 10; // creates price of meals
   private double baseAmtForBonus = 200; // creates bonus amount
   private String accountTypeName;

   public ExpressAccount(int accountNum, int accountBal, int numMeals,
           double baseAmtForBonus, double pricePerMeal, String accountTypeName) {
       this.accountNumber = accountNum;
       this.accountBalance = accountBal;
       this.numberOfMeals = numMeals;
       this.baseAmtForBonus = baseAmtForBonus;
       this.pricePerMeal = pricePerMeal;
       this.accountTypeName = accountTypeName;
   }

   public ExpressAccount(int accountNum) {
       accountNumber = accountNum;

   }

   public int getAccountNumber() {
       return accountNumber;
   }

   public void setAccountNumber(int accountNumber) {
       this.accountNumber = accountNumber;
   }

   public double getAccountBalance() {
       return accountBalance;
   }

   public void setAccountBalance(double accountBalance) {
       this.accountBalance = accountBalance;
   }

   public int getNumberOfMeals() {
       return numberOfMeals;
   }

   public void setNumberOfMeals(int numberOfMeals) {
       this.numberOfMeals = numberOfMeals;
   }

   public double getPricePerMeal() {
       return pricePerMeal;
   }

   public void setPricePerMeal(double pricePerMeal) {
       this.pricePerMeal = pricePerMeal;
   }

   public double getBaseAmtForBonus() {
       return baseAmtForBonus;
   }

   public void setBaseAmtForBonus(int baseAmtForBonus) {
       this.baseAmtForBonus = baseAmtForBonus;
   }

   public String getAccountTypeName() {
       return accountTypeName;
   }

   public void setAccountTypeName(String accountTypeName) {
       this.accountTypeName = accountTypeName;
   }
}

-----------------------------------------------------

3. StudentExpressAccount.java

public class StudentExpressAccount extends ExpressAccount {
   private int rewardLevel = 200; // creates reward level
   private int rewardAmt = 2; // creates reward amount

  
   public StudentExpressAccount(int accountNum, int accountBal, int numMeals) {
       super(accountNum, accountBal, numMeals, 500.0, 10.0,"Student");
   }


   public int getRewardLevel() {
       return rewardLevel;
   }


   public void setRewardLevel(int rewardLevel) {
       this.rewardLevel = rewardLevel;
   }


   public int getRewardAmt() {
       return rewardAmt;
   }


   public void setRewardAmt(int rewardAmt) {
       this.rewardAmt = rewardAmt;
   }
  
}

-----------------------------------------------------------

4. FacultyExpressAccount.java

public class FacultyExpressAccount extends ExpressAccount {

   public FacultyExpressAccount(int accountNum, int accountBal, int numMeals) {
       super(accountNum, accountBal, numMeals, 0.0, 8.0, "Faculty");
   }

   public double getRewardPct() {
       return rewardPct;
   }

   public void setRewardPct(double rewardPct) {
       this.rewardPct = rewardPct;
   }

   private double rewardPct = 0.01;

}

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