2014-03-27 78 views
-2

有人可以幫我嗎?這僅僅是一個測試,但是當我運行我的程序我得到一個找不到符號錯誤,它指向的名字我進入想這是一個變量java程序讀取我的字符串輸入作爲變量

import java.util.*; 
import java.io.*; 
public class Employee{ 
    public String emp_name; 
    public int emp_id; 
    public double emp_salary; 
    public int emp_phone; 

    public Employee(String add_newName, int add_newID, double add_newSalary, int add_newPhone){ 
     emp_name = add_newName; 
     emp_id = add_newID; 
     emp_salary = add_newSalary; 
     emp_phone = add_newPhone; 
    } 

    public Employee(int add_ID, int add_Phone){ 
     emp_name = "NULL"; 
     emp_id = add_ID; 
     emp_salary = 0; 
     emp_phone = add_Phone; 
    } 

    public double increaseSalary(double increase_amt){ 
     return emp_salary += increase_amt; 
    } 

    public String getName(){ 
     return emp_name; 
    } 

    public String toString(){ 
     return "Name of employee: " + emp_name + ",, " + "ID number of employee: " + emp_id + ",, " + "Employee salary: " + emp_salary + ",, " + "Employee phone: " + emp_phone; 
    } 

    public static void process(){ 
     Employee employee1 = new Employee(noel, 101, 5050.50, 1230987); 
     Employee employee2 = new Employee(102, 5672389); 
     System.out.println("Employee Information: " + employee1.toString()); 
    } 

    public static void main(String args[]){ 
     process(); 
    } 
} 

的錯誤是在這個過程中方法,在那裏你看到諾埃爾,Java說找不到符號...幫助?

+1

'新員工( 「諾埃爾」,101,5050.50,1230987);' –

+1

當您將其聲明爲一個String變量時,請嘗試使用「noel」 –

回答

3

變化noel"noel"

Employee employee1 = new Employee("noel", 101, 5050.50, 1230987); 

沒有"" java會認爲它作爲變量

2

語法String S IN Java是:

"Some String" 

注意雙引號。要解決你的問題,你將不得不寫"noel"

Employee employee1 = new Employee("noel", 101, 5050.50, 1230987); 
1

你是路過諾埃爾

Employee employee1 = new Employee(noel, 101, 5050.50, 1230987); 
創造員工

它應該是String作爲:

Employee employee1 = new Employee("noel", 101, 5050.50, 1230987); 
相關問題