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!
hey program starts from main(), so we have to call methods in class from main(). to use class features you have to define a object. therefore, you have to create a object .
Hey @beta9836886690, @giga3691109859, welcome to the forums! @giga3691109859 is right… you have to define a main method otherwise Java will throw an error. (that is where the program starts from, after all.)
Hey, I’ve been doing this practise and ended up getting the following error:
./Store.java:8: error: illegal start of expression
public void greetCustomer(String customer){
^
And these giant blocks of errors:
public void greetCustomer(String customer){
^
Store.java:14: error: class, interface, or enum expected
public void advertise() {
^
Store.java:16: error: class, interface, or enum expected
System.out.println(message);
^
Store.java:17: error: class, interface, or enum expected
}
^
Store.java:20: error: class, interface, or enum expected
public static void main(String args) {
^
Store.java:23: error: class, interface, or enum expected
}
^
6 errors
}
I have everything where it said to put it and where it automatically was yet i still get errors and can’t print the message and the errors are the exact same as the ones that tag got
Edit: actually prob bc i didnt have the declaration of the method
public Store(String product) {
productType = product;
What are you missing here? Return type for the method is missing but its a constructor. So why do we get this message? Hint would be your missing something at the end to close this.
public void greetCustomer(String customer) {
System.out.println("Welcome to the store, " + customer + "!");
}
}
Same thing, do you notice something wrong at the very end of this? This might be the reason you having an error with your constructor. You cannot (correct me if I am wrong) define greetCustomer inside the constructor.
Store lemonadeStand = new Store("Lemonade");
}
public class Store {
// instance fields
String productType;
// constructor method
public Store(String product) {
productType = product;
}
public void greetCustomer(String customer) {
System.out.println("Welcome to the store, " + customer + "!");
}
// advertise method
public void advertise() {
String message = "Selling " + productType + "!";
System.out.println(message);
}
}
Is it just me or does the for Adding Parameters lesson have an error in it? It gives the example:
class Car {
String color;
public Car(String carColor) {
color = carColor;
}
public void startRadio(double stationNum, String stationName) {
System.out.println("Turning on the radio to " + stationNum + ", " + station + "!");
System.out.println("Enjoy!");
}
public static void main(String[] args){
Car myCar = new Car("red");
myCar.startRadio(103.7, "Meditation Station");
}
}
But surely this code wouldn’t work because the variable station from the start radio method is undefined?
I came here just to see if anyone else noticed it too and if this was correct and not a typo. Glad to know it was just a typo and my bug finding skills are developing early
Why do we put the variables in the constructor method in the instance field but when we don’t put the the variables made in the advertise method in the instance fields?
Hello
I think the purpose is to separate the tasks that are doable to a “Store” into methods because of a style called OOP. (Object-oriented Programming)
Correct me if I am wrong. Any feedback is greatly appreciated!
Will this course teach me how to take user input to create an object? It would be useful and more practical than me creating my own made up objects. I want to be able to learn how to connect user input with my classes that I’m creating.