封装(用户输入)

问题描述 投票:-2回答:2

//这是我的主要课程

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;
    }

}

//这是我的主要司机

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.

java encapsulation
2个回答
© www.soinside.com 2019 - 2024. All rights reserved.