java学习笔记(十二)

一、程序分析思路:


1:根据要求写出类所包含的属性

2:所有的属性都必须进行封装

3:封装之后的属性通过setter和getter设置和取得

4:如果需要可愿意加入若干构造方法:

5:再根据其他要求添加相应的方法

6:类中的所有方法都不要直接输出,而是交给被调用处输出

二、实例分析


class Student
{
private String stuno;
private String name;
private float math;
private float english;
private float computer;
public Student(String s,String n,float m,float e,float c){
this.setStuno(s);
this.setName(n);
this.setMath(m);
this.setEnglish(e);
this.setComputer(c);
}
public void setStuno(String s){
stuno = s;
}
public void setName(String n){
name = n;
}
public void setMath(float m){
math = m;
}
public void setEnglish(float e){
english = e;
}
public void setComputer(float c){
computer = c;
}
public String getStuno(){
return stuno;
}
public String getName(){
return name;
}
public float getMath(){
return math;
}
public float getEnglish(){
return english;
}
public float getComputer(){
return computer;
}
public float sum(){
return math+english+computer;
}
public float avg(){
return this.sum()/3;
}
public float max(){
float max = math;
max = max > computer?max:computer;
max = max > english?max:english;
return max;
}
public float min(){
float min = math;
min = min < computer?min:computer;
min = min < english?min:english;
return min;
}
}
public class ExampleDemo
{
public static void main(String args[]){
Student stu = null;
stu = new Student("1000","历史",45.0f,67.0f,89.0f);
System.out.println("学生编号"+stu.getStuno());
System.out.println("学生姓名"+stu.getName());
System.out.println("数学成绩"+stu.getMath());
System.out.println("英语编号"+stu.getEnglish());
System.out.println("计算机成绩"+stu.getComputer());
System.out.println("最高分"+stu.max());
System.out.println("最低分"+stu.min());
System.out.println("平均分"+stu.avg());
System.out.println("总分"+stu.sum());


}
}

题目的分析要一点一点积累;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值