JAVA创建一个具体的学生类
5个回答
展开全部
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方法就行
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方法就行
展开全部
//学生类
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());
}
}
}
希望对你有帮助!
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());
}
}
}
希望对你有帮助!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
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());
}
}
//名字
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());
}
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
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;
}
}
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;
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2012-06-13
展开全部
class Zhangfei
{
String name;
int age=20;
int value=100;
}
{
String name;
int age=20;
int value=100;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询