Generalizations complaining I didn't create an object


#1

13/13

class Coffee extends Beverage{
	
	public Coffee() {

	}
	
	public void addSugar(int cubes) {

		System.out.println("You added " + cubes + " sugar cubes.");

	}

	public static void main(String[] args) {
	Coffee myOrder = new Coffee();
  myOrder.addSugar(2);
  myOrder.isFull();
	}
}

The code works without errors, but it won’t let me pass because it’s saying “Did you create the myOrder object within the main method?” …isn’t that exactly what I’ve done? What’s the problem?


#2

There appears to be a missing method. This method call will be a deal breaker.


#3

That method comes from the Beverage class which is given automatically.


#4

We might have known that if we had a link to the exercise. Please post one, thanks.

It should amount to nothing, but do you see any irregularity in the way your above code reads? Perhaps the SCT does.


#5

Sorry, here’s a link:

https://www.codecademy.com/courses/learn-java/lessons/object-oriented-programming/exercises/generalizations-oop-java

I notice when posted here that two of the lines appeared as spaces rather than tabs. I wonder if that was an issue. It didn’t look like there was any difference in the lesson’s IDE.


#6

When the code looks correct, the only thing I can turn to is the formatting. Just a guess, mind, so not anything expert. If one had the time, redoing all the structure manually, line by line, using only space characters (say 4?) might give some indication. It’s a time waster, though, given that indentation and whitespace should not be an issue, here.


#7

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.