This is my class

import java.io.*;

public class bankAccount
{
//instance variables
public String name;
public int number;
public double balance;
public double deposit;


//constructor
public bankAccount(String name, int number, double balance, double deposit)
{
	this.name = "John Smith";
	this.number = 123456;
	this.balance = 0.0;
}

public double getBalance()
{
	return balance;
}
public void getDeposit(double deposit)
	{
		balance+=deposit;
	}

public String toString()
{
	return "Name:" + name + "\n number:" + number + "\n balance = " + getBalance();
}
}

and my main

import java.io.*;

public class testBank
{
	public static void main(String[] args)
	{
		bankAccount b;
		b = new bankAccount();
		System.out.println(b.toString());
	}
}

I get the error "cannot find symbol" at the b=new bankAccount() part of the main. Apparently, the symbol is the bankAccount constructor.

Why won't this compile?

I know I'm not really some of the methods in my first class, but Im trying to fix this problem first.

Edited 6 Years Ago by socal: n/a

You need an empty constructor if you're going to provide your own one and you still want to create a bank account without passing parameters to it:

public bankAccount() { }

and I'd change the class name to BankAccount as this is the standard way to name classes with capital letters.

Okay, I've changed the way this program is going to be written. Instead of me supplying the bank info, I'm going to use a Scanner instead.

I'm running into trouble getting the input to work? How would I change the main to use Scanners?

Assign user input into variables? Something like:

import java.util.Scanner;

public class testBank
{
	public static void main(String[] args)
	{
                Scanner in = new Scanner(System.in);

                System.out.println("Enter name.");
                String name = in.nextLine();
                System.out.println("Enter number.");
                int number = in.nextInt();
                // etc

		bankAccount b;
		b = new bankAccount( name, number, balance, deposit );
		System.out.println(b.toString());
	}
}
This article has been dead for over six months. Start a new discussion instead.