Answer to Question #280505 in Java | JSP | JSF for Debby

Question #280505

You have been tasked to create a class called Abaaneke, your class should contain four private variables (customerName , deposit, oldBalance, newBalace) using the appropriate data types.



Your class should also have a method that takes three arguments – name of account holder, amount deposited and old balance. The method should add the deposit to the oldBalance and call it new balance.



Using the right setters and getters, initialize the private variables and call the method to display the following



a. Account holders name



b. Amount deposited



c. Old balance



d. And new balance



The user should be able to repeat the running of the program as many as he/she wishes


(Kindly write a full Java program)

1
Expert's answer
2021-12-16T14:31:14-0500


import java.util.Scanner;


class Abaaneke {
	private String customerName;
	private double deposit, oldBalance, newBalace;


	public Abaaneke() {
	}


	public double getDeposit() {
		return deposit;
	}


	public void setDeposit(double deposit) {
		this.deposit = deposit;
	}


	public double getOldBalance() {
		return oldBalance;
	}


	public void setOldBalance(double oldBalance) {
		this.oldBalance = oldBalance;
	}


	public double getNewBalace() {
		return newBalace;
	}


	public void setNewBalace(double newBalace) {
		this.newBalace = newBalace;
	}


	public String getName() {
		return customerName;
	}


	public void setName(String name) {
		this.customerName = name;
	}


	public void updateAccount(String nameAccountHolder, double amountDeposited, double oldBalance) {
		setName(nameAccountHolder);
		setDeposit(amountDeposited);
		setOldBalance(oldBalance);
		newBalace = amountDeposited + oldBalance;
	}


	public void display() {
		System.out.println("Account holders name: " + customerName);
		System.out.println("Amount deposited: " + deposit);
		System.out.println("Old balance: " + oldBalance);
		System.out.println("A new balance: " + newBalace);
	}


}


public class App {


	/**
	 * The start point of the program
	 * 
	 * @param args
	 * 
	 */
	public static void main(String[] args) {
		Scanner keyBoard = new Scanner(System.in);
		String answer = "y";
		while (answer.compareToIgnoreCase("y") == 0) {
			System.out.print("Enter name: ");
			String customerName = keyBoard.next();
			System.out.print("Enter deposit: ");
			double deposit = keyBoard.nextDouble();
			System.out.print("Enter old Balance: ");
			double oldBalance = keyBoard.nextDouble();


			Abaaneke abaaneke = new Abaaneke();
			abaaneke.updateAccount(customerName, deposit, oldBalance);
			abaaneke.display();
			keyBoard.nextLine();
			System.out.print("Do you want to continue: (y/n): ");
			answer = keyBoard.nextLine();


		}
		keyBoard.close();
	}


}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog