📄 list.java
字号:
import java.util.*;
import java.io.*;
public class List{
static int check = 0;
static char S=' ';
static double ave;
static double sum;
final static int numOfS=5;
public static void main(String[] args)throws IOException{
student[] stlist=new student[numOfS];
if (args.length != 1) {
System.out.println("To run enter: java List <1st letter of name>");
System.exit(0);
}
stlist[0]=new student("Petros",762945,3,8.2,9.2);
stlist[1]=new student("Iasonas",78365,2,9.5,9.0);
stlist[2]=new student("Andreas",8383,3,6.7,9.0);
stlist[3]=new student("Maria",63654,1,6.7,9.0);
stlist[4]=new student("Leontios",6363,3,6.5,9.0);
FileOutputStream sub = new FileOutputStream("list.txt");
PrintWriter out = new PrintWriter(sub);
if (Character.isLowerCase(args[0].charAt(0))) S=Character.toUpperCase(args[0].charAt(0));
else S= args[0].charAt(0);
for (int i=0; i<numOfS;i++){
sum = sum + stlist[i].gettotalgpa();
Print(stlist[i],out);
if (i==numOfS-1){
ave = sum / numOfS;
out.println();
out.println("Total Average: "+numOfS);
out.println ("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^");
out.println("Student with Total Average higher than average and they are in 3 years and first character is: "+S+" are : ");
out.println ("==========================================================================================================");
}
}
for (int j=0; j<numOfS;j++){
if (stlist[j].gettotalgpa()>numOfS && stlist[j].getyears()==3 && stlist[j].getname().charAt(0)==S){
Print(stlist[j],out);
check = 1;
}
}
if (check == 0 ) out.println("Students not found ");
out.close();
System.out.println("Names is this text file:(list.txt)");
}
static void Print (student P,PrintWriter o){
o.println("Name:"+P.getname());
o.println("Id:"+P.getid());
o.println("Year:"+P.getyears());
o.println("Gpa:"+P.getgpa());
o.println("Total Gpa:"+P.gettotalgpa());
o.println ("_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -