Question

Hello, I'm very new to programming and I'm running into a problem with the system.out.println function...

Hello, I'm very new to programming and I'm running into a problem with the system.out.println function in the TestAccount Class pasted below.

Account Class:

import java.util.Date;
public class Account {

   private int accountId;
   private double accountBalance, annualInterestRate;
   private Date dateCreated;

   public Account(int id, double balance) {
id = accountId;
       balance = accountBalance;
dateCreated = new Date();
   }

   public Account() {
dateCreated = new Date();
   }

   public int getId() {
return accountId;
   }

   public double getAnnualInterestRate() {
return annualInterestRate;
   }
  
   public String getDateCreated() {
return dateCreated.toString();
   }
  
   public double getMonthlyInterest() {
return annualInterestRate / 12;
   }
  
   public double getBalance() {
return accountBalance;
   }
  
   public void setId(int id) {
accountId = id;
   }
  
   public void setBalance(double balance) {
accountBalance = balance;
   }
  
   public void setaccountAnnualInterestRate(double d) {
annualInterestRate = d;   
       }  

   public void deposit(double a) {
accountBalance += a;
   }
   public void withdraw(double i) {
if(accountBalance >= i) {
accountBalance -= i;
}
   }

}

TestAccount Class:

public class TestAccount {

   public static void main(String[] args) {
Account account = new Account(1122, 20000);
account.setaccountAnnualInterestRate(4.5);
account.setId(1122);
account.setBalance(20000);
  
System.out.println("Balance before withdrawal is " + account.getBalance()); // this line won't print every other line works. Please help me solve this issue.
System.out.println("Your account ID is: " + account.getId());
System.out.println("The annual interest rate is " + account.getAnnualInterestRate());
  
account.withdraw(2500);
  
System.out.println("Balance after withdrawal is " + account.getBalance());
  
account.deposit(3000);
  
System.out.println("Your current balance is " + account.getBalance());
System.out.println("Monthly interest is " + account.getMonthlyInterest());
System.out.println("This account was created at " + account.getDateCreated());

       }

   }

What am i doing wrong? Please help correct the code. Thank you.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Dear Student ,

As per requirement submitted above kindly find below solution.

Account.java :

import java.util.Date;//import package
//Java class
public class Account {
   //instance variables
   private int accountId;
   private double accountBalance, annualInterestRate;
   private Date dateCreated;
   //constructor
   public Account(int id, double balance) {
       id = accountId;
       balance = accountBalance;
       dateCreated = new Date();
   }
   //constructor
   public Account() {
       dateCreated = new Date();
   }
   //getter method
   public int getId() {
       return accountId;
   }

   public double getAnnualInterestRate() {
       return annualInterestRate;
   }

   public String getDateCreated() {
       return dateCreated.toString();
   }

   public double getMonthlyInterest() {
       return annualInterestRate / 12;
   }

   public double getBalance() {
       return accountBalance;
   }
   //setter method
   public void setId(int id) {
       accountId = id;
   }

   public void setBalance(double balance) {
       accountBalance = balance;
   }

   public void setaccountAnnualInterestRate(double d) {
       annualInterestRate = d;
   }
   //method to deposit amount
   public void deposit(double a) {
       accountBalance += a;
   }

   public void withdraw(double i) {
       if (accountBalance >= i) {
           accountBalance -= i;
       }
   }

}

*************************************

TestAccount.java :

//java class
public class TestAccount {
   //main() method
   public static void main(String[] args) {
       //object of Account class
       Account account = new Account(1122, 20000);
       account.setaccountAnnualInterestRate(4.5);//set
       account.setId(1122);//set ID
       account.setBalance(20000);//set balance
       //print balance
       System.out.println("Balance before withdrawal is " + account.getBalance()); // this line won't print every other
                                                                       // line works. Please help me solve
                                                                                   // this issue.
       //print ID
       System.out.println("Your account ID is: " + account.getId());
       System.out.println("The annual interest rate is " + account.getAnnualInterestRate());//print interest rate
       //call method to withdraw amount
       account.withdraw(2500);
       //print balance
       System.out.println("Balance after withdrawal is " + account.getBalance());
       //deposit amount
       account.deposit(3000);
       //print balance
       System.out.println("Your current balance is " + account.getBalance());
       System.out.println("Monthly interest is " + account.getMonthlyInterest());
       System.out.println("This account was created at " + account.getDateCreated());

   }

}

==================================

Output :Compile and run TestAccount.java to get the screen as shown below

Screen 1:TestAccount.java

NOTE :PLEASE FEEL FREE TO PROVIDE FEEDBACK ABOUT THE SOLUTION.

