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 11 of 11

Thread: Could someone explain to me what exactly is messing up?

  1. #1
    Member
    Join Date
    Aug 2013
    Posts
    40
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Could someone explain to me what exactly is messing up?

    I am working on a group project, and my partner bailed on me, and just left me with his broken half of the code. I have finished his half and mine, but Its not exactly compiling right. Could someone take a look at it and point me in the direction of my mistake?

    Here is the assignment:

    In this project, you must implement a simplified version of the student registration system. In particular, your system must present a
    student with a set of courses, with all their relevant information, and allow the student to select five courses, one at a time, that do not
    conflict in day or time.

    If we restate the requirements for this assignment in a single sentence, we might say the following:
    “The user selects courses from a set of offerings such that the day and time ranges of each course do not conflict with the day and time
    ranges of the other selected courses.” With that restatement, we can pick out the nouns to begin our object-oriented design. Here, the
    nouns are “user,” “course,” “offering,” “day,” “time,” and “range.” In this case, the user should probably not be a class itself, but the
    others (excepting “day”) make a lot of sense. So we'll use those four classes for the solution.

    The specific requirements for each class are presented below. Each team must distribute these classes one per member to be
    implemented according to the given specifications. Each member will be scored individually based on his own implemented class,
    which must, at a minimum, pass all unit tests provided to be considered satisfactory. The individual performance represents 70% of the
    individual's grade, with the other 30% to be determined from the group submission.



    Time
    This class represents an hour-minute designation for a time of day. It should represent hours in military (24-hour) time, where, for
    example, 3pm is represented as 1500. It should allow time to be specified as both an hour-minute pair of integers (within the
    appropriate ranges) or as a string like “1530”. The class should also allow comparisons of two Time objects so as to know whether one
    comes before, after, or is equal to another.

    Private Attributes
    int hour
    must be in range [0, 23]

    int minute
    must be in range [0, 59]

    Private Methods
    String pad(String time)
    pads a given string representing a time with leading zeros, so that, for instance, “115” becomes “0115”.

    int[] convertStringToHoursMins(String time)
    converts a (possibly unpadded) string to hours and minutes, which are returned as a two-element array of integers where element 0 is
    hours and element 1 is minutes. This method may throw a NumberFormatException if the string contains elements that cannot be
    converted to integers.

    Public Methods
    Time()
    default constructor that initializes the time to midnight (0 hour and 0 minute).

    Time(String time)
    constructor that initializes the time to the value contained in the string argument. The value of the string must be a valid time;
    otherwise, the constructor initializes the object to midnight.

    Time(int hour, int minute)
    constructor that initializes the time to the hour and minute specified. The values for hour and minute must be within the valid ranges;
    otherwise, they are replaced with zeros.

    int getHour()
    returns the hour

    void setHour(int hour)
    sets the hour, if it is within the allowed range

    int getMinute()
    returns the minute

    void setMinute(int minute)
    sets the minute, if it is within the allowed range

    void setTime(String time)
    sets the time based on the given string, if it contains legal hour and minute values

    boolean before(Time time)
    returns true if the time held in the current object occurs before the time object being passed

    boolean after(Time time)
    returns true if the time held in the current object occurs after the time object being passed

    boolean equals(Time time)
    returns true if the time held in the current object is the same as the time object being passed

    String toString()
    returns the string representation of the current object, which should be of the form “HHMM”

    TimeRange
    This class represents a duration or range of time marked by a starting and ending time. This class does not allow for such a range of
    time to extend to the following day. In other words, the start time must always come before the end time without considering the days.
    So defining a range like 1900 to 0200 (7pm to 2am) would instead be interpreted as 0200 to 1900 (2am to 7pm).

    Private Attributes
    Time startTime
    Time endTime
    the starting and ending times for the range. The start time must always come before the end time.

    Public Methods
    TimeRange(Time startTime, Time endTime)
    constructor that takes a start and end time and initializes the object. If the start time does not come before the end time, the constructor
    switches them around to make the range meaningful.

    Time getStartTime()
    Time getEndTime()
    returns the start and end times, respectively. Note that there are no equivalent setter methods here. This is because a setter method
    might violate the “start comes before end” property, forcing the time range to rearrange itself to remain meaningful. Instead, any
    changes must be done by instantiating a new TimeRange object.

    int getDuration()
    returns the duration in minutes of the range

    boolean contains(Time time)
    returns true if the current TimeRange object contains the time passed in. For instance, the time range (1000, 1400) contains 1030 (and
    1000 and 1400 and all times in between) but does not contain 0800 or 1500 (or 1401, for that matter).

    boolean overlaps(TimeRange otherTime)
    returns true if the current TimeRange object overlaps the TimeRange object passed in. For instance, the time range(1000, 1400)
    overlaps the ranges (1100, 1500), (1030, 1130), and (0900, 1430), but it does not overlap the range (0800, 0900).

    String toString()
    returns the string representation of the time range of the form “HHMM-HHMM” where the first time is the start and the second is the
    end

    Here is the Time class:

    import java.io.*;
    import java.util.*;
    public class Time {
     
    	private int hour;
    	private int minute;
     
    	public static void main (String[] args)
    	{  	
    		int hour = 0;
    		int minute = 0;
    		int total = 0;
    		total = hour + minute;
    		Time newTime = new Time();
    	}
     
    	private String pad(String time)
    	{ 
    		if (time.length() == 3){
    		time = 0 + time;
    		return time;
            }
            else{
                return time;
            }
    	}
     
    	private int[] convertStringToHoursMins(String time) 
    	{ 
            time = pad(time);
    		String[] array = new String[100];
    		String[] compile = new String[100];
    		int[] timen = new int[2];
    		compile = time.split("");
    		int a = 0;
    		for (String item: compile){
    					array[a] = item;
    					a = a+1;	
    			}
    				timen[0] = Integer.parseInt(array[1] + array[2]);
    				timen[1] = Integer.parseInt(array[3] + array[4]);
    				return timen;
    	}
     
    	public Time(){
    		hour = 0;
    		minute = 0;
     
    	}
    	public Time(String time){
            int timeq = Integer.parseInt(pad(time));
            hour = timeq / 100;
            minutes = timeq % 100;
     
    	}
     
    	public Time(int hour,int minute){
            if (( hour <= 24 && hour >= 0) && (min >= 0 && min <= 60){
                hour = hour;
                minute = minute;
            }
            else{
                hour = 00;
                minute = 00;
            }
    	}
     
    	}
    	public int getHour(){
    	return hour;
    	}
    	public void setHour(int hour){
    	if (hour > 0 && hour < 23){
    	hour = hour;
    	}
    	}
     
    	public int getMinute(){
    	return minute;
    	}
    	public void setMinute(int minute){
    	if (minute > 0 && minute < 59){
    	minute = minute;
    	}
    	}
    	public void setTime(String time){
    	int timeq = Integer.parseInt(pad(time));
            hour = timeq / 100;
            minutes = timeq % 100;
    	}
     
    	boolean before(Time time){
            int newHour = time.getHour();
            int newMin = time.getMinute();
            int newTime = (newHour * 60) + newMin;
            int currentTime = (hour * 60) + minute;
            if (currentTime < newTime){
                return true;
            }
            else{
                return false;
            }
    	}
     
        boolean after (Time time){
            int newHour = time.getHour();
            int newMin = time.getMinute();
            int newTime = (newHour * 60) + newMin;
            int currentTime = (hour * 60) + minute;
            if (currentTime > newTime){
                return true;
            }
            else{
                return false;
            }
        }
     
        boolean equals (Time time){
            int newHour = time.getHour();
            int newMin = time.getMinute();
            int newTime = (newHour * 60) + newMin;
            int currentTime = (hour * 60) + minute;
            if (currentTime == newTime){
                return true;
            }
            else{
                return false;
            }
        }
     
         public String toString(){
            String currentTime = "" +  hour + minute;
            return currentTime;
        }
    }

    Here is the timeRange Class:

    import java.io.*;
    import java.util.*;
     
    public class TimeRange{
     
        // Private Attributes.
        private Time startTime;
        private Time endTime;
     
        /* Constructor that takes a start and end time and initializes the object. If the start time does not come before the end time, the constructor 
            switches them around to make the range meaningful. */
        public TimeRange(Time startTime, Time endTime){
            if (startTime > endTime){
                Time temp = startTime;
                startTime = endTime;
                endTime = temp;
            }
            else{
                startTime = startTime;
                endTime = endTime;
            }
     
        }
     
        // Returns the start and end times, respectively. 
        public Time getStartTime(){
            return startTime;
        }
     
        public Time getEndTime(){
            return endTime;
        }
     
        // Returns the duration in minutes of the range.
        public int getDuration(){
            int endHour = endTime.getHour();
            int endMin = endTime.getMinute();
            int startHour = startTime.getHour();
            int startMin = startTime.getMin();
            int startTime = (startHour * 60) + startMin;
            int endTime = (endHour * 60) + endMin;
            return (Math.abs(endTime - startTime));
        }
     
        /* Returns true if the current TimeRange object contains the time passed in. For instance, the time range (1000, 1400) contains 1030 (and 
            1000 and 1400 and all times in between) but does not contain 0800 or 1500 (or 1401, for that matter). */
        boolean contains(Time time){
            int endHour = endTime.getHour();
            int endMin = endTime.getMinute();
            int startHour = startTime.getHour();
            int startMin = startTime.getMin();
            int startTime = (startHour * 60) + startMin;
            int endTime = (endHour * 60) + endMin;
            int timeHour = time.getHour();
            int timeMin = time.getMinute();
            int timec = (timeHour * 60) + timeMin;
     
            if (time <= endTime && timec >= startTime){
                return true;
            }
            else{
                return false;
            }
        }
     
        /* Returns true if the current TimeRange object overlaps the TimeRange object passed in. For instance, the time range(1000, 1400) 
            overlaps the ranges (1100, 1500), (1030, 1130), and (0900, 1430), but it does not overlap the range (0800, 0900). */
        boolean overlaps(TimeRange otherTime){
            if (contains(otherTime.getStartTime())){
                return true;
            }
            else if (contains(otherTime.getEndTime())){
                return true;
            }
            else if (otherTime.contains(startTime)){
                return true;
            }
            else if (otherTime.contains(endTime)){
                return true;
            }
            else{
                return false;
            }
     
        }
     
         // Returns the string representation of the time range of the form "HHMM-HHMM" where the first time is the start and the second is the end.
        public String toString(){
            int endHour = endTime.getHour();
            int endMin = endTime.getMinute();
            int startHour = startTime.getHour();
            int startMin = startTime.getMin();
            String timeRange = "" + startHour + startMin + " - " + endhour + endMin;
            return timeRange;
        }
    }

    Here is a test program that my teacher gave us in order to test the timeRange (my particular part in the project) :

    import junit.framework.*;
     
    public class TestTimeRange extends TestCase { 
        private TimeRange t;
        private TimeRange u;
        public TestTimeRange(String name) {
            super(name);
        }
        protected void setUp() { 
            t = new TimeRange(new Time(11, 30), new Time(10, 00));
            u = new TimeRange(new Time(11, 0), new Time(14, 0));
        }
        public void testGets() {
            assertEquals("1000", t.getStartTime().toString());
            assertEquals("1130", t.getEndTime().toString());
            assertEquals("1100", u.getStartTime().toString());
            assertEquals("1400", u.getEndTime().toString());
        }
        public void testGetDuration() {
            assertEquals(90, t.getDuration());
            assertEquals(180, u.getDuration());
        }
        public void testContains() {
            assertTrue(t.contains(new Time("1100")));
            assertTrue(t.contains(new Time("1000")));
            assertTrue(!t.contains(new Time("0959")));
            assertTrue(!t.contains(new Time("1131")));
        }
        public void testOverlaps() {
            assertTrue(t.overlaps(u));
            assertTrue(!t.overlaps(new TimeRange(new Time("1400"), new Time("1500"))));
        }
    }

    Here are the errors I am getting when I try and compile the codes:

    Time class:


    C:\Users\Jared\Desktop\Group Project\TimeRange>javac Time.java
    Time.java:58: error: ')' expected
            if (( hour <= 24 && hour >= 0) && (min >= 0 && min <= 60){
                                                                     ^
    Time.java:69: error: class, interface, or enum expected
            public int getHour(){
                   ^
    Time.java:71: error: class, interface, or enum expected
            }
            ^
    Time.java:72: error: class, interface, or enum expected
            public void setHour(int hour){
                   ^
    Time.java:75: error: class, interface, or enum expected
            }
            ^
    Time.java:78: error: class, interface, or enum expected
            public int getMinute(){
                   ^
    Time.java:80: error: class, interface, or enum expected
            }
            ^
    Time.java:81: error: class, interface, or enum expected
            public void setMinute(int minute){
                   ^
    Time.java:84: error: class, interface, or enum expected
            }
            ^
    Time.java:86: error: class, interface, or enum expected
            public void setTime(String time){
                   ^
    Time.java:88: error: class, interface, or enum expected
            hour = timeq / 100;
            ^
    Time.java:89: error: class, interface, or enum expected
            minutes = timeq % 100;
            ^
    Time.java:90: error: class, interface, or enum expected
            }
            ^
    Time.java:94: error: class, interface, or enum expected
            int newMin = time.getMinute();
            ^
    Time.java:95: error: class, interface, or enum expected
            int newTime = (newHour * 60) + newMin;
            ^
    Time.java:96: error: class, interface, or enum expected
            int currentTime = (hour * 60) + minute;
            ^
    Time.java:97: error: class, interface, or enum expected
            if (currentTime < newTime){
            ^
    Time.java:99: error: class, interface, or enum expected
            }
            ^
    Time.java:102: error: class, interface, or enum expected
            }
            ^
    Time.java:107: error: class, interface, or enum expected
            int newMin = time.getMinute();
            ^
    Time.java:108: error: class, interface, or enum expected
            int newTime = (newHour * 60) + newMin;
            ^
    Time.java:109: error: class, interface, or enum expected
            int currentTime = (hour * 60) + minute;
            ^
    Time.java:110: error: class, interface, or enum expected
            if (currentTime > newTime){
            ^
    Time.java:112: error: class, interface, or enum expected
            }
            ^
    Time.java:115: error: class, interface, or enum expected
            }
            ^
    Time.java:120: error: class, interface, or enum expected
            int newMin = time.getMinute();
            ^
    Time.java:121: error: class, interface, or enum expected
            int newTime = (newHour * 60) + newMin;
            ^
    Time.java:122: error: class, interface, or enum expected
            int currentTime = (hour * 60) + minute;
            ^
    Time.java:123: error: class, interface, or enum expected
            if (currentTime == newTime){
            ^
    Time.java:125: error: class, interface, or enum expected
            }
            ^
    Time.java:128: error: class, interface, or enum expected
            }
            ^
    Time.java:131: error: class, interface, or enum expected
         public String toString(){
                ^
    Time.java:133: error: class, interface, or enum expected
            return currentTime;
            ^
    Time.java:134: error: class, interface, or enum expected
        }
        ^
    34 errors
     
    C:\Users\Jared\Desktop\Group Project\TimeRange>

    The timeRange Class:


    C:\Users\Jared\Desktop\Group Project\TimeRange>javac TimeRange.java
    .\Time.java:58: error: ')' expected
            if (( hour <= 24 && hour >= 0) && (min >= 0 && min <= 60){
                                                                     ^
    .\Time.java:69: error: class, interface, or enum expected
            public int getHour(){
                   ^
    .\Time.java:71: error: class, interface, or enum expected
            }
            ^
    .\Time.java:72: error: class, interface, or enum expected
            public void setHour(int hour){
                   ^
    .\Time.java:75: error: class, interface, or enum expected
            }
            ^
    .\Time.java:78: error: class, interface, or enum expected
            public int getMinute(){
                   ^
    .\Time.java:80: error: class, interface, or enum expected
            }
            ^
    .\Time.java:81: error: class, interface, or enum expected
            public void setMinute(int minute){
                   ^
    .\Time.java:84: error: class, interface, or enum expected
            }
            ^
    .\Time.java:86: error: class, interface, or enum expected
            public void setTime(String time){
                   ^
    .\Time.java:88: error: class, interface, or enum expected
            hour = timeq / 100;
            ^
    .\Time.java:89: error: class, interface, or enum expected
            minutes = timeq % 100;
            ^
    .\Time.java:90: error: class, interface, or enum expected
            }
            ^
    .\Time.java:94: error: class, interface, or enum expected
            int newMin = time.getMinute();
            ^
    .\Time.java:95: error: class, interface, or enum expected
            int newTime = (newHour * 60) + newMin;
            ^
    .\Time.java:96: error: class, interface, or enum expected
            int currentTime = (hour * 60) + minute;
            ^
    .\Time.java:97: error: class, interface, or enum expected
            if (currentTime < newTime){
            ^
    .\Time.java:99: error: class, interface, or enum expected
            }
            ^
    .\Time.java:102: error: class, interface, or enum expected
            }
            ^
    .\Time.java:107: error: class, interface, or enum expected
            int newMin = time.getMinute();
            ^
    .\Time.java:108: error: class, interface, or enum expected
            int newTime = (newHour * 60) + newMin;
            ^
    .\Time.java:109: error: class, interface, or enum expected
            int currentTime = (hour * 60) + minute;
            ^
    .\Time.java:110: error: class, interface, or enum expected
            if (currentTime > newTime){
            ^
    .\Time.java:112: error: class, interface, or enum expected
            }
            ^
    .\Time.java:115: error: class, interface, or enum expected
            }
            ^
    .\Time.java:120: error: class, interface, or enum expected
            int newMin = time.getMinute();
            ^
    .\Time.java:121: error: class, interface, or enum expected
            int newTime = (newHour * 60) + newMin;
            ^
    .\Time.java:122: error: class, interface, or enum expected
            int currentTime = (hour * 60) + minute;
            ^
    .\Time.java:123: error: class, interface, or enum expected
            if (currentTime == newTime){
            ^
    .\Time.java:125: error: class, interface, or enum expected
            }
            ^
    .\Time.java:128: error: class, interface, or enum expected
            }
            ^
    .\Time.java:131: error: class, interface, or enum expected
         public String toString(){
                ^
    .\Time.java:133: error: class, interface, or enum expected
            return currentTime;
            ^
    .\Time.java:134: error: class, interface, or enum expected
        }
        ^
    TimeRange.java:20: error: bad operand types for binary operator '>'
            if (startTime > endTime){
                          ^
      first type:  Time
      second type: Time
    TimeRange.java:43: error: cannot find symbol
            int endHour = endTime.getHour();
                                 ^
      symbol:   method getHour()
      location: variable endTime of type Time
    TimeRange.java:44: error: cannot find symbol
            int endMin = endTime.getMinute();
                                ^
      symbol:   method getMinute()
      location: variable endTime of type Time
    TimeRange.java:45: error: cannot find symbol
            int startHour = startTime.getHour();
                                     ^
      symbol:   method getHour()
      location: variable startTime of type Time
    TimeRange.java:46: error: cannot find symbol
            int startMin = startTime.getMin();
                                    ^
      symbol:   method getMin()
      location: variable startTime of type Time
    TimeRange.java:55: error: cannot find symbol
            int endHour = endTime.getHour();
                                 ^
      symbol:   method getHour()
      location: variable endTime of type Time
    TimeRange.java:56: error: cannot find symbol
            int endMin = endTime.getMinute();
                                ^
      symbol:   method getMinute()
      location: variable endTime of type Time
    TimeRange.java:57: error: cannot find symbol
            int startHour = startTime.getHour();
                                     ^
      symbol:   method getHour()
      location: variable startTime of type Time
    TimeRange.java:58: error: cannot find symbol
            int startMin = startTime.getMin();
                                    ^
      symbol:   method getMin()
      location: variable startTime of type Time
    TimeRange.java:61: error: cannot find symbol
            int timeHour = time.getHour();
                               ^
      symbol:   method getHour()
      location: variable time of type Time
    TimeRange.java:62: error: cannot find symbol
            int timeMin = time.getMinute();
                              ^
      symbol:   method getMinute()
      location: variable time of type Time
    TimeRange.java:65: error: bad operand types for binary operator '<='
            if (time <= endTime && timec >= startTime){
                     ^
      first type:  Time
      second type: int
    TimeRange.java:96: error: cannot find symbol
            int endHour = endTime.getHour();
                                 ^
      symbol:   method getHour()
      location: variable endTime of type Time
    TimeRange.java:97: error: cannot find symbol
            int endMin = endTime.getMinute();
                                ^
      symbol:   method getMinute()
      location: variable endTime of type Time
    TimeRange.java:98: error: cannot find symbol
            int startHour = startTime.getHour();
                                     ^
      symbol:   method getHour()
      location: variable startTime of type Time
    TimeRange.java:99: error: cannot find symbol
            int startMin = startTime.getMin();
                                    ^
      symbol:   method getMin()
      location: variable startTime of type Time
    TimeRange.java:100: error: cannot find symbol
            String timeRange = "" + startHour + startMin + " - " + endhour + endMin;
     
                                                                   ^
      symbol:   variable endhour
      location: class TimeRange
    .\Time.java:53: error: cannot find symbol
            minutes = timeq % 100;
            ^
      symbol:   variable minutes
      location: class Time
    .\Time.java:58: error: cannot find symbol
            if (( hour <= 24 && hour >= 0) && (min >= 0 && min <= 60){
                                               ^
      symbol:   variable min
      location: class Time
    .\Time.java:58: error: cannot find symbol
            if (( hour <= 24 && hour >= 0) && (min >= 0 && min <= 60){
                                                           ^
      symbol:   variable min
      location: class Time
    54 errors
     
    C:\Users\Jared\Desktop\Group Project\TimeRange>

    The TestTimeRange:


    C:\Users\Jared\Desktop\Group Project\TimeRange>javac TesttimeRange.java
    TesttimeRange.java:1: error: package junit.framework does not exist
    import junit.framework.*;
    ^
    TesttimeRange.java:3: error: cannot find symbol
    public class TestTimeRange extends TestCase {
                                       ^
      symbol: class TestCase
    .\Time.java:58: error: ')' expected
            if (( hour <= 24 && hour >= 0) && (min >= 0 && min <= 60){
                                                                     ^
    .\Time.java:69: error: class, interface, or enum expected
            public int getHour(){
                   ^
    .\Time.java:71: error: class, interface, or enum expected
            }
            ^
    .\Time.java:72: error: class, interface, or enum expected
            public void setHour(int hour){
                   ^
    .\Time.java:75: error: class, interface, or enum expected
            }
            ^
    .\Time.java:78: error: class, interface, or enum expected
            public int getMinute(){
                   ^
    .\Time.java:80: error: class, interface, or enum expected
            }
            ^
    .\Time.java:81: error: class, interface, or enum expected
            public void setMinute(int minute){
                   ^
    .\Time.java:84: error: class, interface, or enum expected
            }
            ^
    .\Time.java:86: error: class, interface, or enum expected
            public void setTime(String time){
                   ^
    .\Time.java:88: error: class, interface, or enum expected
            hour = timeq / 100;
            ^
    .\Time.java:89: error: class, interface, or enum expected
            minutes = timeq % 100;
            ^
    .\Time.java:90: error: class, interface, or enum expected
            }
            ^
    .\Time.java:94: error: class, interface, or enum expected
            int newMin = time.getMinute();
            ^
    .\Time.java:95: error: class, interface, or enum expected
            int newTime = (newHour * 60) + newMin;
            ^
    .\Time.java:96: error: class, interface, or enum expected
            int currentTime = (hour * 60) + minute;
            ^
    .\Time.java:97: error: class, interface, or enum expected
            if (currentTime < newTime){
            ^
    .\Time.java:99: error: class, interface, or enum expected
            }
            ^
    .\Time.java:102: error: class, interface, or enum expected
            }
            ^
    .\Time.java:107: error: class, interface, or enum expected
            int newMin = time.getMinute();
            ^
    .\Time.java:108: error: class, interface, or enum expected
            int newTime = (newHour * 60) + newMin;
            ^
    .\Time.java:109: error: class, interface, or enum expected
            int currentTime = (hour * 60) + minute;
            ^
    .\Time.java:110: error: class, interface, or enum expected
            if (currentTime > newTime){
            ^
    .\Time.java:112: error: class, interface, or enum expected
            }
            ^
    .\Time.java:115: error: class, interface, or enum expected
            }
            ^
    .\Time.java:120: error: class, interface, or enum expected
            int newMin = time.getMinute();
            ^
    .\Time.java:121: error: class, interface, or enum expected
            int newTime = (newHour * 60) + newMin;
            ^
    .\Time.java:122: error: class, interface, or enum expected
            int currentTime = (hour * 60) + minute;
            ^
    .\Time.java:123: error: class, interface, or enum expected
            if (currentTime == newTime){
            ^
    .\Time.java:125: error: class, interface, or enum expected
            }
            ^
    .\Time.java:128: error: class, interface, or enum expected
            }
            ^
    .\Time.java:131: error: class, interface, or enum expected
         public String toString(){
                ^
    .\Time.java:133: error: class, interface, or enum expected
            return currentTime;
            ^
    .\Time.java:134: error: class, interface, or enum expected
        }
        ^
    TesttimeRange.java:14: error: cannot find symbol
            assertEquals("1000", t.getStartTime().toString());
            ^
      symbol:   method assertEquals(String,String)
      location: class TestTimeRange
    TesttimeRange.java:15: error: cannot find symbol
            assertEquals("1130", t.getEndTime().toString());
            ^
      symbol:   method assertEquals(String,String)
      location: class TestTimeRange
    TesttimeRange.java:16: error: cannot find symbol
            assertEquals("1100", u.getStartTime().toString());
            ^
      symbol:   method assertEquals(String,String)
      location: class TestTimeRange
    TesttimeRange.java:17: error: cannot find symbol
            assertEquals("1400", u.getEndTime().toString());
            ^
      symbol:   method assertEquals(String,String)
      location: class TestTimeRange
    TesttimeRange.java:20: error: cannot find symbol
            assertEquals(90, t.getDuration());
            ^
      symbol:   method assertEquals(int,int)
      location: class TestTimeRange
    TesttimeRange.java:21: error: cannot find symbol
            assertEquals(180, u.getDuration());
            ^
      symbol:   method assertEquals(int,int)
      location: class TestTimeRange
    TesttimeRange.java:24: error: cannot find symbol
            assertTrue(t.contains(new Time("1100")));
            ^
      symbol:   method assertTrue(boolean)
      location: class TestTimeRange
    TesttimeRange.java:25: error: cannot find symbol
            assertTrue(t.contains(new Time("1000")));
            ^
      symbol:   method assertTrue(boolean)
      location: class TestTimeRange
    TesttimeRange.java:26: error: cannot find symbol
            assertTrue(!t.contains(new Time("0959")));
            ^
      symbol:   method assertTrue(boolean)
      location: class TestTimeRange
    TesttimeRange.java:27: error: cannot find symbol
            assertTrue(!t.contains(new Time("1131")));
            ^
      symbol:   method assertTrue(boolean)
      location: class TestTimeRange
    TesttimeRange.java:30: error: cannot find symbol
            assertTrue(t.overlaps(u));
            ^
      symbol:   method assertTrue(boolean)
      location: class TestTimeRange
    TesttimeRange.java:31: error: cannot find symbol
            assertTrue(!t.overlaps(new TimeRange(new Time("1400"), new Time("1500"))
    ));
            ^
      symbol:   method assertTrue(boolean)
      location: class TestTimeRange
    .\TimeRange.java:20: error: bad operand types for binary operator '>'
            if (startTime > endTime){
                          ^
      first type:  Time
      second type: Time
    .\TimeRange.java:43: error: cannot find symbol
            int endHour = endTime.getHour();
                                 ^
      symbol:   method getHour()
      location: variable endTime of type Time
    .\TimeRange.java:44: error: cannot find symbol
            int endMin = endTime.getMinute();
                                ^
      symbol:   method getMinute()
      location: variable endTime of type Time
    .\TimeRange.java:45: error: cannot find symbol
            int startHour = startTime.getHour();
                                     ^
      symbol:   method getHour()
      location: variable startTime of type Time
    .\TimeRange.java:46: error: cannot find symbol
            int startMin = startTime.getMin();
                                    ^
      symbol:   method getMin()
      location: variable startTime of type Time
    .\TimeRange.java:55: error: cannot find symbol
            int endHour = endTime.getHour();
                                 ^
      symbol:   method getHour()
      location: variable endTime of type Time
    .\TimeRange.java:56: error: cannot find symbol
            int endMin = endTime.getMinute();
                                ^
      symbol:   method getMinute()
      location: variable endTime of type Time
    .\TimeRange.java:57: error: cannot find symbol
            int startHour = startTime.getHour();
                                     ^
      symbol:   method getHour()
      location: variable startTime of type Time
    .\TimeRange.java:58: error: cannot find symbol
            int startMin = startTime.getMin();
                                    ^
      symbol:   method getMin()
      location: variable startTime of type Time
    .\TimeRange.java:61: error: cannot find symbol
            int timeHour = time.getHour();
                               ^
      symbol:   method getHour()
      location: variable time of type Time
    .\TimeRange.java:62: error: cannot find symbol
            int timeMin = time.getMinute();
                              ^
      symbol:   method getMinute()
      location: variable time of type Time
    .\TimeRange.java:65: error: bad operand types for binary operator '<='
            if (time <= endTime && timec >= startTime){
                     ^
      first type:  Time
      second type: int
    .\TimeRange.java:96: error: cannot find symbol
            int endHour = endTime.getHour();
                                 ^
      symbol:   method getHour()
      location: variable endTime of type Time
    .\TimeRange.java:97: error: cannot find symbol
            int endMin = endTime.getMinute();
                                ^
      symbol:   method getMinute()
      location: variable endTime of type Time
    .\TimeRange.java:98: error: cannot find symbol
            int startHour = startTime.getHour();
                                     ^
      symbol:   method getHour()
      location: variable startTime of type Time
    .\TimeRange.java:99: error: cannot find symbol
            int startMin = startTime.getMin();
                                    ^
      symbol:   method getMin()
      location: variable startTime of type Time
    .\TimeRange.java:100: error: cannot find symbol
            String timeRange = "" + startHour + startMin + " - " + endhour + endMin;
     
                                                                   ^
      symbol:   variable endhour
      location: class TimeRange
    .\Time.java:53: error: cannot find symbol
            minutes = timeq % 100;
            ^
      symbol:   variable minutes
      location: class Time
    .\Time.java:58: error: cannot find symbol
            if (( hour <= 24 && hour >= 0) && (min >= 0 && min <= 60){
                                               ^
      symbol:   variable min
      location: class Time
    .\Time.java:58: error: cannot find symbol
            if (( hour <= 24 && hour >= 0) && (min >= 0 && min <= 60){
                                                           ^
      symbol:   variable min
      location: class Time
    68 errors
     
    C:\Users\Jared\Desktop\Group Project\TimeRange>


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Could someone explain to me what exactly is messing up?

    error: ')' expected
    That error says what the problem is. The code needs a ) near where the ^ is.

    One big problem I see is that the Time class's code is poorly formatted. There should never be a } directly below another }. That makes it very hard to read and understand the nesting of the logic. Nested statements and blocks need to be indented 3-4 spaces to show the logic.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Member
    Join Date
    Aug 2013
    Posts
    40
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Could someone explain to me what exactly is messing up?

    Yea that was my partner's code... I made that revision and here are the errors I am still getting concerning the Time class:

    C:\Users\Jared\Desktop\Group Project\TimeRange>javac Time.java
    Time.java:69: error: class, interface, or enum expected
    public int getHour(){
    ^
    Time.java:71: error: class, interface, or enum expected
    }
    ^
    Time.java:72: error: class, interface, or enum expected
    public void setHour(int hour){
    ^
    Time.java:75: error: class, interface, or enum expected
    }
    ^
    Time.java:78: error: class, interface, or enum expected
    public int getMinute(){
    ^
    Time.java:80: error: class, interface, or enum expected
    }
    ^
    Time.java:81: error: class, interface, or enum expected
    public void setMinute(int minute){
    ^
    Time.java:84: error: class, interface, or enum expected
    }
    ^
    Time.java:86: error: class, interface, or enum expected
    public void setTime(String time){
    ^
    Time.java:88: error: class, interface, or enum expected
    hour = timeq / 100;
    ^
    Time.java:89: error: class, interface, or enum expected
    minutes = timeq % 100;
    ^
    Time.java:90: error: class, interface, or enum expected
    }
    ^
    Time.java:94: error: class, interface, or enum expected
    int newMin = time.getMinute();
    ^
    Time.java:95: error: class, interface, or enum expected
    int newTime = (newHour * 60) + newMin;
    ^
    Time.java:96: error: class, interface, or enum expected
    int currentTime = (hour * 60) + minute;
    ^
    Time.java:97: error: class, interface, or enum expected
    if (currentTime < newTime){
    ^
    Time.java:99: error: class, interface, or enum expected
    }
    ^
    Time.java:102: error: class, interface, or enum expected
    }
    ^
    Time.java:107: error: class, interface, or enum expected
    int newMin = time.getMinute();
    ^
    Time.java:108: error: class, interface, or enum expected
    int newTime = (newHour * 60) + newMin;
    ^
    Time.java:109: error: class, interface, or enum expected
    int currentTime = (hour * 60) + minute;
    ^
    Time.java:110: error: class, interface, or enum expected
    if (currentTime > newTime){
    ^
    Time.java:112: error: class, interface, or enum expected
    }
    ^
    Time.java:115: error: class, interface, or enum expected
    }
    ^
    Time.java:120: error: class, interface, or enum expected
    int newMin = time.getMinute();
    ^
    Time.java:121: error: class, interface, or enum expected
    int newTime = (newHour * 60) + newMin;
    ^
    Time.java:122: error: class, interface, or enum expected
    int currentTime = (hour * 60) + minute;
    ^
    Time.java:123: error: class, interface, or enum expected
    if (currentTime == newTime){
    ^
    Time.java:125: error: class, interface, or enum expected
    }
    ^
    Time.java:128: error: class, interface, or enum expected
    }
    ^
    Time.java:131: error: class, interface, or enum expected
    public String toString(){
    ^
    Time.java:133: error: class, interface, or enum expected
    return currentTime;
    ^
    Time.java:134: error: class, interface, or enum expected
    }
    ^
    33 errors

    C:\Users\Jared\Desktop\Group Project\TimeRange>

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Could someone explain to me what exactly is messing up?

    Most of those errors are probably due to misplaced code and/or {}s. Properly formatting the code should show where the problem is. When that error is fixed, the list of errors will be much shorter.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Member
    Join Date
    Aug 2013
    Posts
    40
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Could someone explain to me what exactly is messing up?

    okay, I have fixed all of the errors on the Time class, and now just have the following 6 errors for the TimeRange class:

    C:\Users\Jared\Desktop\Group Project\TimeRange>javac TimeRange.java
    TimeRange.java:20: error: bad operand types for binary operator '>'
    if (startTime > endTime){
    ^
    first type: Time
    second type: Time
    TimeRange.java:46: error: cannot find symbol
    int startMin = startTime.getMin();
    ^
    symbol: method getMin()
    location: variable startTime of type Time
    TimeRange.java:58: error: cannot find symbol
    int startMin = startTime.getMin();
    ^
    symbol: method getMin()
    location: variable startTime of type Time
    TimeRange.java:65: error: bad operand types for binary operator '<='
    if (time <= endTime && timec >= startTime){
    ^
    first type: Time
    second type: int
    TimeRange.java:99: error: cannot find symbol
    int startMin = startTime.getMin();
    ^
    symbol: method getMin()
    location: variable startTime of type Time
    TimeRange.java:100: error: cannot find symbol
    String timeRange = "" + startHour + startMin + " - " + endhour + endMin;

    ^
    symbol: variable endhour
    location: class TimeRange
    6 errors

    C:\Users\Jared\Desktop\Group Project\TimeRange>

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Could someone explain to me what exactly is messing up?

    bad operand types for binary operator '>'
    The > operator is for numeric primitive operands. Objects need to use methods to compare their contents.

    cannot find symbol
    The compiler can not find the symbol shown in the error message. Check if the variable/method is defined and spelled correctly.
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Member
    Join Date
    Aug 2013
    Posts
    40
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Could someone explain to me what exactly is messing up?

    Okay, I have fixed all of the errors in the TimeRange class. Now when I try and run the code that the teacher gave us to test our classes I get these errors:

    C:\Users\Jared\Desktop\Group Project\TimeRange>javac TestTimeRange.java
    TestTimeRange.java:1: error: package junit.framework does not exist
    import junit.framework.*;
    ^
    TestTimeRange.java:3: error: cannot find symbol
    public class TestTimeRange extends TestCase {
    ^
    symbol: class TestCase
    TestTimeRange.java:14: error: cannot find symbol
    assertEquals("1000", t.getStartTime().toString());
    ^
    symbol: method assertEquals(String,String)
    location: class TestTimeRange
    TestTimeRange.java:15: error: cannot find symbol
    assertEquals("1130", t.getEndTime().toString());
    ^
    symbol: method assertEquals(String,String)
    location: class TestTimeRange
    TestTimeRange.java:16: error: cannot find symbol
    assertEquals("1100", u.getStartTime().toString());
    ^
    symbol: method assertEquals(String,String)
    location: class TestTimeRange
    TestTimeRange.java:17: error: cannot find symbol
    assertEquals("1400", u.getEndTime().toString());
    ^
    symbol: method assertEquals(String,String)
    location: class TestTimeRange
    TestTimeRange.java:20: error: cannot find symbol
    assertEquals(90, t.getDuration());
    ^
    symbol: method assertEquals(int,int)
    location: class TestTimeRange
    TestTimeRange.java:21: error: cannot find symbol
    assertEquals(180, u.getDuration());
    ^
    symbol: method assertEquals(int,int)
    location: class TestTimeRange
    TestTimeRange.java:24: error: cannot find symbol
    assertTrue(t.contains(new Time("1100")));
    ^
    symbol: method assertTrue(boolean)
    location: class TestTimeRange
    TestTimeRange.java:25: error: cannot find symbol
    assertTrue(t.contains(new Time("1000")));
    ^
    symbol: method assertTrue(boolean)
    location: class TestTimeRange
    TestTimeRange.java:26: error: cannot find symbol
    assertTrue(!t.contains(new Time("0959")));
    ^
    symbol: method assertTrue(boolean)
    location: class TestTimeRange
    TestTimeRange.java:27: error: cannot find symbol
    assertTrue(!t.contains(new Time("1131")));
    ^
    symbol: method assertTrue(boolean)
    location: class TestTimeRange
    TestTimeRange.java:30: error: cannot find symbol
    assertTrue(t.overlaps(u));
    ^
    symbol: method assertTrue(boolean)
    location: class TestTimeRange
    TestTimeRange.java:31: error: cannot find symbol
    assertTrue(!t.overlaps(new TimeRange(new Time("1400"), new Time("1500"))
    ));
    ^
    symbol: method assertTrue(boolean)
    location: class TestTimeRange
    14 errors

    C:\Users\Jared\Desktop\Group Project\TimeRange>

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Could someone explain to me what exactly is messing up?

    package junit.framework does not exist
    Do you have a jar file with that package in it? Add it to the classpath so the compiler can find it.
    When the compiler can find that package, most of the "cannot find symbol" should go away.
    If you don't understand my answer, don't ignore it, ask a question.

  9. #9
    Member
    Join Date
    Aug 2013
    Posts
    40
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Could someone explain to me what exactly is messing up?

    All that I have is the JDK that my teacher installed onto my computer. How do I get the jar file?

  10. #10
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Could someone explain to me what exactly is messing up?

    How do I get the jar file?
    Ask your teacher where the package named in the error message is defined.
    Try asking Google also.
    If you don't understand my answer, don't ignore it, ask a question.

  11. #11
    Member
    Join Date
    Aug 2013
    Posts
    40
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Could someone explain to me what exactly is messing up?

    Thank you! I really appreciate it!

Similar Threads

  1. Just started messing with databases
    By pbj in forum JDBC & Databases
    Replies: 6
    Last Post: July 24th, 2013, 02:20 AM
  2. i need an explain please !
    By keep smiling in forum Java Theory & Questions
    Replies: 3
    Last Post: December 21st, 2011, 11:22 AM
  3. Replies: 1
    Last Post: December 13th, 2010, 05:13 AM
  4. String to Int messing up
    By The_Mexican in forum What's Wrong With My Code?
    Replies: 5
    Last Post: November 28th, 2010, 02:54 PM
  5. can anyone explain this?
    By chronoz13 in forum Java Theory & Questions
    Replies: 4
    Last Post: October 12th, 2009, 02:51 AM