Answer to Question #267935 in Java | JSP | JSF for Qwame

Question #267935

Java practical 1

It has been realized that hackers have started hacking and changing the account detains of some banks, to stop this practice, you have been tasked to create a class called Abaaneke, your class should contain three private variables (deposit, oldBalance, newBalace) all of type float and a variable of type String (name of the account holder)

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


1
Expert's answer
2021-11-18T06:55:14-0500
import java.util.Scanner;
public class Main
{
	public static void main(String[] args) {
		Abaaneke a=new Abaaneke();
		a.getData();
		a.display();
		a.update("Ann",5000,4500);
		a.display();
	}
}


class Abaaneke{
    private float deposit, oldBalance, newBalace;
    private String name;


    public float getDeposit() {
        return deposit;
    }


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


    public float getOldBalance() {
        return oldBalance;
    }


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


    public float getNewBalace() {
        return newBalace;
    }


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


    public String getName() {
        return name;
    }


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


    public Abaaneke() {
    }
    
    public void getData(){
        Scanner in =new Scanner(System.in);
        System.out.println("Enter name: ");
        name=in.next();
        System.out.println("Enter deposit: ");
        deposit=in.nextFloat();
        System.out.println("Enter old Balance: ");
        oldBalance=in.nextFloat();
        System.out.println("Enter new Balace: ");
        newBalace=in.nextFloat();
    }
    public void update(String n, float dep,float oldb){
        newBalace=dep+oldb;
    }
    public void display(){
        System.out.println("Name: "+name);
        System.out.println("Deposit: "+deposit);
        System.out.println("old Balance: "+oldBalance);
        System.out.println("newBalace: "+newBalace);
    }
    
}

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
APPROVED BY CLIENTS