Question

In: Computer Science

2.     Modify assignment 1 solution code I posted to do the following: a.     Change car class to bankAccount...

2.     Modify assignment 1 solution code I posted to do the following:

a.     Change car class to bankAccount class and TestCar class to TestBank class

b.     Change mileage to balance

c.     Change car info (make, model, color, year, fuel efficiency) to customer first and last name and account balance

d.     Change add gas to deposit (without limit)

e.     Change drive to withdraw cash

f.  Change test car menu to the following Bank Account Menu choices

1 - Deposit

2 - Withdraw

3 - Display account info

4 - Exit


public class Car {
   //Attributes
   private double fuelEfficiency, mileage, fuelCapacity, fuelLevel;
   private String make, model, color, year;
   /**
   * @return the make
   */
   public String getMake() {
       return make;
   }

   /**
   * @param make the make to set
   */
   public void setMake(String make) {
       this.make = make;
   }

   /**
   * @return the model
   */
   public String getModel() {
       return model;
   }

   /**
   * @param model the model to set
   */
   public void setModel(String model) {
       this.model = model;
   }

   /**
   * @return the color
   */
   public String getColor() {
       return color;
   }

   /**
   * @param color the color to set
   */
   public void setColor(String color) {
       this.color = color;
   }

   /**
   * @return the year
   */
   public String getYear() {
       return year;
   }

   /**
   * @param year the year to set
   */
   public void setYear(String year) {
       this.year = year;
   }

   /**
   * @return the fuelEfficiency
   */
   public double getFuelEfficiency() {
       return fuelEfficiency;
   }

   /**
   * @param fuelEfficiency the fuelEfficiency to set
   */
   public void setFuelEfficiency(double fuelEfficiency) {
       this.fuelEfficiency = fuelEfficiency;
   }

   /**
   * @return the mileage
   */
   public double getMileage() {
       return mileage;
   }

   /**
   * @param mileage the mileage to set
   */
   public void setMileage(double mileage) {
       this.mileage = mileage;
   }

   /**
   * @return the fuelCapacity
   */
   public double getFuelCapacity() {
       return fuelCapacity;
   }

   /**
   * @param fuelCapacity the fuelCapacity to set
   */
   public void setFuelCapacity(double fuelCapacity) {
       this.fuelCapacity = fuelCapacity;
   }

   /**
   * @return the fuelLevel
   */
   public double getFuelLevel() {
       return fuelLevel;
   }

   /**
   * @param fuelLevel the fuelLevel to set
   */
   public void setFuelLevel(double fuelLevel) {
       this.fuelLevel = fuelLevel;
   }

   public Car() {
       fuelLevel = 0;
       fuelCapacity = 0;
       mileage = 0;
       fuelEfficiency = 0;
   }
  
   public Car (double fuelEfficiency, double mileage, double fuelCapacity) {
       this.fuelEfficiency = fuelEfficiency;
       this.mileage = mileage;
       this.fuelCapacity = fuelCapacity;
   }
  
   public void drive(double distance) {
       double gallons = distance/fuelEfficiency;
       if(fuelLevel <gallons){
           System.out.println("Not enough gas!");
       }
       else {
           mileage = mileage + distance;
           fuelLevel = fuelLevel - gallons;
           System.out.println("You have driven " +distance+ " mile(s).");
           System.out.println();
           return;
       }
   }
  
   public void addGas(double fuel) {
       if (fuel + fuelLevel < fuelCapacity){
           fuelLevel = fuelLevel + fuel;
           System.out.println("You have added " +fuel+ " gallon(s) of fuel.");
           System.out.println();
           return;
       }
       else {
           System.out.println("Please enter an amount of fuel less than it's capacity.");
       }
   }
  
   public void displayCar(){
       System.out.println();
       System.out.println("Make: " + getMake());
       System.out.println("Model: " + getModel());
       System.out.println("Color: " + getColor());
       System.out.println("Year: " + getYear());
       System.out.println("You have driven " + getMileage() + " miles.");
       System.out.println("Your fuel level is: " + getFuelLevel() + " gallon(s)");
       System.out.println("Your fuel efficiency is " + getFuelEfficiency() + " mpg.");
       System.out.println("Your fuel tank capacity is " + getFuelCapacity() + " gallons.");  
       System.out.println();
       }
      
   }
  
  

Solutions

Expert Solution

bankAccount.java:
Raw_code:

public class bankAccount {
//Attributes
private double balance, accountbalance;
private String firstname, lastname;
/**
* @return the name
*/
public String getName() {
return firstname + " "+ lastname;
}

public void setFirst(String first){
this.firstname = first;
}

public void setLast(String last){
this.lastname = last;
}

/**
* @param name the name to set
*/
public void setName(String first, String last) {
this.firstname = first;
this.lastname = last;
}

/**
* @return the balance
*/
public double getBalance() {
return this.balance;
}

/**
* @param balance the balance to set
*/
public void setBalance(double balance) {
this.balance = balance;
}

public bankAccount() {
balance = 0;
firstname = "";
lastname = "";
}

public bankAccount (String first, String last, double balance) {
this.firstname = first;
this.lastname = last;
this.balance = balance;
}

public void deposit(double money) {
if (money > 0){
this.balance += money;
System.out.println("You have deposited " + money + " dollors.");
System.out.println();
return;
}
}

public void withdraw(double money) {
if (this.balance > 0 && this.balance > money){
this.balance -= money;
System.out.println("You have withdraw " +money+ " dollors.");
System.out.println();
return;
}
else {
System.out.println("Insufficient balance in Account.");
}
}

public void displayAccount(){
System.out.println();
System.out.println("Name: " + getName());
System.out.println("Balance: " + getBalance());;
System.out.println();
}
}

TestBank.java:
Raw_code:

import java.util.Scanner;
public class TestBank{

public static void menu(){
System.out.println();
System.out.println("Account Menu : ");
System.out.println("1 - Deposit");
System.out.println("2 - Withdraw");
System.out.println("3 - Display Account Info");
System.out.println("4 - Exit");
System.out.println();
}
public static void main(String [] args){
Scanner snr = new Scanner(System.in);
int choice = 1;
double money = 0;
bankAccount b1 = new bankAccount();
System.out.print("Enter the FirstName : ");
b1.setFirst(snr.nextLine());
System.out.print("Enter the LastName : ");
b1.setFirst(snr.nextLine());
while(choice > 0){
menu();
System.out.print("Enter your choice : ");
choice = snr.nextInt();

while (choice < 0 && choice > 5){
System.out.println("Invalid Choice!.");
System.out.print("Enter your choice : ");
choice = snr.nextInt();
}
if (choice == 1){
System.out.print("Enter ammount : ");
money = snr.nextDouble();
b1.deposit(money);
}
else if (choice == 2){
System.out.print("Enter ammount : ");
money = snr.nextDouble();
b1.withdraw(money);
}
else if (choice == 3)
b1.displayAccount();
else if (choice == 4){
System.out.println("Thank you. Hava a nice day");
System.exit(0);
}
}
}
}

output:


Related Solutions

Write code in SAS to do each of the following I have posted the data below...
Write code in SAS to do each of the following I have posted the data below from a pace delimited data set consisting of 66 randomly selected cars Upload the data set to SAS and store it as a SAS data set called cars. Make sure the full values are stored for all character variables. Create a comparative bar chart (with appropriate title and labels) displaying the brands of each car by fuel type (so that fuel type is on...
If there are 32 concurrent processes, how will you modify the following code? Process i do...
If there are 32 concurrent processes, how will you modify the following code? Process i do { while (turn == j);                critical section; turn = j;                remainder section } while (true);
I have the following assignment for probability class: I am supposed to write a routine (code)...
I have the following assignment for probability class: I am supposed to write a routine (code) in MATLAB that does solve the following problem for me: a) Generate N=10000 samples of a Uniform random variable (X) using the rand () command. This Uniform RV should have a range of -1 to +3. b) Generate (Estimate) and plot the PDF of X from the samples. You are not allowed to use the Histogram () command, any commands from the Matlab Statistics...
I have the following code for my java class assignment but i am having an issue...
I have the following code for my java class assignment but i am having an issue with this error i keep getting. On the following lines: return new Circle(color, radius); return new Rectangle(color, length, width); I am getting the following error for each line: "non-static variable this cannot be referenced from a static context" Here is the code I have: /* * ShapeDemo - simple inheritance hierarchy and dynamic binding. * * The Shape class must be compiled before the...
I have to modify the following code to: 1. Use the unique algorithm to reduce the...
I have to modify the following code to: 1. Use the unique algorithm to reduce the array to unique values 2. Use the copy algorithm to display the unique results. #include<iostream> #include<vector> #include<algorithm> using namespace std; int main() {     //creating an array of 20 integers     int array[20];     //creating an empty vector     vector<int> vec;     //input from end user to get 20 ints and a for loop to interate through 20     cout << "Enter 20 integers:"...
Problem Write in drjava is fine. Using the classes from Assignment #2, do the following: Modify...
Problem Write in drjava is fine. Using the classes from Assignment #2, do the following: Modify the parent class (Plant) by adding the following abstract methods: a method to return the botanical (Latin) name of the plant a method that describes how the plant is used by humans (as food, to build houses, etc) Add a Vegetable class with a flavor variable (sweet, salty, tart, etc) and 2 methods that return the following information: list 2 dishes (meals) that the...
Problem Write in drjava is fine. Using the classes from Assignment #2, do the following: Modify...
Problem Write in drjava is fine. Using the classes from Assignment #2, do the following: Modify the parent class (Plant) by adding the following abstract methods: a method to return the botanical (Latin) name of the plant a method that describes how the plant is used by humans (as food, to build houses, etc) Add a Vegetable class with a flavor variable (sweet, salty, tart, etc) and 2 methods that return the following information: list 2 dishes (meals) that the...
How do I add the information below to my current code that I have also posted...
How do I add the information below to my current code that I have also posted below. <!DOCTYPE html> <html> <!-- The author of this code is: Ikeem Mays --> <body> <header> <h1> My Grocery Site </h1> </header> <article> This is web content about a grocery store that might be in any town. The store stocks fresh produce, as well as essential grocery items. Below are category lists of products you can find in the grocery store. </article> <div class...
1. Copy the files from Assignment 1 to Assignment 3. 2. Modify the PetFoodCompany header to...
1. Copy the files from Assignment 1 to Assignment 3. 2. Modify the PetFoodCompany header to mention a friend function called "computeBonusBudget". This method should compute the bonus budget as netIncome() * BonusBudgetRate and this method should exist in the driver program - not the Class defintion. 3. Modify the output of the program to display the results of the computeBonusBudget. Enter Total Sales: 1000 Enter Total Expenses: 600 Net Income = 400 Bonus Budget = 8 Here is the...
How do I start to code in mysql to Alter table to modify column remove not...
How do I start to code in mysql to Alter table to modify column remove not null constraint First drop the foreign key associated with Drop the column Add the column back with new definition Add the foreign key back This Is what I wrote so far alter table employees modify column repotsTo remove null:
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT