Question

In: Computer Science

I am struggling to even get started on this assignment. its a teach yourself kind of...

I am struggling to even get started on this assignment. its a teach yourself kind of situation and I have and no issues up to this point but I just can't wrap my head around it.

  1. Implement the Account class.
    1. Add a public enum called ACCOUNT_TYPE with two values CHECKING, SAVING
    2. Add the following private instance variables to the Account class:
      • An instance variable called aType of type Enum ACCOUNT_TYPE.
      • An instance variable called accountOwner of type String.
      • An instance variable called interestRate of type double.
      • An instance variable called balance of type double
    3. Add getters and setters for the four instance variables of item (b) to the Account class:
    4. Add the following methods to the Account class:
      • A void method called initialize that takes a parameter of type ACCOUNT_TYPE, a String, two doubles and uses those arguments to set the values of the accountType, accountOwner, interestRate, and balance instance variables.
      • A void method called display that displays the account information.
      • A void method called deposit with one parameter of double that adds the given parameter to the balance instance variable.
      • A void method called withdraw with one parameter of double that deduct the given parameter from the balance instance variable. This method prints an error message when the given parameter is greater than the balance. In this case no money should be withdrawn from the account.
  • In the main method of your main class, create two Account objects and perform the following:
    • Initialize the first account objects with SAVING as the accountType and other parameters of your own choice.
    • Initialize the first account objects with CHECKING as the accountType and other parameters of your own choice.
    • Display both accounts.
    • Deposit $200 from the first account
    • Withdraw $500 from the second account
  • Display both accounts.
  • Run the main program to see if the tests were successful.
    • Here is a sample output of the program.

Account Type: SAVING

Account Owner: Customer B

Interest Rate: 1.1

Balance: 500.0

Account Type: CHECKING

Account Owner: Customer A

Interest Rate: 1.2

Balance: 200.0

Cannot withdraw more than account balance


java is the language.

Solutions

Expert Solution

hey there ! i am done with the code .Please give me a like to appreciate my work and efforts...

here is the code -

package Bank;

/**
*
* @author Aditya kumar
*/
enum ACCOUNT_TYPE
{
CHECKING,SAVINGS;
}
public class Account {
//create five variable
private ACCOUNT_TYPE aType;
private String accountOwner;
private double interestRate;
private double Balance;

//setter and getter methods
public ACCOUNT_TYPE getaType() {
return aType;
}

public void setaType(ACCOUNT_TYPE aType) {
this.aType = aType;
}

public String getAccountOwner() {
return accountOwner;
}

public void setAccountOwner(String accountOwner) {
this.accountOwner = accountOwner;
}

public double getInterestRate() {
return interestRate;
}

public void setInterestRate(double interestRate) {
this.interestRate = interestRate;
}

public double getBalance() {
return Balance;
}

public void setBalance(double Balance) {
this.Balance = Balance;
}
//initialize method to initialize varibales
void initialize(ACCOUNT_TYPE atype,String name,double interestRate,double balance)
{
//set the value
setaType(atype);
setAccountOwner(name);
setInterestRate(interestRate);
setBalance(balance);
  
}
//display method
void display()
{
System.out.println(" Account Type : "+aType.name());
System.out.println("Account Owner : "+getAccountOwner());
System.out.println("Interest Rate : "+getInterestRate());
System.out.println("Balance : "+getBalance());
}
//deposit to the account
void deposit(double amount)
{

double bal=getBalance();
setBalance(bal+amount);
System.out.println("Successfull Deposit ! ");
}
//withdraw from account
void withdraw(double amount)
{
//if balance is 0 or amount is greater than balance
if(getBalance()<=0 || amount>getBalance())
{
System.out.println("You don't have enough money to withdraw");
}
else
{
double bal=getBalance();
setBalance(bal-amount);
System.out.println("Successfully withdraw ! ");
}

}

public static void main(String args[])
{
//two object
Account ac=new Account();
Account ac1=new Account();
  
//initialize with Savings
ac.initialize(ACCOUNT_TYPE.SAVINGS, "Customer B ", 1.1, 500);
//initialize with Checking
ac1.initialize(ACCOUNT_TYPE.CHECKING, "Customer A ", 1.2, 200);
//display
ac.display();
ac1.display();
//deposit into account
ac.deposit(20);
//withdraw from account
ac.withdraw(60);
//display
ac.display();
  
  
  
}
}

and the snapshot of the output is -

Thank You ! Dont forget to Like !


Related Solutions

I am struggling with this assignment. I can't get the program to run when I enter...
I am struggling with this assignment. I can't get the program to run when I enter a number with the $ symbol followed by a number below 10. any help would be greatly appreciated. Create a program named Auction that allows a user to enter an amount bid on an online auction item. Include three overloaded methods that accept an int, double, or string bid. Each method should display the bid and indicate whether it is over the minimum acceptable...
I am really struggling with this chemistry problem. I don`t even know how to start.. The...
I am really struggling with this chemistry problem. I don`t even know how to start.. The problem is about recrystallization: Two crystalline compounds x and y have the same solubility ratio in water( the solubility is: 1 g/100 mL at 20 degree celsius and 10 g/100 mL at 100 degree celsius) In this example we predict that if the x and y compunds is in the mix, they have the same solubility ratio. 1. From a mix of 10 g...
I am struggling with this assignment for my java class. Objectives: Your program will be graded...
I am struggling with this assignment for my java class. Objectives: Your program will be graded according to the rubric below. Please review each objective before submitting your work so you don’t lose points. 1.Create a new project and class in Eclipse and add the main method. (5 points) 2. Construct a Scanner to read input from the keyboard. (5 points) 3. Prompt the user with three questions from the Psychology Today quiz, and use the Scanner to read their...
I am having a hard time getting started on how to do this assignment. I would...
I am having a hard time getting started on how to do this assignment. I would like some ideas on how to start the MEMO. and maybe some ideas on what you would include. But I don't necessarily need the assignment completed for me. just need ideas!!! One routine negative message in the form of an internal memo. 400-500 word message. Single-spaced, with 1-inch margins on all sides. Objective: To announce organizational restructuring, one routine negative message addressed to employees....
I am comfortable with structures that contains one item per variable. But i am struggling to...
I am comfortable with structures that contains one item per variable. But i am struggling to manage structure that contains multiple items in one variable (within a matrix). it's in C language. for example this structure :    struct resume{ char *name; char *job; char school*; int counter_resume; }resume; i want to create functions that are able to dynamically allocate memory so it can add multiple persons resume without knowing how many they are going to be in the beginning....
Assembly Question: I am trying to annotate this code and am struggling to understand what it...
Assembly Question: I am trying to annotate this code and am struggling to understand what it is doing. Can someone please add comments? .data .star: .string "*" .line: .string "\n" .input: .string "%d" .count: .space 8 .text .global main printstars: push %rsi push %rdi _printstars: push %rdi mov $.star, %rdi xor %rax, %rax call printf pop %rdi dec %rdi cmp $0, %rdi jg _printstars mov $.line, %rdi xor %rax, %rax call printf pop %rdi pop %rsi ret printstarpyramid: mov %rdi,...
I am struggling with certain types of factoring. I recognize there is a special situation, but...
I am struggling with certain types of factoring. I recognize there is a special situation, but don't understand how to factor it. For example y2+24yw-36w What's the procedure on determining how to factor this?
Hi there I need to write an ethic issue in technology but I am struggling to...
Hi there I need to write an ethic issue in technology but I am struggling to choose a topic. I am asking about the possibility of "Ethical issues" topics that is tread common in technology. Would anyone can give me some options to choose from. Thank you.
Hello, I am working on an assignment but I am unsure of how to solve it....
Hello, I am working on an assignment but I am unsure of how to solve it. Please help me. The assignment details are below. Consider this scenario: Your friend starts a website, nothingbutflags.com, which is not making money. Your friend asks you to help generate more traffic. You ask your friend how much traffic the website had last month? And your friend replies and says only 500 visits. You also ask how many flags did you sell? Your friend replies...
Hello, I am working on an assignment but I am unsure of how to solve it....
Hello, I am working on an assignment but I am unsure of how to solve it. Please help me. The assignment details are below. Consider this scenario: Your friend starts a website, nothingbutflags.com, which is not making money. Your friend asks you to help generate more traffic. You ask your friend how much traffic the website had last month? And your friend replies and says only 500 visits. You also ask how many flags did you sell? Your friend replies...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT