JAVA创建一个具体的学生类

创建一个叫张飞的学生类
该类中拥有名字,年龄,成绩三个成员变量
年龄是20,成绩是100
谢谢了

public class student {
private String name;
private int age;
private double value;
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 double getValue() {
return value;
}
public void setValue(double value) {
this.value = value;
}
}
要用的时候直接new 一个,然后设置值,比如
student s=new student();
s.setName("张飞");
s.setValue(100);
s.setAge(20);
需要得到值的时候就是get方法就行
温馨提示:内容为网友见解,仅供参考
第1个回答  2012-06-12
//学生类
public class Student{
private String stu_id;
private String stu_name;
private float math;
private float chinese;
private float computer;

public void setStu_id(String stu_id){
this.stu_id=stu_id;
}
public String getStu_id(){
return stu_id;
}
public void setStu_name(String stu_name){
this.stu_name=stu_name;
}
public String getStu_name(){
return stu_name;
}
public void setMath(float math){
this.math=math;
}
public float getMath(){
return math;
}
public void setChinese(float chinese){
this.chinese=chinese;
}
public float getChinese(){
return chinese;
}
public void setComputer(float computer){
this.computer=computer;
}
public float getComputer(){
return computer;
}

}

//主方法的类
public class Start{
public static void main(String[] args){
Student stu1=new Student();
stu1.setStu_id("No1");
stu1.setStu_name("张三");
stu1.setMath(89.5f);
stu1.setChinese(70f);
stu1.setComputer(98f);
Student stu2=new Student();
stu2.setStu_id("No2");
stu2.setStu_name("李四");
stu2.setMath(79.5f);
stu2.setChinese(90f);
stu2.setComputer(68f);
float stu1Sum = stu1.getMath()+stu1.getChinese()+stu1.getComputer();
float stu2Sum = stu2.getMath()+stu2.getChinese()+stu2.getComputer();
if(stu1Sum > stu2Sum){
System.out.println ("总分最高分为:"+stu1Sum);
System.out.println ("学号:"+stu1.getStu_id());
System.out.println ("姓名:"+stu1.getStu_name());
System.out.println ("数学:"+stu1.getMath());
System.out.println ("语文:"+stu1.getChinese());
System.out.println ("计算机:"+stu1.getComputer());
}else if(stu1Sum < stu2Sum){
System.out.println ("总分最高分为:"+stu2Sum);
System.out.println ("学号:"+stu2.getStu_id());
System.out.println ("姓名:"+stu2.getStu_name());
System.out.println ("数学:"+stu2.getMath());
System.out.println ("语文:"+stu2.getChinese());
System.out.println ("计算机:"+stu2.getComputer());
}else{
System.out.println ("总分一样高为:"+stu1Sum);
System.out.println ("学号:"+stu1.getStu_id());
System.out.println ("姓名:"+stu1.getStu_name());
System.out.println ("数学:"+stu1.getMath());
System.out.println ("语文:"+stu1.getChinese());
System.out.println ("计算机:"+stu1.getComputer());
System.out.println ("学号:"+stu2.getStu_id());
System.out.println ("姓名:"+stu2.getStu_name());
System.out.println ("数学:"+stu2.getMath());
System.out.println ("语文:"+stu2.getChinese());
System.out.println ("计算机:"+stu2.getComputer());
}
}
}

希望对你有帮助!
第2个回答  2012-06-11
public class ZhangFei {
//名字
String name;
//年龄
int age;
//成绩
double value;

public String getName() {
return "张飞";
}
public int getAge() {
return 20;
}
public double getValue() {
return 100;
}
public static void main(String[] args){
ZhangFei get=new ZhangFei();
System.out.println("名字是: "+get.getName());
System.out.println("年龄为: "+get.getAge());
System.out.println("成绩为: "+get.getValue());
}
}本回答被网友采纳
第3个回答  2012-06-12
package com.sunyard.test;

