Error Message

I Dont Understand Error, Need Help.

Page 1 of 1

7 Replies - 964 Views - Last Post: 30 November 2007 - 12:20 PM Rate Topic: -----

#1 sudo  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 22-November 07

Error Message

Posted 30 November 2007 - 10:33 AM

 public class ClockDisplay
{
	private NumberDisplay hours;
	private NumberDisplay minutes;
	private String displayString; // simulates the actual display
	// newZone holds an ArrayList that can store Zone objects  
	private ArrayList<Zone> newZone;
	private String Zone;
   
	/**
	 * Constructor for ClockDisplay objects. This constructor 
	 * creates a new clock set at 00:00.
	 */
	public ClockDisplay()
	{
		hours = new NumberDisplay(24);
		minutes = new NumberDisplay(60);
		updateDisplay();
		newZone = new ArrayList<Zone>();
	}

	/**
	 * Constructor for ClockDisplay objects. This constructor
	 * creates a new clock set at the time specified by the 
	 * parameters.
	 */
	public ClockDisplay(int hour, int minute)
	{
		hours = new NumberDisplay(24);
		minutes = new NumberDisplay(60);
		setTime(hour, minute);
		newZone = new ArrayList<Zone>();
	}

	/**
	 * This method should get called once every minute - it makes
	 * the clock display go one minute forward.
	 */
	public void timeTick()
	{
		minutes.increment();
		if(minutes.getValue() == 0) {  // it just rolled over!
			hours.increment();
		}
		updateDisplay();
	}

	/**
	 * Set the time of the display to the specified hour and
	 * minute.
	 */
	public void setTime(int hour, int minute)
	{
		hours.setValue(hour);
		minutes.setValue(minute);
		updateDisplay();
	}

	/**
	 * Return the current time of this display in the format HH:MM.
	 */
	public String getTime()
	{
		return displayString;
	}   
		
		
	   /** 
	 * This if statement is to say that Offset is between -12 and 12, 
	 * and if false display error.
	 */
	public void addZone(String newZoneName, int newOffset)
	{
		if ((newOffset >=-12) && (newOffset<=12)){
		   newZone.add(new Zone (newZoneName, newOffset));
		}
		else {
			System.out.println("Error no time Zone available");
	}
}
	
	public int findZone (String ZoneName)
	{
		int index = 0;
		boolean found = false;
		while (index < newZone.size() && !found); {
		newZone = Zone.get() (index);	}
		if (Zone.getName() = (ZoneName))
		{
			found = true;
		}
		else { index++;
		}
		return index;
	}
} 


Hello Everyone

I keep getting an Error with "findZone" method, the error line is in bold.

I want the method to check if there is a time zone with the same name in the "Arraylist".

How can i do this, because i keep getting an error.

Thank You

Is This A Good Question/Topic? 0
  • +

Replies To: Error Message

#2 Amadeus  Icon User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 248
  • View blog
  • Posts: 13,507
  • Joined: 12-July 02

Re: Error Message

Posted 30 November 2007 - 10:54 AM

What is the exact error you get?
Was This Post Helpful? 0
  • +
  • -

#3 sudo  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 22-November 07

Re: Error Message

Posted 30 November 2007 - 11:01 AM

View PostAmadeus, on 30 Nov, 2007 - 10:54 AM, said:

What is the exact error you get?


Error says "class, interface, or enum expected"
Was This Post Helpful? 0
  • +
  • -

#4 Programmist  Icon User is offline

  • CTO
  • member icon

Reputation: 252
  • View blog
  • Posts: 1,833
  • Joined: 02-January 06

Re: Error Message

Posted 30 November 2007 - 11:07 AM

Check your "{" and "}" (curly braces) pairs. You probably have improperly closed curly braces.
Was This Post Helpful? 0
  • +
  • -

#5 sansclue  Icon User is offline

  • D.I.C Regular

Reputation: 29
  • View blog
  • Posts: 316
  • Joined: 21-November 07

Re: Error Message

Posted 30 November 2007 - 11:17 AM

if (Zone.getName() = (ZoneName))



