User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Java section within the Software Development category of DaniWeb, a massive community of 423,575 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,476 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Java advertiser: Lunarpages Java Web Hosting
Views: 887 | Replies: 2 | Solved
Reply
Join Date: Nov 2007
Posts: 14
Reputation: Java-Newbie is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
Java-Newbie Java-Newbie is offline Offline
Newbie Poster

<identifier> expected error... Help!

  #1  
Mar 1st, 2008
Can anybody tell me why I keep getting this error?

Asig02_Attempt2.java:37: <identifier> expected
public void sincronizarCanal(canal)

Am I mixing a class with a method? This is just a small program that simulates a TV. I'm trying to pass a number (chanel) to a method that tells the user that they are now watching chanel (whatever number I passed)...

import java.util.Scanner;

class Televisor
{
	int	canales,
		volumen,
		canal,
		vol;
			
			
	public Televisor()
	{
		canales = 5;
		volumen = 10;
	}
	
	public void encender()
	{
		System.out.println("Televisor Encendido.");
	}
	
	public void apagar()
	{
		System.out.println("Televisor Apagado. Adios...");
	}
	
	public void sincronizarCanal(canal)
	{
	  System.out.println("El canal ha sido sincronizado al canal" + canal);
	}
	
	public void ajustarVolumen()
	{
	  System.out.println("El volumen ha sido ajustado.");
	}
}

public class Asig02_Attempt2
{
	public static void main(String arguments[]) 
	{ 
	             Scanner input = new Scanner( System.in ); 
	
	             Televisor myTVSet = new Televisor();
	
		myTVSet.encender();
	
		System.out.print("Sincronizar al canal --> ");
		myTVSet.canales = input.nextInt();
		myTVSet.sincronizarCanal(myTVSet.canales);
	
		System.out.print("\n");
	
		System.out.print("Ajustar el volumen a --> ");
		myTVSet.volumen = input.nextInt();
		myTVSet.ajustarVolumen();
	
		myTVSet.apagar();
	}
}
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jan 2008
Posts: 1,747
Reputation: VernonDozier is just really nice VernonDozier is just really nice VernonDozier is just really nice VernonDozier is just really nice VernonDozier is just really nice 
Rep Power: 8
Solved Threads: 217
VernonDozier VernonDozier is offline Offline
Posting Virtuoso

Re: <identifier> expected error... Help!

  #2  
Mar 1st, 2008
You are not telling the compiler what type "canal" is. I am guessing that "canal" is an integer, but you don't specify this:
public void sincronizarCanal(canal)

If canal is an integer, you should change it to this:
public void sincronizarCanal(int canal)

However, this also won't work since you have a data member CALLED "canal". If it is the data member "canal" you are intending here, then don't pass the function anything, like this:
public void sincronizarCanal()

I'm not exactly sure what you are trying to do. It looks like you ARE trying to pass the function something. If so, if it is an integer, which appears to me to be your intent, I would rename it to some other name that is not the name of a data member, and place an "int" in front of that variable name, like this:
public void sincronizarCanal(int someIntegerName)
Reply With Quote  
Join Date: Nov 2007
Posts: 14
Reputation: Java-Newbie is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
Java-Newbie Java-Newbie is offline Offline
Newbie Poster

Re: <identifier> expected error... Help!

  #3  
Mar 1st, 2008
well, now I feel dumb... :-D I should have known that! Thanks a lot!!
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb Java Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the Java Forum

All times are GMT -4. The time now is 7:13 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC