?
Solved

Quick question abouy Java method toString( )

Posted on 2006-05-24
8
Medium Priority
?
365 Views
Last Modified: 2008-02-01
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(openMessage);
            else
                  System.out.println(closeMessage);
      }      
      
      Public String toString() {
            return "Store Owner is " + Owner + "Store Hours are " + openTime + "am to " +
                              closeTime + "pm";
      }
      
      
}





0
Comment
Question by:drewman75
  • 4
  • 3
8 Comments
 
LVL 14

Accepted Solution

by:
Tommy Braas earned 2000 total points
ID: 16755084
    Public String toString() {

Should be:
     public String toString() {
0
 
LVL 14

Expert Comment

by:hoomanv
ID: 16755102
Public String toString() {

public --> lowercase
0
 
LVL 14

Expert Comment

by:hoomanv
ID: 16755112
orangehead911 :) you're too fast
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 14

Expert Comment

by:Tommy Braas
ID: 16755114
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.
0
 
LVL 14

Expert Comment

by:Tommy Braas
ID: 16755120
;-)
0
 
LVL 14

Expert Comment

by:hoomanv
ID: 16755178
could be helpful

Code Conventions for the Java
http://java.sun.com/docs/codeconv/html/CodeConvTOC.doc.html
0
 

Author Comment

by:drewman75
ID: 16755261
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.
0
 
LVL 14

Expert Comment

by:Tommy Braas
ID: 16755272
We're here to help!

;-D
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
Suggested Courses
Course of the Month13 days, 20 hours left to enroll

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question