Student Class
package week04;
public class Student {
String name;
int stdnum;
String department;
String gender;
Student(String name, int stdnum, String department, String gender){
this.name = name;
this.stdnum = stdnum;
this.department = department;
this.gender = gender;
}
}
Test Class
package week04;
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
System.out.println("이름 : ");
String name = sc.nextLine();
System.out.println("학번 : ");
int stdnum = sc.nextInt();
sc.nextLine();
//int stdnum = Integer.parseInt(sc.nextLine());
System.out.println("학부 : ");
String department = sc.nextLine();
System.out.println("성별 : ");
String gender = sc.nextLine();
Student studentKim = new Student(name, stdnum, department, gender);
System.out.println(studentKim.name);
System.out.println(studentKim.stdnum);
System.out.println(studentKim.department);
System.out.println(studentKim.gender);
}
}