Add a comment
Know the answer?
Add Answer to:
Hello, I'm very new to programming and I'm running into a problem with the system.out.println function...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Unable to find out why am I getting: Account.java:85: error: reached end of file while parsing...

    Unable to find out why am I getting: Account.java:85: error: reached end of file while parsing import java.util.*; class Account{ private int id; private double balance; private double annualInterestRate; private Date dateCreated; public Account() { id = 0; balance = 0; annualInterestRate = 0; dateCreated = new Date(); } public Account(int id1, double balance1) { id =id1; balance = balance1; dateCreated = new Date(); } public void setId(int id1) { id=id1; } public void setBalance(double balance1) { balance = balance1;...

  • The code is attached below has the Account class that was designed to model a bank account.

    IN JAVAThe code is attached below has the Account class that was designed to model a bank account. An account has the properties account number, balance, annual interest rate, and date created, and methods to deposit and withdraw funds. I need creat program using the 2 java programs.Create two subclasses for checking and savings accounts. A checking account has an overdraft limit, but a savings account cannot be overdrawn.I need to write a test program that creates objects of Account,...

  • Design a class named BankAccount that contains: 1. A private int data field named accountId for...

    Design a class named BankAccount that contains: 1. A private int data field named accountId for the account. 2. A private double data field named accountBalance for the account (default 0). 3. A private double data field named annualInterestRate that stores the current interest rate (default 0). Assume all accounts have the same interest rate. 4. A private Date data field named dateCreated that stores the date when the account was created. 5. A private int data field named numberOfDeposits...

  • How do you write a test class that tests each of the setters and constructors to ensure that the appropriate exception is raised?(Note: sed. Recall that the setter method should be called in the constructor and the edits should not be in the setters, not

     /** * Write a description of class LoanTest here. * */public class Loan {  private double annualInterestRate;  private int numberOfYears;  private double loanAmount;  private java.util.Date loanDate;  /** Default constructor */  public Loan() {    this(2.5, 1, 1000);  }  /** Construct a loan with specified annual interest rate,      number of years and loan amount     */  public Loan(double annualInterestRate, int numberOfYears,double loanAmount){    if(loanAmount <= 0)    {        throw new IllegalArgumentException("loan must be greater than 0");       } ...

  • (Enable the Account class comparable & cloneable) @ Create ComparableAccount class inheritanc...

    (Enable the Account class comparable & cloneable) @ Create ComparableAccount class inheritance from the Account class, and implemented the comparable and cloneable interfaces. Override the compareTo method to compare the balance of two accounts. Print the Account ID, balance and dataCreated information from the toString() method. Implements the cloneable interface and override the clone method to perform a deep copy on the dateCreated field. Write a driver program to create one array contains 5 ComparableAcccount objects (account #: 1001-1005, initial...

  • 9.7 (The Account class) Design a class named Account that contains: • A private int data...

    9.7 (The Account class) Design a class named Account that contains: • A private int data field named id for the account (default o). • A private double data field named balance for the account (default o). • A private double data field named annualInterestRate that stores the current interest rate (default o). Assume that all accounts have the same interest rate. • A private Date data field named dateCreated that stores the date when the account was created. •...

  • (The Account class) Design a class named Account that contains: A private int data field named...

    (The Account class) Design a class named Account that contains: A private int data field named id for the account (default 0). A private double data field named balance for the account (default 0). A private double data field named annualInterestRate that stores the current interest rate (default 0). Assume all accounts have the same interest rate. A private Date data field named dateCreated that stores the date when the account was created. A no-arg constructor that creates a default...

  • NETBEANS JAVA BANK PROGRAM (TAKE SCREENSHOTS FROM NETBEANS INCLUDING OUTPUT PLEASE) Display the accounts for the...

    NETBEANS JAVA BANK PROGRAM (TAKE SCREENSHOTS FROM NETBEANS INCLUDING OUTPUT PLEASE) Display the accounts for the current displayed customer PLEASEEEEEEEEEE package bankexample; import java.util.UUID; public class Customer { private UUID id; private String email; private String password; private String firstName; private String lastName;    public Customer(String firstName, String lastName, String email, String password) { this.id = UUID.randomUUID(); this.firstName = firstName; this.lastName = lastName; this.email = email; this.password = password; } public String getFirstName() { return firstName; } public void setFirstName(String...

  • java code ========= public class BankAccount { private String accountID; private double balance; /** Constructs a...

    java code ========= public class BankAccount { private String accountID; private double balance; /** Constructs a bank account with a zero balance @param accountID - ID of the Account */ public BankAccount(String accountID) { balance = 0; this.accountID = accountID; } /** Constructs a bank account with a given balance @param initialBalance the initial balance @param accountID - ID of the Account */ public BankAccount(double initialBalance, String accountID) { this.accountID = accountID; balance = initialBalance; } /** * Returns the...

  • Why is my program returning 0 for the area of a triangle? public class GeometricObjects {...

    Why is my program returning 0 for the area of a triangle? public class GeometricObjects {    private String color = " white ";     private boolean filled;     private java.util.Date dateCreated;     public GeometricObjects() {         dateCreated = new java.util.Date();     }     public GeometricObjects(String color, boolean filled) {         dateCreated = new java.util.Date();         this.color = color;         this.filled = filled;     }     public String getColor() {         return color;     }     public void setColor(String color)...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT