Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > General Discussion > The Lounge > <identifier> expected

Reply
Thread Tools

<identifier> expected

 
 
Keke101 Keke101 is offline
Junior Member
Join Date: Jan 2012
Posts: 1
 
      01-02-2012
Hi all I am taking an intro to programming (Java) class and I am working on an assignment and I keep getting this error. Here is my code and the error I am getting.

// Class Phone represents a telephone object
public class Phone
{
private static String firstname;
private static String lastname;
private static String number;

public Phone()
{
}

public Phone(String firstname1, String lastname1, String number1)
{
firstname = first1;
lastname = last1;
number = number1;
}

public static String getfirstname()
{
return firstname;
}
public void setfirstname(String first1);
{
firstname = first1;
}
public static string getlastname()
{
return lastname;
}
public void setlastname(String last1);
{
lastname = last1;
}
public static String getnumber()
{
return number;
}
public void setnumber(String number1);
{
number = number1;
}
System.out.println("First Name : " + getfirstname()); [error here]
System.out.println("Last Name : " + getlastname()); [error here]
System.out.println("Number : " + getnumber()); [error here]
}
}

File: C:\Documents and Settings\Keke\Desktop\School\Programming\Lab03\Les son3_5\src\Phone.java [line: 43]
Error: C:\Documents and Settings\Keke\Desktop\School\Programming\Lab03\Les son3_5\src\Phone.java:43: <identifier> expected

Thank you in advance to anyone who can help. I would greatly appreciate it.
 
Reply With Quote
 
 
 
 
tuttle64 tuttle64 is offline
Junior Member
Join Date: Feb 2012
Posts: 1
 
      02-25-2012
it seems you are a java beginner. anyway, the main errors are:

1) if you want to assign the arguments of your constructor to the objects fields, the argument names must match the one given in the method. ex.

public Phone(String firstname1, String lastname1, String number1)
{
firstname = firstname1;

2) If you use a constructor to initialize the field variables you don't need any setter methods and you methods doesn't need to be static.

3) The method signature doesn't end with a semicolon. so

public void setfirstname(String first1);
{

will not run, but

public void setfirstname(String first1)
{

is ok.

4) Java is case sensitive, so an identifier getLastName will not be recognized by the compiler if you use getlastname.

5) If you make a call to a method you must specify the object or if the method is static you must specify the class. only getfirstname() will not work.

Here is the code that will compile and run:

Code:
public class Phone {
    private String firstname;
    private String lastname;
    private String number;

    public Phone() {
    }

    public Phone(String firstname1, String lastname1, String number1) {
        firstname = firstname1;
        lastname = lastname1;
        number = number1;
    }

    public String getfirstname() {
        return firstname;
    }

    public String getlastname() {
        return lastname;
    }

    public String getnumber() {
        return number;
    }

    public static void main(String[] args) {
        Phone p1 = new Phone("Albert", "Einstein", "01-11111");
        System.out.println("First Name : " + p1.getfirstname());
        System.out.println("Last Name : " + p1.getlastname());
        System.out.println("Number : " + p1.getnumber());
    }
}
and the output will be:

Quote:
First Name : Albert
Last Name : Einstein
Number : 01-11111
 

Last edited by tuttle64; 02-25-2012 at 10:16 AM..
Reply With Quote
 
 
 
 
sandi7777777 sandi7777777 is offline
Junior Member
Join Date: Oct 2012
Location: Indonesia
Posts: 1
 
      10-11-2012
i get the same error. Could you tell me how to fix it ? I'm an ameteur about this.

class encrypt1 {
public static void main (String[] args) {
String msg = "sasdasdasdasd";
String msg2 = "";
char c ='a';
boolean b = true;
for (int i = 0; i < msg.length(); i++) ;
c = msg.charAt(i);
if (msg.charAt(i) == 'm') {
if (b) {
c = 'a' ;
b = false;
} else {
b = true;
}
}
if (msg.charAt(i) == 'z') {
c = 'i';
}
if (msg.charAt(i) == 'x') {
c = 'e';
}
if (msg.charAt(i) == 'a') {
c = 's';
}
msg2 = msg2 + c ;
}
System.out.println(msg2);
}
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Is this expected IBGP peer behaviour? p47 Cisco 6 01-08-2006 02:52 PM
- Boot image integrity check...Failed (CRC expected 0x00004e9d, not ron Cisco 1 11-10-2005 01:24 AM
ISE:ERROR:Xst:829: Constant Value expected for Generic 'U'? Phil Tomson VHDL 3 02-16-2005 08:54 AM
[News] Jobless Claims Rise More Than Expected TechGeekPro MCSE 0 04-15-2004 03:44 PM
Re: Better than I expected 73171 The Poster Formerly Known as Kline Sphere MCSD 2 01-05-2004 05:41 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57