public class Student {

private int age = 20;
private int score = 100;
private String name;
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public int getScore() {
return score;
}
public void setScore(int score) {
this.score = score;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
第4个回答  2012-06-13
class Zhangfei
{
String name;
int age=20;
int value=100;
}

用java表示学生信息 问题:用java怎么写学生表示?
getNo():获得学号;getName():获得姓名;getSex():获得性别;getAge()获得年龄;getJava():获得Java 课程成绩 (4)根据类Student的定义,创建五个该类的对象,输出每个学生的信息,计算并输出这五个学生Java语言成绩的平均值,以及计算并输出他们Java语言成绩的最大值和最小值。*\/ class...

如何使用java来创建一个学生类?
首先,你需要创建一个学生类来表示学生的信息,例如:public class Student { private String name;private int age;private String gender;private String grade;public Student(String name, int age, String gender, String grade) { this.name = name;this.age = age;this.gender = gender;this.g...

Java程序设计,定义一个表示学生的类Student
public class Student { \/\/定义一个学生类 private int StuNum; \/\/学号 private int Class; \/\/班级 private char Gender; \/\/性别 private int Age; \/\/年龄 public Student(int StuNum, int Class, char Gender, int Age){\/\/构造函数 this.stuNum = StuNum;this.class = Cla...

用JAVA编写一个学生类Student的程序
学生类:public class Student { private String num;\/\/学号 private String name;\/\/姓名 private String sex;\/\/性别 private int age;\/\/年龄 public Student(String num,String name,String sex,int age){ this.num = num;this.name = name;this.sex = sex;this.age = age;} public String ...

用JAVA定义一个学生类Student来表示学生信息,学生类中包含成员有学号...
}public int getWai() {return wai;}public void setWai(int wai) {this.wai = wai;} Java是一种可以撰写跨平台应用程序的面向对象的程序设计语言。Java 技术具有卓越的通用性、高效性、平台移植性和安全性,广泛应用于PC、数据中心、游戏控制台、科学超级计算机、移动电话和互联网,同时拥有全球最...

用java定义学生类(学号、姓名、成绩)。用列表list存放班级学生信息...
import java.util.List;public class Admin { public static void main(String... args) { List data = new ArrayList();Student s0 = new Student();s0.setNo("000");s0.setName("a");s0.setChengji(100.0);data.add(s0);Student s1 = new Student();s1.setNo("001");s1.set...

java定义一个学生类要求学号,姓名,年龄,三个成员变量
class Student{private int STU_NUM;private String STU_NAME;private int STU_AGE;public Student(int NUM,String NAME){this.STU_NAME=NAME;this.STU_NUM=NUM;}public Student(int NUM,String NAME,int AGE){this.STU_NAME=NAME;this.STU_NUM=NUM;this.STU_AGE=AGE;}} ...

在java中编写程序,定义一个学生类
import java.util.ArrayList;import java.util.List;\/ 编写一个Java应用程序,该程序包括3个类:定义一个学生类,Student有姓名,学号,选学的课程列表 定义一个课程类:课程名称,课程分数 (1)初始化一个学生,选择了三门课程,并添加到学生的属性中 (2)实现统计学生的总分功能 1.正确编写2个类(5...

JAVA 定义一个学生类(Student),包含学号、姓名、年龄(7-60岁)三个私 ...
import java.util.Scanner;class Student{ private String num;private int age;private String name;public Student(String b,String a,int c) { num=b;name=a;age=c;} public int reage() { return age;} void shou() { if(age>=7&&age<=60)System.out.println(name+" "+num+" "+...

用java创建一个学生类,包括学号,姓名,成绩,然后构造方法,初始化,输出...
}public String getNumber() {return number;}public void setNumber(String number) {this.number = number;}public int getScore() {return score;}public void setScore(int score) {this.score = score;}public String toString() {return "Name: " + name+ ",Number: " + number+ ",...

相似回答