drewman75
asked on
Quick question abouy Java method toString( )
Hello,
I am a relative newbie to Java and I am working my way through a tutorial online. I am getting an error on toString( ) that I just can't figure out. Any ideas?
Error:
MusicStore.java:60: ';' expected
Public String toString() {
//TestMusicStore.java
public class TestMusicStore{
public static void main(String args[]) {
MusicStore myMusic = new MusicStore();
myMusic.setOwner("Drew");
System.out.println(myMusic );
System.exit(0);
}
}
//MusicStore.java
public class MusicStore {
String Owner = "No Owner";
String openMessage = "Yes, we are open!";
String closeMessage = "Sorry, we are closed.";
int openTime = 9;
int closeTime = 21;
void displayHoursOfOperation() {
System.out.println("Store hours: " + openTime + "am to "+ (closeTime - 12) + "pm");
}
void setOwner(String Owner) {
this.Owner = Owner;
}
void displayOwner() {
System.out.println(Owner);
}
String getOwner() {
return Owner;
}
int getOpen() {
return openTime;
}
void setOpen(int openTime) {
this.openTime = openTime;
}
int getClose() {
return closeTime;
}
void setClose(int closeTime) {
this.closeTime = closeTime;
}
boolean isOpen() {
AltDate d = new AltDate();
int currentTime = d.getHourInt();
if(currentTime > openTime && currentTime < closeTime)
return true;
else
return false;
}
void getOpenClosedMessage() {
if(isOpen())
System.out.println(openMes sage);
else
System.out.println(closeMe ssage);
}
Public String toString() {
return "Store Owner is " + Owner + "Store Hours are " + openTime + "am to " +
closeTime + "pm";
}
}
I am a relative newbie to Java and I am working my way through a tutorial online. I am getting an error on toString( ) that I just can't figure out. Any ideas?
Error:
MusicStore.java:60: ';' expected
Public String toString() {
//TestMusicStore.java
public class TestMusicStore{
public static void main(String args[]) {
MusicStore myMusic = new MusicStore();
myMusic.setOwner("Drew");
System.out.println(myMusic
System.exit(0);
}
}
//MusicStore.java
public class MusicStore {
String Owner = "No Owner";
String openMessage = "Yes, we are open!";
String closeMessage = "Sorry, we are closed.";
int openTime = 9;
int closeTime = 21;
void displayHoursOfOperation() {
System.out.println("Store hours: " + openTime + "am to "+ (closeTime - 12) + "pm");
}
void setOwner(String Owner) {
this.Owner = Owner;
}
void displayOwner() {
System.out.println(Owner);
}
String getOwner() {
return Owner;
}
int getOpen() {
return openTime;
}
void setOpen(int openTime) {
this.openTime = openTime;
}
int getClose() {
return closeTime;
}
void setClose(int closeTime) {
this.closeTime = closeTime;
}
boolean isOpen() {
AltDate d = new AltDate();
int currentTime = d.getHourInt();
if(currentTime > openTime && currentTime < closeTime)
return true;
else
return false;
}
void getOpenClosedMessage() {
if(isOpen())
System.out.println(openMes
else
System.out.println(closeMe
}
Public String toString() {
return "Store Owner is " + Owner + "Store Hours are " + openTime + "am to " +
closeTime + "pm";
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
orangehead911 :) you're too fast
Java keywords are all lower case. Class names should be in camel case (http://en.wikipedia.org/wiki/CamelCase) , and start with an upper case letter. Method and variable names should be in camel case (http://en.wikipedia.org/wiki/CamelCase) , and start with a lower case letter.
;-)
could be helpful
Code Conventions for the Java
http://java.sun.com/docs/codeconv/html/CodeConvTOC.doc.html
Code Conventions for the Java
http://java.sun.com/docs/codeconv/html/CodeConvTOC.doc.html
ASKER
Thank you all so much. That did the trick. orangehead911, since you were, first, I will award the points. Thanks to everyone who responded. More points to be had I am sure as I will probably have lots of questions as I venture through learning Java. Thanks again.
We're here to help!
;-D
;-D
public --> lowercase