
protected double r
public Circle(double r){
this.r=r
}
public Circle(){
this.r=10
}
public double area(){
double area=0
double r=this.r
area=3.14*r*r
return area
}
public double perimeter(){
double per=0
double r=this.r
per=3.14*2*r
return per
}
}
public class PlainCircle extends Circle
{
double cX,cY
public PlainCircle(double cX,double cY,double r) {
this.r=r
this.cX=cX
this.cY=cY
}
public PlainCircle() {
this.cX=0
this.cY=0
this.r=10
}
public boolean isInside(double x,double y){
if((x-cX)*(x-cX)+(y-cY)*(y-cY)<=r*r ){
return true
}
else
return false
}
}
//把你的那个表作成test3.txt放到D盘根,跑程序就好了import java.io.BufferedReader
import java.io.FileInputStream
import java.io.InputStreamReader
import java.util.ArrayList
import java.util.Collections
import java.util.Iterator
import java.util.List
public class MyTest3 {
List stuInfoList = new ArrayList()
public MyTest3(){
printResult()
}
public void readFile() {
try {
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream("d:\\test3.txt")))
String line = ""
int i=0
while ((line = br.readLine()) != null) {
if(i++>0){ //略过头上的汉字行
StudentInfo student = new StudentInfo(line.split(" "))
stuInfoList.add(student)
}
}
} catch (Exception e) {
e.printStackTrace()
}
}
class StudentInfo implements Comparable{
public int stuId
public double pings
public double qizhong
public double qimo
public double bishi
public double zhongFeng
public StudentInfo(){}
public StudentInfo(String[] info){
this.stuId = Integer.parseInt(info[0])
this.pings = Integer.parseInt(info[1])
this.qizhong = Integer.parseInt(info[2])
this.qimo = Integer.parseInt(info[3])
this.bishi = Integer.parseInt(info[4])
this.zhongFeng = pings*0.1+qizhong*0.25+qimo*0.15+bishi*0.5
}
public String getPingJunFeng(int size){
return pings/size +" "+qizhong/size+" "+qimo/size+" "+bishi/size+" "+zhongFeng/size
}
public String toString(){
return stuId + " " +pings + " "+qizhong+" "+qimo+" "+bishi+" "+zhongFeng
}
public int compareTo(Object arg0) {
StudentInfo info = (StudentInfo)arg0
return (int)(info.zhongFeng-this.zhongFeng)
}
}
public void printResult(){
readFile()
System.out.println("学号 平时 期中 期末 笔试 总评分")
for(Iterator it=stuInfoList.iterator()it.hasNext()){
System.out.println(it.next())
}
System.out.println("-----------80分以上---------------\r\n学号 总评分")
for(Iterator it=stuInfoList.iterator()it.hasNext()){
StudentInfo info = (StudentInfo)it.next()
if(info.zhongFeng>=80)
System.out.println(info.stuId + " "+info.zhongFeng)
}
System.out.println("-----------没有及格---------------\r\n学号 总评分")
for(Iterator it=stuInfoList.iterator()it.hasNext()){
StudentInfo info = (StudentInfo)it.next()
if(info.zhongFeng<60)
System.out.println(info.stuId + " "+info.zhongFeng)
}
Collections.sort(stuInfoList)
System.out.println("-----------排序之后---------------\r\n学号 平时 期中 期末 笔试 总评分")
for(Iterator it=stuInfoList.iterator()it.hasNext()){
System.out.println(it.next())
}
StudentInfo pinjunfeng = new StudentInfo()
for(Iterator it=stuInfoList.iterator()it.hasNext()){
StudentInfo info = (StudentInfo)it.next()
pinjunfeng.bishi+=info.bishi
pinjunfeng.pings+=info.pings
pinjunfeng.qimo+=info.qimo
pinjunfeng.qizhong+=info.qizhong
pinjunfeng.zhongFeng+=info.zhongFeng
}
System.out.println("-----------平均分---------------\r\n平时 期中 期末 笔试 总评分")
System.out.println(pinjunfeng.getPingJunFeng(stuInfoList.size()))
}
public static void main(String[] args) throws Exception {
new MyTest3()
}
}
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)