大家好,又见面了,我是你们的朋友全栈君。
学生类
import java.util.Scanner;
public class Student {
String name = "张三";
int age = 16;
String grade = "三年二班" ;
String fancy = "打篮球 唱歌 读书 冒险";
public void introduce(){
System.out.println("-----------------------------------------------------");
System.out.println("姓名:" + name + "\n年龄:" + age + "\n班级:" + grade);
System.out.println("兴趣爱好:" + fancy);
}
public void init(){
Scanner sc = new Scanner(System.in);
System.out.print("请输入姓名:");
name = sc.nextLine();
System.out.print("请输入年龄:");
age = sc.nextInt();
System.out.print("请输入班级:");
grade = sc.next();
System.out.print("请输入兴趣爱好:");
fancy = sc.next();
}
public static void main(String[] args){
Student student = new Student();
student.init();
student.introduce();
}
}
教师类,输出教师相关信息
import java.util.Scanner;
public class Teacher {
String name = "李四";
int age = 10;
String major = "计算机视觉" ;
String course = "计算机网络 操作系统 数据结构 数据库";
public void introduce(){
System.out.println("-----------------------------------------------------");
System.out.println("姓名:" + name + "\n教龄:" + age + "年\n专业方向:" + major);
System.out.println("教授课程:" + course);
}
public void init(){
Scanner sc = new Scanner(System.in);
System.out.print("请输入姓名:");
name = sc.nextLine();
System.out.print("请输入教龄:");
age = sc.nextInt();
System.out.print("请输入专业方向:");
major = sc.next();
System.out.print("请输入教授课程:");
course = sc.next();
}
public static void main(String[] args){
Teacher teacher = new Teacher();
//teacher.init();
teacher.introduce();
}
}
发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/156721.html原文链接:https://javaforall.cn
【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛
【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...