2016-11-13 19 views
-2

//これは、これが私のメインドライバあなたは=記号を削除する必要がカプセル化(ユーザー入力)

import java.util.*; 
public class MainDriver{ 

    public static void main(String args[]){ 

     TheInnovator theinnov = new TheInnovator(); 
     Scanner input = new Scanner(System.in); 

     theinnov.setName = (input.nextLine()); 
     theinnov.setAge = (input.nextLine()); 
     theinnov.setDesignation = (input.nextLine()); 
     theinnov.setCourse = (input.nextLine()); 
     theinnov.setYrlvl = (input.nextLine()); 



     System.out.println("Name: " + theinnov.getName()); 
     System.out.println("\nAge: " + theinnov.getAge()); 
     System.out.println("\nDesignation: " + theinnov.getDesignation()); 
     System.out.println("\nCourse: " + theinnov.getCourse()); 
     System.out.println("\nYear Level: " + theinnov.getYrlvl());  

    } 


} 

So my problem is everytime I run the MainDriver.java, it cannot find my setter variables. what's wrong or what's missing in my code? thank you for a quik response! anyway I'm using notepad++ on this because it's a requirement.

+1

これはC# 'theinnov.setName =(input.nextLine())ではない;'のJava上の適切な方法は、 'theinnov.setName(input.nextLine())である。' –

+0

セッターは方法であります値を割り当てることができる変数ではないパラメータを受け取ります。あなたはこのヒントでそれを解決できることを願って:) –

答えて

0

ある

import java.io.*; 
import java.util.*; 

public class TheInnovator{  
    private String name; 
    private String age; 
    private String designation; 
    private String course; 
    private String yrlvl; 

    public TheInnovator(String name, String age, String designation, String course, String yrlvl){ 

     this.name = name; 
     this.age = age; 
     this.designation = designation; 
     this.course = course; 
     this.yrlvl = yrlvl; 

    } 

    public void setName(String name){ 
     this.name = name; 
    } 

    public void setAge(String age){ 
     this.age = age; 
    } 

    public void setDesignation (String designation){ 
     this.designation = designation; 
    } 

    public void setCourse(String couse){ 
     this.course = course; 
    } 

    public void setYrlvl (String yrlvl){ 
     this.yrlvl = yrlvl; 
    } 

    public String getName(){ 
     return name; 
    } 

    public String getAge(){ 
     return age; 
    } 

    public String getDesignation(){ 
     return designation; 
    } 

    public String getCourse(){ 
     return course; 
    } 

    public String getYrlvl(){ 
     return yrlvl; 
    } 

} 

//私のメインクラスです。コンパイラはsetNameがフィールドであり、メソッドではないと考えさせます。

theinnov.setName (input.nextLine());