import java.io.*;
import java.util.*;
public class BankAccount
{
public static void main(String[] args)
{
BankAccount matschecking = new BankAccount();
matschecking.deposit(1000);
matschecking.withdraw(500);
matschecking.withdraw(400);
System.out.println(matschecking.getBalance());
}
{
balance = 0;
}
//public BankAccountTester(double initialBalance)
{
//balance = initialBalance;
}
public void deposit(double amount)
{
double newBalance = balance + amount;
balance = newBalance;
}
public void withdraw(double amount)
{
double newBalance = balance - amount;
balance = newBalance;
}
public double getBalance()
{
return balance;
}
private double balance;
}
19 Replies - 311 Views - Last Post: 13 July 2012 - 11:21 AM
#1
I keep getting errors, what is needed?
Posted 12 July 2012 - 06:26 PM
Replies To: I keep getting errors, what is needed?
#2
Re: I keep getting errors, what is needed?
Posted 12 July 2012 - 11:30 PM
Except for being improperly indented, your source code looks fine. What happens when you try to run it in JCreator?
#3
Re: I keep getting errors, what is needed?
Posted 13 July 2012 - 01:41 AM
The code works fine in Eclipse too so what is the problem exactly?
#4
Re: I keep getting errors, what is needed?
Posted 13 July 2012 - 07:30 AM
it comes up with 2 errors, both are "cannot find symbol". The unfound symbols are both BankAccount on line 08, (BankAccount matschecking = new BankAccount()
.
#5
Re: I keep getting errors, what is needed?
Posted 13 July 2012 - 07:35 AM
I have no experience with JCreator, but since that's obviously a ridiculous error for the code you've posted, I have to ask if the class name and file name (.java) are the same in the JCreator project you've created, or whatever it's called.
. . . or the code you've posted is different than what you have in the JCreator class.
. . . or the code you've posted is different than what you have in the JCreator class.
This post has been edited by GregBrannon: 13 July 2012 - 07:39 AM
#6
Re: I keep getting errors, what is needed?
Posted 13 July 2012 - 07:51 AM
The code is the same and the class and file names match.
#7
Re: I keep getting errors, what is needed?
Posted 13 July 2012 - 09:00 AM
I created this using Java on Netbeans. I need to know what changes I should make to get it to work.
import java.io.*;
import java.util.*;
public class SavingsAccount
{
public static void main(String[] args)
{
BankAccount matssavings = new BankAccount(1000);
matssavings.addInterest(10);
System.out.println(matssavings.getBalance());
}
{
balance = 0;
}
//public BankAccountTester(double initialBalance)
{
//balance = initialBalance;
}
public void deposit(double amount)
{
double newBalance = balance + amount;
balance = newBalance;
}
public void withdraw(double amount)
{
double newBalance = balance - amount;
balance = newBalance;
}
public void addInterest(double rate)
{
double newBalance = balance + rate;
balance = newBalance;
}
public double getBalance()
{
return balance;
}
private double balance;
}
#8
Re: I keep getting errors, what is needed?
Posted 13 July 2012 - 09:07 AM
In what way is it not working? What is it doing that you want it to do, or what is it not doing that you think it ought to do? If there are errors, please paste the compiler output so we can help you trace them.
#9
Re: I keep getting errors, what is needed?
Posted 13 July 2012 - 09:15 AM
this is the run output:
run:
Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - cannot find symbol
symbol: class BankAccount
location: class SavingsAccount
at SavingsAccount.main(SavingsAccount.java:12)
Java Result: 1
BUILD SUCCESSFUL (total time: 2 seconds)
and this is the debugger output:
Listening on javadebug
User program running
Debugger stopped on uncompilable source code.
Thread main stopped at SavingsAccount.java:12.
run:
Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - cannot find symbol
symbol: class BankAccount
location: class SavingsAccount
at SavingsAccount.main(SavingsAccount.java:12)
Java Result: 1
BUILD SUCCESSFUL (total time: 2 seconds)
and this is the debugger output:
Listening on javadebug
User program running
Debugger stopped on uncompilable source code.
Thread main stopped at SavingsAccount.java:12.
#10
Re: I keep getting errors, what is needed?
Posted 13 July 2012 - 09:34 AM
you have a lot of unnecessary brackets { }
#11
Re: I keep getting errors, what is needed?
Posted 13 July 2012 - 10:15 AM
What that error is telling you is that the compiler can't find a class called BankAccount. Is there a file called BankAccount.class visible to the SavingsAccount class?
#12
Re: I keep getting errors, what is needed?
Posted 13 July 2012 - 10:35 AM
How would you recommend I go about that?
#13
Re: I keep getting errors, what is needed?
Posted 13 July 2012 - 10:48 AM
Go about what? I asked a question!
#14
Re: I keep getting errors, what is needed?
Posted 13 July 2012 - 10:53 AM
I created the file but it doesn't seem to make much of a difference.
this is the file:
and the output:
Exception in thread "main" java.lang.UnsupportedOperationException: Not yet implemented
at BankAccount.<init>(BankAccount.java:13)
at SavingsAccount.main(SavingsAccount.java:10)
Java Result: 1
BUILD SUCCESSFUL (total time: 2 seconds)
this is the file:
class BankAccount {
BankAccount(int i) {
throw new UnsupportedOperationException("Not yet implemented");
}
void addInterest(int i) {
throw new UnsupportedOperationException("Not yet implemented");
}
}
and the output:
Exception in thread "main" java.lang.UnsupportedOperationException: Not yet implemented
at BankAccount.<init>(BankAccount.java:13)
at SavingsAccount.main(SavingsAccount.java:10)
Java Result: 1
BUILD SUCCESSFUL (total time: 2 seconds)
#15
Re: I keep getting errors, what is needed?
Posted 13 July 2012 - 10:57 AM
Right. That's exactly what you expect to get if you put that Exception in the constructor.
Why do you have BankAccount at all? Your class is called SavingsAccount. Are you trying to make a superclass for it?
Why do you have BankAccount at all? Your class is called SavingsAccount. Are you trying to make a superclass for it?
|
|

New Topic/Question
Reply



MultiQuote




|