Bank Account Static (Java) Your task is to complete these six methods: getAccountNumber should allow the account number
Posted: Mon May 02, 2022 12:01 pm
Bank Account Static (Java)
Your task is to complete these six methods:
getAccountNumber should allow the account number to be
retrieved. It should not accept any parameters, and should return
the value of the account number.
setAccountNumber should allow the account number to be updated.
It should accept the new account number as a parameter, and should
not return anything.
getAccountName should allow the account name to be retrieved. It
should not accept any parameters, and should return the value of
the account name.
setAccountName should allow the account name to be updated. It
should accept the new account name as a parameter, and should not
return anything.
getBalance should allow the account balance to be retrieved. It
should not accept any parameters, and should return the balance of
the account.
deposit should allow the account balance to be updated. It
should accept a currency amount, and add this to the current
balance. It should not return anything.
Provided Code Skeleton:
public class BankAccountStatic
{
/*
* The variables follow. These are also
* called "fields" or "?"private data members".
*/
private static int accountNumber = 0;
private static String accountName = "no name";
private static double balance; // eg. 1.27 means
$1.27
public static void main(String[] args) {
System.out.println("The initial value for
account number is " + accountNumber + ". Look at line 24.");
System.out.println("The initial value for
account name is " + accountName + ". Look at line 26.");
System.out.println("The initial value for
balance is " + balance + ". Look at line 28.");
BankAccountStatic.setAccountNumber(12345678);
BankAccountStatic.setAccountName("Samantha");
//the above two lines should update the values
stored in accountNumber and accountName to the given value. Let's
test it:
System.out.println("The new account number is
12345678. Your program's new account number is " + accountNumber
+". If these two numbers don't match then something is not
right...");
System.out.println("The new account name is
Samantha. Your program's new account name is " + accountName+". If
these two names don't match then something is not right...");
//lets put some money in the account
BankAccountStatic.deposit(3.70);
//the new balance should be 3.70. Let's
check it:
System.out.println("New balance should be
3.70. Your program's new balance is " + balance+". If these two
numbers don't match then something is not right...");
//let's put some more money in our bank
account:
BankAccountStatic.deposit(100.00);
//the new balance should be 103.70. Let's
check it:
System.out.println("New balance should be
103.70. Your program's new balance is " + balance+". If these two
numbers don't match then something is not right...");
//let's withdraw some money now. the new
balance should be 93.20. Let's check it:
System.out.println("After this line, the new
balance should be 93.20. Your program's balance after calling
withdraw(10.50) is " + BankAccountStatic.withdraw(10.50) + ". If
these two numbers don't match then something is not
right...");
//let's attempt to withdraw
more than what we have in the account. The result of print
statement should be zero:
System.out.println("Attempting to withdraw
1000.00 dollars from this bank accoutn should return a -1.0. Your
program's return value after calling withdraw(1000.00) is " +
BankAccountStatic.withdraw(1000.00) + ". If these two numbers don't
match then something is not right...");
}
/**
* This method needs to be completed. It needs:
* - a proper return type
* - a proper list of parameters (maybe empty)
* - code to actually do what it should
*/
public static int getAccountNumber()
{
return accountNumber;
}
/**
* This method needs to be completed. It needs:
* - a proper return type
* - a proper list of parameters (maybe empty)
* - code to actually do what it should
*/
public static void setAccountNumber(int Acc)
{
accountNumber = Acc;
}
/**
* This method needs to be completed. It needs:
* - a proper return type
* - a proper list of parameters (maybe empty)
* - code to actually do what it should
*/
public static String getAccountName()
{
return accountName;
}
/**
* This method needs to be completed. It needs:
* - a proper return type
* - a proper list of parameters (maybe empty)
* - code to actually do what it should
*/
public static void setAccountName(String name)
{
accountName = name;
}
/**
* This method needs to be completed. It needs:
* - a proper return type
* - a proper list of parameters (maybe empty)
* - code to actually do what it should
*/
public static double getBalance()
}
double balance = 0;
for (Transaction t:
this.transactions) {
balance +=
t.getAmount();
}
return balance;
}
/**
* This method needs to be completed. It needs:
* - a proper return type
* - a proper list of parameters (maybe empty)
* - code to actually do what it should
*/
public static void deposit(double deposit)
{
balance = balance + deposit;
System.out.println("\ndepositing " + deposit +
" To bank .....")
}
/**
* @param amount To be subtracted from
the balance
*
* @return the updated account balance or -1.0
if the withdrawal is refused
*
* The withdrawal is refused when the withdrawal
would
* have resulted in a negative balance.
*
* Note: This method "withdraw" has been provided
in
* its entirety. You do NOT have
to make any
* changes to it.
*/
public static double withdraw(double amount)
{
if ( balance >= amount )
{
balance = balance -
amount;
return balance;
}
else
return -1.0;
}
} // class BankAccountStatic
Your task is to complete these six methods:
getAccountNumber should allow the account number to be
retrieved. It should not accept any parameters, and should return
the value of the account number.
setAccountNumber should allow the account number to be updated.
It should accept the new account number as a parameter, and should
not return anything.
getAccountName should allow the account name to be retrieved. It
should not accept any parameters, and should return the value of
the account name.
setAccountName should allow the account name to be updated. It
should accept the new account name as a parameter, and should not
return anything.
getBalance should allow the account balance to be retrieved. It
should not accept any parameters, and should return the balance of
the account.
deposit should allow the account balance to be updated. It
should accept a currency amount, and add this to the current
balance. It should not return anything.
Provided Code Skeleton:
public class BankAccountStatic
{
/*
* The variables follow. These are also
* called "fields" or "?"private data members".
*/
private static int accountNumber = 0;
private static String accountName = "no name";
private static double balance; // eg. 1.27 means
$1.27
public static void main(String[] args) {
System.out.println("The initial value for
account number is " + accountNumber + ". Look at line 24.");
System.out.println("The initial value for
account name is " + accountName + ". Look at line 26.");
System.out.println("The initial value for
balance is " + balance + ". Look at line 28.");
BankAccountStatic.setAccountNumber(12345678);
BankAccountStatic.setAccountName("Samantha");
//the above two lines should update the values
stored in accountNumber and accountName to the given value. Let's
test it:
System.out.println("The new account number is
12345678. Your program's new account number is " + accountNumber
+". If these two numbers don't match then something is not
right...");
System.out.println("The new account name is
Samantha. Your program's new account name is " + accountName+". If
these two names don't match then something is not right...");
//lets put some money in the account
BankAccountStatic.deposit(3.70);
//the new balance should be 3.70. Let's
check it:
System.out.println("New balance should be
3.70. Your program's new balance is " + balance+". If these two
numbers don't match then something is not right...");
//let's put some more money in our bank
account:
BankAccountStatic.deposit(100.00);
//the new balance should be 103.70. Let's
check it:
System.out.println("New balance should be
103.70. Your program's new balance is " + balance+". If these two
numbers don't match then something is not right...");
//let's withdraw some money now. the new
balance should be 93.20. Let's check it:
System.out.println("After this line, the new
balance should be 93.20. Your program's balance after calling
withdraw(10.50) is " + BankAccountStatic.withdraw(10.50) + ". If
these two numbers don't match then something is not
right...");
//let's attempt to withdraw
more than what we have in the account. The result of print
statement should be zero:
System.out.println("Attempting to withdraw
1000.00 dollars from this bank accoutn should return a -1.0. Your
program's return value after calling withdraw(1000.00) is " +
BankAccountStatic.withdraw(1000.00) + ". If these two numbers don't
match then something is not right...");
}
/**
* This method needs to be completed. It needs:
* - a proper return type
* - a proper list of parameters (maybe empty)
* - code to actually do what it should
*/
public static int getAccountNumber()
{
return accountNumber;
}
/**
* This method needs to be completed. It needs:
* - a proper return type
* - a proper list of parameters (maybe empty)
* - code to actually do what it should
*/
public static void setAccountNumber(int Acc)
{
accountNumber = Acc;
}
/**
* This method needs to be completed. It needs:
* - a proper return type
* - a proper list of parameters (maybe empty)
* - code to actually do what it should
*/
public static String getAccountName()
{
return accountName;
}
/**
* This method needs to be completed. It needs:
* - a proper return type
* - a proper list of parameters (maybe empty)
* - code to actually do what it should
*/
public static void setAccountName(String name)
{
accountName = name;
}
/**
* This method needs to be completed. It needs:
* - a proper return type
* - a proper list of parameters (maybe empty)
* - code to actually do what it should
*/
public static double getBalance()
}
double balance = 0;
for (Transaction t:
this.transactions) {
balance +=
t.getAmount();
}
return balance;
}
/**
* This method needs to be completed. It needs:
* - a proper return type
* - a proper list of parameters (maybe empty)
* - code to actually do what it should
*/
public static void deposit(double deposit)
{
balance = balance + deposit;
System.out.println("\ndepositing " + deposit +
" To bank .....")
}
/**
* @param amount To be subtracted from
the balance
*
* @return the updated account balance or -1.0
if the withdrawal is refused
*
* The withdrawal is refused when the withdrawal
would
* have resulted in a negative balance.
*
* Note: This method "withdraw" has been provided
in
* its entirety. You do NOT have
to make any
* changes to it.
*/
public static double withdraw(double amount)
{
if ( balance >= amount )
{
balance = balance -
amount;
return balance;
}
else
return -1.0;
}
} // class BankAccountStatic