java声明两个类,一个学生类,一个教师类,并输出相关信息

比如学号,姓名,爱好,身高。最后输出相关信息。用尽量简单的语句,刚学java

第1个回答  推荐于2017-12-16
//没用到访问器(set、get)
public class TestClass {

public static void main(String[] args) {
//创建一个学生对象
Student xiaoming=new Student(2011001,"小明","打篮球、足球、玩游戏","175cm");
//创建一个老师对象
Teacher wanglaoshi=new Teacher("Java","王老师","编程、业余黑客","185cm");
}

}
//学生类
class Student {
//学生的学号,姓名,爱好,身高
int St_Id;
String St_Name,St_Love,St_Stature;
public Student(int id, String name, String love, String stature) {
this.St_Id=id;
this.St_Name=name;
this.St_Love=love;
this.St_Stature=stature;
//自我介绍下:
System.out.println("我是一名学生,我的名字是:"+St_Name
+" 我的学号是:"+St_Id
+" 我身高"+St_Stature
+" 我的爱好有: "+St_Love);
}
}
//教师类
class Teacher{
//教师的学号,姓名,爱好,身高
String T_Name,T_course,T_Love,T_Stature;
public Teacher(String course, String name, String love, String stature) {
this.T_course=course;
this.T_Name=name;
this.T_Love=love;
this.T_Stature=stature;
//自我介绍下:
System.out.println("我是一名学生,我的名字是:"+T_Name
+" 我带你们的课程是:"+T_course
+" 我身高"+T_Stature
+" 我的爱好有: "+T_Love);
}
}本回答被提问者采纳
第2个回答  2011-09-25

package Test;

import java.util.Date;

public class test {

public static void main(String[] args) {
Student stu=new Student();
stu.setName("zhangsan");
stu.setAge(18);
stu.setBirthday(new Date().toString());
System.out.println(stu);
}

}

class Student{
private String name;
private int age;
private String birthday;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getBirthday() {
return birthday;
}
public void setBirthday(String birthday) {
this.birthday = birthday;
}

public String toString(){
return "name="+name+"\tage="+age+"\tbirthday"+birthday;
}

}
第3个回答  2011-09-26
做任务,打扰勿怪
第4个回答  2011-09-24
class student{
int id,age;
int EnglishScore,JavaScore,NetworkScore;
String name,sex;
public student(){
id=0;
age=0;
EnglishScore=JavaScore=NetworkScore=0;
name="null";
sex="female";
}
void setId(int id){
this.id=id;
}
int getId(){
return id;
}
void setAge(int age){
this.age=age;
}
int getAge(){
return age;
}
void setEnglishScore(int score){
EnglishScore=score;
}
int getEnglishScore(){
return EnglishScore;
}
void setJavaScore(int score){
JavaScore=score;
}
int getJavaScore(){
return JavaScore;
}
void setNetworkScore(int score){
NetworkScore=score;
}
int getNetworkScore(){
return NetworkScore;
}
void setName(String name){
this.name=name;
}
String getName(){
return name;
}
void setSex(String sex){
this.sex=sex;
}
String getSex(){
return sex;
}
}

public class TestStudent{
public static void main(String args[]){
student s[]=new student[5];
int ave[]=new int[5];
int high[]=new int[5];
int low[]=new int[5];
for(int i=0;i<s.length;i++){
s[i]=new student();
s[i].setId(i);
s[i].setName("s"+i);
s[i].setAge(i);
s[i].setEnglishScore(i*10);
s[i].setJavaScore(i*11);
s[i].setNetworkScore(i*12);
}
for(int i=0;i<s.length;i++){
ave[i]=s[i].getEnglishScore()+s[i].getNetworkScore()+s[i].getJavaScore();
ave[i]/=3;
high[i]=Math.max(Math.max(s[i].getEnglishScore(),s[i].getJavaScore()),s[i].getNetworkScore());
low[i]=Math.min(Math.min(s[i].getEnglishScore(),s[i].getJavaScore()),s[i].getNetworkScore());
System.out.println("Name:"+s[i].getName());
System.out.println("ave:"+ave[i]);
System.out.println("low:"+low[i]);
System.out.println("high:"+high[i]);
System.out.println();
}

}
}
这是学生的,教师类稍微改改就是了。
第5个回答  2011-09-24
自己写才有意义追问

不是太懂概念,想看一下例子,书上用的都是方法,写得很长,我想看看大家都是怎么写的~~帮个忙哈~

相似回答