list.java

来自「to find a student and class」· Java 代码 · 共 77 行

JAVA
77
字号
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 + =
减小字号Ctrl + -
显示快捷键?