I suspect you meant to use an equality test there, not an assignment operator
Was This Post Helpful? 0
  • +
  • -

#6 Programmist  Icon User is offline

  • CTO
  • member icon

Reputation: 252
  • View blog
  • Posts: 1,833
  • Joined: 02-January 06

Re: Error Message

Posted 30 November 2007 - 11:34 AM

View PostProgrammist, on 30 Nov, 2007 - 12:07 PM, said:

Check your "{" and "}" (curly braces) pairs. You probably have improperly closed curly braces.


Yeah - on closer inspection, your curly braces are mismatched in at least two places (that I can see without plugging the code into an IDE.)
Was This Post Helpful? 0
  • +
  • -

#7 sudo  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 22-November 07

Re: Error Message

Posted 30 November 2007 - 11:43 AM

public class ClockDisplay
{
	private NumberDisplay hours;
	private NumberDisplay minutes;
	private String displayString; // simulates the actual display
	// newZone holds an ArrayList that can store Zone objects  
	private ArrayList<Zone> newZone;
	private String Zone;
	
	/**
	 * Constructor for ClockDisplay objects. This constructor 
	 * creates a new clock set at 00:00.
	 */
	public ClockDisplay()
	{
		hours = new NumberDisplay(24);
		minutes = new NumberDisplay(60);
		updateDisplay();
		newZone = new ArrayList<Zone>();
	}

	/**
	 * Constructor for ClockDisplay objects. This constructor
	 * creates a new clock set at the time specified by the 
	 * parameters.
	 */
	public ClockDisplay(int hour, int minute)
	{
		hours = new NumberDisplay(24);
		minutes = new NumberDisplay(60);
		setTime(hour, minute);
		newZone = new ArrayList<Zone>();
	}

	/**
	 * This method should get called once every minute - it makes
	 * the clock display go one minute forward.
	 */
	public void timeTick()
	{
		minutes.increment();
		if(minutes.getValue() == 0) {  // it just rolled over!
			hours.increment();
		}
		updateDisplay();
	}

	/**
	 * Set the time of the display to the specified hour and
	 * minute.
	 */
	public void setTime(int hour, int minute)
	{
		hours.setValue(hour);
		minutes.setValue(minute);
		updateDisplay();
	}

	/**
	 * Return the current time of this display in the format HH:MM.
	 */
	public String getTime()
	{
		return displayString;
	}   
		
	/** This is an if statement for printing the Zones
	 * and printing an Error message if there's no zone available.
	 */
	public void printZones(String name, int offset)
	{
		if(newZone.size() >= 0) { 
		System.out.println("Time zones are:");
		System.out.println(name + "(GMT" + offset + ")");
	}
	else
		System.out.println("No time zones available");
	}
	
	/** 
	 * This if statement is to say that Offset is between -12 and 12, 
	 * and if false display error.
	 */
	public void addZone(String newZoneName, int newOffset)
	{
		if ((newOffset >=-12) && (newOffset<=12)){
		   newZone.add(new Zone (newZoneName, newOffset));
		}
		else {
			System.out.println("Error no time zone available");
	}
}
	
	public int findZone (String ZoneName)
	{
		int index = 0;
		boolean found = false;
		while (index < newZone.size() && !found); {
		Zone = newZone.get (index);
	}
		if (Zone.getName() == (ZoneName))
		{
			found = true;
		}
		else { index++;
		}
		return index;
	}
} 



 

/**
	 * Update the internal string that represents the display.
	 */
private void updateDisplay()
	{
		displayString = hours.getDisplayValue() + ":" + 
						minutes.getDisplayValue();
	} 
} 


This method is to update the internal String that represents the display.

I have added this at the end of my previous code, but there is an error.

Error says "class,interface, or enum expected"

Any ideas?
Was This Post Helpful? 0
  • +
  • -

#8 Programmist  Icon User is offline

  • CTO
  • member icon

Reputation: 252
  • View blog
  • Posts: 1,833
  • Joined: 02-January 06

Re: Error Message

Posted 30 November 2007 - 12:20 PM

Ummm....yes, I have an idea. You'll find it in my last two posts.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1