Ask your own question, for FREE!
Computer Science 16 Online
OpenStudy (anonymous):

Java: Program doesn't compile Hi, I'm a Java beginner using BlueJ, and I don't understand why this code is not compiling. BlueJ tells me that ')' is expected after 'color', but that is not intended. Can anyone point out to what's wrong in the source code?

OpenStudy (anonymous):

class MyPod{ String color; int memory; double cost; void MyPodinfo(){ System.out.println("This MyPod is " + color ", " + memory + "GB, and $" + cost); } } public class MyPodDriver{ public static void main(String[] args){ MyPod one = new MyPod; one.color = "Red"; one.memory = 30; one.cost = 199.99; one.MyPodinfo(); MyPod two = new MyPod; two.color = "Blue"; two.memory = 60; two.cost = 249.99; two.MyPodinfo(); } }

OpenStudy (anonymous):

MyPod one = new MyPod; is meant to be MyPod one = new MyPod();

OpenStudy (anonymous):

Woah, didn't notice that, thanks. But the code still doesn't compile because the compiler expects a '(' after 'color' in the MyPod class.

OpenStudy (anonymous):

look at MyPod two... =)

OpenStudy (anonymous):

Sure, I corrected that too when you pointed out MyPod one.

OpenStudy (anonymous):

oh also in MyPodinfo you're missing a +

OpenStudy (anonymous):

Compiled! It did the magic. Thank you!

OpenStudy (anonymous):

awesome =)

OpenStudy (anonymous):

next time say at which line it gives error, because you used 'color' more than 1 time

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!