Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Newbie questions about lesson on class implementation

  1. #1
    Junior Member
    Join Date
    Apr 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Talking Newbie questions about lesson on class implementation

    Hey everybody,
    I have been learning Java onlin for about a week now.
    here is the program I am trying to get to work
    class OfficeLights {
     
          char Status = Off;
          char Status = On;
          void changeStatus(char newValue) {
               status = newValue;
          }
     
          void printStates() {
               System.out.println("Status:"+Status);
          }
    } 
     
    class CoffeeMug {
     
          char lid = Open;
          char Lid = Closed;
          char Contents = Empty;
          char Contents = Coffee;
          char Contents = Tea; 
     
          void changeLid(char newValue) {
               lid = newValue;
          }
     
          void changeContents(char newValue) {
               Contents = newValue;
          }
     
          void printStates() {
               System.out.println("lid:"+lid+" Contents:"+Contents);
          }
    }
     
    class OfficeLightsCoffeeMug {
        public static void main(String[] JD) {
     
     
          OfficeLights light1 = new OfficeLights();
     
          light1.changeStatus(On);
          light1.printStates();
     
     
          CoffeeMug mug1 = new CoffeeMug();
     
          mug1.changeLid(Closed);
          mug1.changeContents(Coffee);
          mug1.printStates();
          }
    }
    It wont compile, I get 14 error messages.
    I have attached a screenshot of the errors I am getting when I try to compile.
    Any advice on this particular program &| some newbie tips/advice in general would be very welcome,
    Thanks!
    P.S. I hope this is the right topic to post under, sorry if I commited a faux pas...


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Newbie questions about lesson on class implementation

    For starters,
    char Status = Off;
    is not a proper statement. char is a primitive whose syntax is:
    char status = 'o';

    If you just want something to store an off/on value, look into using a boolean
    For more information on primitives which will help you fix your errors, see Primitive Data Types (The Java™ Tutorials > Learning the Java Language > Language Basics)

Similar Threads

  1. java newbie..simple mail server implementation
    By saurabh4dudes in forum Java Networking
    Replies: 0
    Last Post: March 12th, 2010, 08:53 AM
  2. JAAS Implementation with JSF
    By mhwish in forum JavaServer Pages: JSP & JSTL
    Replies: 0
    Last Post: February 20th, 2010, 02:16 AM
  3. Interface Implementation
    By Samyx in forum Object Oriented Programming
    Replies: 1
    Last Post: December 2nd, 2009, 03:46 AM
  4. Help wih implementation...
    By Frank_nor in forum What's Wrong With My Code?
    Replies: 4
    Last Post: November 24th, 2009, 05:43 PM
  5. B+ Tree implementation
    By programmer in forum Java Theory & Questions
    Replies: 2
    Last Post: November 15th, 2009, 05:47 PM