0

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 by socal: n/a

3
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by idlackage
0

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.

0

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?

0

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 topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.