What is the default value for HashMap in Java?

Java error in creating multiple new objects?

  • Write two classes: TestAccount and Account to represent an account. The class contains: a) An int data field named id for the account with value 100. b) A double data field named balance for the account with value 1000. c) A double data field named annualInterestRate that stores the current interest rate with value 0.1 d) The accessor method for id, balance, and annual InterestRate. Account.java public class Account { //attributes double id; double bal; double air; //default constructor public Account() { id = 0.0; bal = 0.0; air = 0.0; } //parameterized constructor (3 parameters) public Account (double id, double bal, double air) { Identity = id; Balance = bal; AnnualInterestRate = air; } public double Identity() { return id; } public double Balance() { return bal; } public double AnnualInterestRate() { return air; } } ERROR: Account.java:19: error: cannot find symbol Identity = id; ^ symbol: variable Identity location: class Account Account.java:20: error: cannot find symbol Balance = bal; ^ symbol: variable Balance location: class Account Account.java:21: error: cannot find symbol AnnualInterestRate = air; ^ symbol: variable AnnualInterestRate location: class Account 3 errors TestAccount.java public class TestAccount { public static void main(String [] args) { //create a new object Identity id = new Identity(100); Balance bal = new Balance(1000); AnnualInterestRate air = new AnnualInterestRate(0.1); //Three variables that retrieve values from the account object's attributes double id = get.id(); double bal = get.bal(); double air = get.air(); double id * bal * air = monthlyinterestrate; } } ERROR: TestAccount.java:15: error: illegal start of expression double id; * bal * air = monthlyinterestrate; ^ 1 error

  • Answer:

    You have not declared the variables you are setting in your constructor. It should be like this : public class Account { //attributes double id; double bal; double air; //default constructor public Account() { id = 0.0; bal = 0.0; air = 0.0; } //parameterized constructor (3 parameters) public Account (double id, double bal, double air) { Id = this.id; bal = this.bal; air = this.air; }

T.A.K. at Yahoo! Answers Visit the source

Was this solution helpful to you?

Other answers

You tried to set variables called Identity, Balance and AnnualInterestRate to certain values without having ever declared those variables anywhere. This is incorrect coding, the compiler can't know what you mean when you do that and so it just gives an error. You need to declare your variables properly.

green meklar

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.