Question

In: Computer Science

Create a Java class file for an Account class. In the File menu select New File......

  1. Create a Java class file for an Account class.
    1. In the File menu select New File...
    2. Under Categories: make sure that Java is selected.
    3. Under File Types: make sure that Java Class is selected.
    4. Click Next.
    5. For Class Name: type Account.
    6. For Package: select csci1011.lab8.
    7. Click Finish.
    8. A text editor window should pop up with the following source code (except with your actual name):
    1. csci1011.lab8;

      /**
      *
      * @author Your Name
      */
      public class Account {

      }
  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

Account Type: SAVING

Account Owner: Customer B

Interest Rate: 1.1

Balance: 700.0

Account Type: CHECKING

Account Owner: Customer A

Interest Rate: 1.2

Balance: 200.0

Solutions

Expert Solution

enum ACCOUNT_TYPE
{
CHECKING,SAVING
}
class Account
{
private ACCOUNT_TYPE aType;
private String accountOwner;
private double interestRate;
private double balance;
public void setAType(ACCOUNT_TYPE aType)
{
this.aType=aType;
}
public ACCOUNT_TYPE getAType()
{
return aType;
}
public void setAccountOwner(String accountOwner)
{
this.accountOwner=accountOwner;
}
public String getAccountOwner()
{
return accountOwner;
}
public void setInterestrate(double interestRate)
{
this.interestRate=interestRate;
}
public double getInterestRate()
{
return interestRate;
}
public void setBalance(double balance)
{
this.balance=balance;
}
public double getBalance()
{
return balance;
}
public void initialize(ACCOUNT_TYPE aType,String accountOwner,double interestRate,double balance)
{
this.aType=aType;
this.accountOwner=accountOwner;
this.interestRate=interestRate;
this.balance=balance;
}
public void display()
{
System.out.println("Account Type: "+getAType());
System.out.println("Account Owner: "+getAccountOwner());
System.out.println("Interest Rate: "+getInterestRate());
System.out.println("Balance: "+getBalance());
}
public void deposit(double amount)
{
balance+=amount;
}
public void withdraw(double amount)
{
if(amount>balance)
System.out.println("Cannot withdraw more than account balance");
else
balance=balance-amount;
}
}
public class Main
{
   public static void main(String[] args)
   {
       Account a1 = new Account();
       a1.setAType(ACCOUNT_TYPE.SAVING);
       a1.setAccountOwner("Customer B");
       a1.setInterestrate(1.1);
       a1.setBalance(500);
       Account a2 = new Account();
       a2.setAType(ACCOUNT_TYPE.CHECKING);
       a2.setAccountOwner("Customer A");
       a2.setInterestrate(1.2);
       a2.setBalance(200);  
       a1.display();
       a2.display();
       a1.deposit(200);
       a2.withdraw(500);
       a1.display();
       a2.display();      
   }
}


Related Solutions

Create a Java class file for a Car class. In the File menu select New File......
Create a Java class file for a Car class. In the File menu select New File... Under Categories: make sure that Java is selected. Under File Types: make sure that Java Class is selected. Click Next. For Class Name: type Car. For Package: select csci2011.lab7. Click Finish. A text editor window should pop up with the following source code (except with your actual name): csci1011.lab7; /** * * @author Your Name */ public class Car { } Implement the Car...
Create a menu in Java. A menu is a presentation of options for you to select....
Create a menu in Java. A menu is a presentation of options for you to select. You can do this in the main() method. 1. Create a String variable named menuChoice. 2. Display 3 options for your program. I recommend using 3 System.out.println statements and a 4th System.out.print to show "Enter your Selection:". This needs to be inside the do -- while loop. A. Buy Stock. B. Sell Stock X. Exit Enter your Selection: 3. Prompt for the value menuChoice....
create a menu in Java. A menu is a presentation of options for you to select....
create a menu in Java. A menu is a presentation of options for you to select. The article above that is in our discussion board may be helpful. You can do this in the main() method. 1. Create a String variable named menuChoice. 2. Display 3 options for your program. I recommend using 3 System.out.println statements and a 4th System.out.print to show "Enter your Selection:". This needs to be inside the do -- while loop. A. Buy Stock. B. Sell...
(In C++) Bank Account Program Create an Account Class Create a Menu Class Create a main()...
(In C++) Bank Account Program Create an Account Class Create a Menu Class Create a main() function to coordinate the execution of the program. We will need methods: Method for Depositing values into the account. What type of method will it be? Method for Withdrawing values from the account. What type of method will it be? Method to output the balance of the account. What type of method will it be? Method that will output all deposits made to the...
Class, Let's create a menu in Java. A menu is a presentation of options for you...
Class, Let's create a menu in Java. A menu is a presentation of options for you to select. You can do this in the main() method. 1. Create a String variable named menuChoice. 2. Display 3 options for your program. I recommend using 3 System.out.println statements and a 4th System.out.print to show "Enter your Selection:". This needs to be inside the do -- while loop. A. Deposit Cash. B. Withdraw Cash X. Exit Enter your Selection: 3. Prompt for the...
android studio -Starting with a basic activity, create a new Java class (use File->New->Java class) called...
android studio -Starting with a basic activity, create a new Java class (use File->New->Java class) called DataBaseManager as in Lecture 5 and create a database table in SQLite, called StudentInfo. The fields for the StudentInfo table include StudentID, FirstName, LastName, YearOfBirth and Gender. Include functions for adding a row to the table and for retrieving all rows, similar to that shown in lecture 5. No user interface is required for this question, t -Continuing from , follow the example in...
Start NetBeans. Create a new project called Lab7. Create a Java main class file using the...
Start NetBeans. Create a new project called Lab7. Create a Java main class file using the class name YourlastnameLab7 with your actual last name. Create a Java class file for a Polygon class. Implement the Polygon class. Add a private instance variable representing the number of sides in the polygon. Add a constructor that takes a single argument and uses it to initialize the number of sides. If the value of the argument is less than three, display an error...
1. Create a1. Create a new java file named Name.java that should have Name class based...
1. Create a1. Create a new java file named Name.java that should have Name class based on new java file named Name.java that should have Name class based on the following UML Name - first: String - last: String + Name () + Name (String firstName, String lastName) + getName () : String + setName (String firstName, String lastName) : void + getFirst () : String + setFirst (String firstName) : void + getLast () : String + setLast (String...
Create a new Java file, containing this code public class DataStatsUser { public static void main...
Create a new Java file, containing this code public class DataStatsUser { public static void main (String[] args) { DataStats d = new DataStats(6); d.append(1.1); d.append(2.1); d.append(3.1); System.out.println("final so far is: " + d.mean()); d.append(4.1); d.append(5.1); d.append(6.1); System.out.println("final mean is: " + d.mean()); } } This code depends on a class called DataStats, with the following API: public class DataStats { public DataStats(int N) { } // set up an array (to accept up to N doubles) and other member...
Create a Java project called Lab3B and a class named Lab3B. Create a second new class...
Create a Java project called Lab3B and a class named Lab3B. Create a second new class named Book. In the Book class: Add the following private instance variables: title (String) author (String) rating (int) Add a constructor that receives 3 parameters (one for each instance variable) and sets each instance variable equal to the corresponding variable. Add a second constructor that receives only 2 String parameters, inTitle and inAuthor. This constructor should only assign input parameter values to title and...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT