Results 1 to 2 of 2
  1. #1
    Javaryan is offline Member
    Join Date
    Oct 2012
    Posts
    1
    Rep Power
    0

    Talking Need Help With the TIME Class!

    So I am stuck on this assignment for my AP Computer Science class in high school. I have to take an incomplete definition of the Time class, and do all this crazy stuff with it. I've been trying for a couple days but my deadline is coming up soon and I'm really hoping someone can help me out.

    Consider the following incomplete definition of the Time class, used to represent a time of day:

    [code]
    public class Time
    {
    private int hour; //a value from 0 to 23
    private int minutes; //a value from 0 to 59
    public Time();
    {
    }
    public Time(int newHour, int newMinutes)
    {
    }
    }
    Questions:

    1) Complete the constructors as defined

    2) Add a printTime method that returns a string representing the time in a 12-hour formate, including am or pm as appropriate. Midnight, when both the hour and minutes fields are zero, and noon, when the hour field is 12 and the minutes field is zero, should be treated as special cases; instead of returning the time using numbers, the words midnight or noon should be returned.

    3) Add an add10 method that adds 10 minutes to the current time.

    4) Add a subtract10 method that subtracts 10 minutes from the current time.

    5) Test the Time class with a client class
    ---- Create two Time objects and enter a loop that does the following
    ---------- print current time for each object
    ---------- ask if the user would like to add time to the first object and then update accordingly
    ---------- ask if the user would like to add time to the second time object and then update accordingly
    ---------- ask if the user would like to subtract time from the first time object then update accordingly
    ---------- you can guess what this is
    ---------- repeat the loop until the user is ready to quit testing
    -- each and every method in the Time class must be called at least once within the client class.

    This is what I have for the first four questions, let me know if I'm on the right track or if I'm doing anything wrong! Thanks in advance.

    Java Code:
    import cs1.Keyboard;
    
    public class Time
    {
    	private int hour; //a value from 0 to 23
    	private int minutes; //a value from 0 to 59
    	Time t = new Time();
    
    	public Time()
    	{
    		public String printTime(String num)
    		{
    			int Time = 0;
    			Time timeClass = new Time (1, 30); //parameters are hour, minutes
    			{
    			if (t = 0, 0);
    				System.out.print("midnight");
    			}
    			{
    			if (t = 12, 0);
    				System.out.print("noon");
    			}
    			{
    				else
    					return Time;
    		}
    
    
    		public void addTen(int num1)
    		{
    			minutes = minutes+10; //add ten minutes
    		}
    
    		public void subtractTen(int num2)
    		{
    			minutes = minutes-10; //subtract ten minutes
    		}
    	}
    	public Time(int newHour, int newMinutes)
    	{
    		hour = newHour();
    		minutes = newMinutes();
    	}
    }
    And this is what I have for the client class so far:
    Java Code:
    import cs1.Keyboard;
    
    public class TestTime
    {
    	public static boolean main (String[] args)
    	{
    		Object t1 = new Object();
    		Object t2 = new Object();
    		Boolean b = new Boolean(true);
    	}
    	while (b = true);
    	{
    	System.out.println(Time);
    	System.out.println("Would you like to add ten seconds to the time?");
    		Keyboard.readBoolean();
    	}
    	{
    	if(b = true);
    		Time.addTen();
    		}
    		{
    		else
    			System.out.println("The time is" + Time);
    		}
    	System.out.println("Would you like to subtract ten seconds from the time?");
    		Keyboard.readBoolean();
    		{
    	if(b = true);
    		Time.subtractTen();
    		}
    		{
    		else
    			System.out.println("The time is" + Time);
    	}
    }
    Any and all help and/or information is very welcome and appreciated!

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,923
    Rep Power
    8

    Default Re: Need Help With the TIME Class!

    Does the code run? Does it do what you expect it to do? You've got quite a few syntax errors and at least one logic error that should be pretty simple to at least detect. Take your problems one at a time and try to break them down into smaller steps. That's easier to do than looking at your entire assignment at one time.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. How to add the time line for main class
    By kewlkeny in forum New To Java
    Replies: 1
    Last Post: 01-03-2012, 12:11 PM
  2. making a Time class but Universal time always says 0
    By Bravid2001 in forum New To Java
    Replies: 2
    Last Post: 10-24-2011, 07:55 AM
  3. Replies: 1
    Last Post: 09-30-2010, 02:36 AM
  4. Class Time - represents time of day
    By verbazon in forum New To Java
    Replies: 1
    Last Post: 04-13-2009, 01:06 AM
  5. First time with abstract class
    By crazydeo in forum New To Java
    Replies: 0
    Last Post: 06-03-2008, 06:24 PM

Tags for this Thread

Posting Permissions

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