There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply () below.
If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.
Join the Discussion. Help a fellow learner on their journey.
Ask or answer a question about this exercise by clicking reply () below!
Agree with a comment or answer? Like () to up-vote the contribution!
In step one of this activity, where it asks you to make a checkBalance function, it throws an error that says, “Oops! The test returned an error. Maybe you have a syntax error, or a typo. See full error.” When I click “See full error” it says, “Cannot read property “0” of undefined.” What does this mean? What do I have to do to fix the error?
The program is telling me that I completed all the steps, but I am seeing errors in the return instead of my printed messages. For every method that I call from the main method, I get an error like the below:
SavingsAccount.java:31: error: non-static method checkBalance() cannot be referenced from a static context
** SavingsAccount.checkBalance();**
Here is my main method:
** public static void main(String args){
SavingsAccount savings = new SavingsAccount(2000);
Late response but this is because you are calling SavingsAccount rather than savings. The new savings account created in the main method is called savings so when checking the balance and whatnot you will want to call savings.checkBalance();
Hey, so I am having trouble with step one of this project. I keep getting a dozen errors after I put my code in,
/*********************/
public void checkBalance(){
System.out.println("Hello!");
System.out.println("Your balance is ");
}
/*********************/
I noticed in the hint that the method title was blue. I dont recall CC teaching how to do that unless you were starting off the code. But does that have something to do with it?
Edit: Never mind i found the issue i didnt follow the instructions
After some experimentation it seems to me that the issue is that you’re providing the information you want in the string, instead of a reference to a string object. I got an error when I tried to use two return commands, I’m guessing that after running the first return command, it returns to the main and the objects in the constructor method are no longer accessible, hence you can only have one return command.
Here’s how I made it work. You’ll notice that the \r creates a linebreak, so we don’t need two separate strings.
public String toString(){
String message = "Accessing Savings Account \rYou are now viewing your savings account. Your balance is " + balance;
Hello everyone maybe i cant read directions or something, but i am really so confused on what to do on the first step each time i think i have it right there is always some sort of error! please help );
hello @midlindner i really appreciate you taking your time to help me ! I’m having trouble with step one of this project ! Simply just stuck maybe i cant understand the directions or something.
In between the constructor and the main() method, add a method called advertise() to the Store class. It should be accessible by other classes, and should have no output.
I’m sorry, i’m not being clear enough it’s the 9th project aka the " Learn Java: Methods - Review " where we are building our own savings account, but the very first step on this one.
Dont know why i keep getting this error i know it has to do with maybe a missing “(” or “{” but not sure if maybe im overseeing something.
/SavingsAccount.java:31: error: illegal start of expression
public void checkBalance() {
^
Ah. Okay. Got it. First, when you post code, it will help me if you click the </> button first, and then paste your code in the space provided. That way I can see how everything is formatted, and even copy and paste it, to run it myself, and help locate errors. Where did you locate the function declaration, and do you have a closing }? The empty function should look like this:
public void checkBalance() {
}
From the error, it appears you may have placed the method inside of the main() method. It needs to be outside the method.
You wont believe it, but i just figured it out haha im so sorry, but i honestly really do i appreciate you taking your time to help me out also will do for next time, rookie mistakes );
It’s because of the two return statements in your toString() method.
As the error message said the second return statement is “unreachable” because the first return already exits the method. When you delete or commenting-out one of the lines with a return statement the program will work.