Results 1 to 4 of 4
  1. #1
    Sammie is offline Member
    Join Date
    Nov 2014
    Posts
    3
    Rep Power
    0

    Default help. terminal window problems

    Very new to Java and coding. My high school just opened up a class.
    *I apologize if my code is pushed to left once more.
    How do I get my code to print what I input using the JOptionPane method and by setting its instance variables instead of this mumbo jumbo?
    ---My terminal window shows this :
    Java Code:
    ClockStore@c7c071
    ClockStore@1ec69e3
    ---Main class
    Java Code:
    public class ClockStore
    {
        int hours;
        int minutes;
        int seconds;
        
        public ClockStore ()
        {
            hours=0;
            minutes=0;
            seconds=0;
        } // end zero argument constructor
        
        public ClockStore (int thisHours, int thisMinutes, int thisSeconds)
        {
            hours=thisHours;
            minutes=thisMinutes;
            seconds=thisSeconds;
        }
        
        public String toSring ()
        {
            return "The time is " +hours+ ":" +minutes+ ":" +seconds;
        }
    }
    ---Driver class
    Java Code:
    import javax.swing.JOptionPane;
    public class ClockStoreDriver
    {
        public static void main (String [] args)
        {
            ClockStore kitchenClock = new ClockStore();
            System.out.println(kitchenClock.toString());
            
            ClockStore bedroomClock= new ClockStore();
            String hoursStr=JOptionPane.showInputDialog("Enter the hours");
            int hoursNum=Integer.parseInt(hoursStr);
            
            String minutesStr=JOptionPane.showInputDialog("Enter the minutes");
            int minutesNum=Integer.parseInt(minutesStr);
            
            String secondsStr=JOptionPane.showInputDialog("Enter the seconds");
            int secondsNum=Integer.parseInt(secondsStr);
            
            System.out.println(bedroomClock.toString());
            
            
            
        }
    }
    Last edited by JosAH; 12-01-2014 at 11:46 AM. Reason: added [code] ... [/code] tags

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,001
    Rep Power
    33

    Default Re: help. terminal window problems

    my code is pushed to left once more.
    Please edit your post and wrap your code with highlight tags:
    [highlight=java]
    YOUR CODE GOES HERE
    [/highlight]
    to get highlighting and preserve formatting.

    ClockStore@c7c071
    That is the String returned by the default toString() method for the ClockStore class See the Object class for the toString() method's definition). If you want to see something different, override the toString() method and have it return the String you want to see.
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    1,991
    Rep Power
    8

    Default Re: help. terminal window problems

    Your toString method isn't there. There is one that LOOKS like it: public String toSring (). Spot the typo.
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2 2013

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,001
    Rep Power
    33

    Default Re: help. terminal window problems

    Hint: Every time you are trying to override a method, be sure to put an @Override annotation before it so that the compiler can check it.
    If you don't understand my response, don't ignore it, ask a question.

Similar Threads

  1. Using BlueJ Terminal Window and JFrame simultaneously
    By erroreport in forum AWT / Swing
    Replies: 0
    Last Post: 10-23-2012, 09:25 AM
  2. Replies: 10
    Last Post: 07-03-2011, 01:07 PM
  3. Java - Error in terminal window
    By cvillejin in forum New To Java
    Replies: 3
    Last Post: 04-01-2011, 08:03 PM
  4. Replies: 5
    Last Post: 05-25-2009, 09:03 PM
  5. Replies: 1
    Last Post: 02-16-2008, 11:43 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •