2017-07-17 5 views
-3

このプログラムでは、エラーsymbol not foundが発生しました。私の問題を解決してください。私はすべての行をチェックしているが、すべてが正しいことがわかった。コンパイラはec.setName = input.next();行にこのエラーを表示します。だから誰かが私にこれを解決するのを助けてください。カプセル化プログラムに関連するエラーが発生しました

ここに私のコード:

import java.util.Scanner; 
    class Encapsul 
    { 
    private String name; 
    private int roll_no; 
    private float marks; 
    private double total; 
    private String school; 

    public String getName() { 
    return name; 
    } 
    public int getRoll_no() { 
    return roll_no; 
    } 
    public float getMarks(){ 
    return marks; 
    } 
    public double getTotal(){ 
     return total; 
    } 
    public String getSchool(){ 
     return school; 
    } 

    public void setName(String newName) { 
     name = newName; 
    } 

    public void setRoll_no(int newRoll_no) { 
     roll_no = newRoll_no; 
    } 

    public void setMarks(float newMarks) { 
     marks = newMarks; 
    } 

    public void setTotal(double newTotal) { 
     total = newTotal; 
    } 

    public void setSchool(String newSchool) { 
     school = newSchool; 
    } 

} 


class Test{ 
    public static void main(String args[]){ 
     Scanner input = new Scanner(System.in); 

    Encapsul c = new Encapsul(); 
    System.out.println("please enter the Name"); 
    c.setName = input.next(); 

    System.out.println("please enter the roll_no"); 
    c.setRoll_no = input.nextInt(); 

    System.out.println("please enter the marks"); 
    c.setMarks = input.nextFloat(); 

    System.out.println("please enter the total"); 
    c.setTotal = input.nextDouble(); 

    System.out.println("please enter the school"); 
    c.setSchool = input.next(); 

    System.out.println("Name :"+ c.getName()); 
    System.out.println("Roll no :"+ c.getRoll_no()); 
    System.out.println("Marks :"+ c.getMarks()); 
    System.out.println("Total :"+ c.getTotal()); 
    System.out.println("School :"+ c.getSchool()); 
    } 
} 
+1

'setName'はメソッドです。フィールドではありません。 – Ivar

+1

@Ivar **フィールド** – sudo

+0

どうすればいいですか –

答えて

0

setName()などがmethod秒、ないfield秒です。

//... 
System.out.println("please enter the Name"); 
c.setName(input.next()); 

System.out.println("please enter the roll_no"); 
c.setRoll_no(input.nextInt()); 

System.out.println("please enter the marks"); 
c.setMarks(input.nextFloat()); 

System.out.println("please enter the total"); 
c.setTotal(input.nextDouble()); 

System.out.println("please enter the school"); 
c.setSchool(input.next()); 
//... 
関連する問題