anastasia_petr
4 years ago
1 changed files with 0 additions and 65 deletions
@ -1,65 +0,0 @@ |
|||||
|
|
||||
package standarinputIO; |
|
||||
import java.io.BufferedReader; |
|
||||
import java.io.IOException; |
|
||||
import java.io.InputStreamReader; |
|
||||
import java.util.ArrayList; |
|
||||
|
|
||||
/** |
|
||||
* |
|
||||
* @author anasf |
|
||||
*/ |
|
||||
public class StandardInputIO { |
|
||||
|
|
||||
final static String endstr="000000"; //this variable ends the process |
|
||||
static String AM="[0-9]{6}"; |
|
||||
static float average=0; |
|
||||
static ArrayList<String> students = new ArrayList<String>(); |
|
||||
static int count=0; |
|
||||
static String str; |
|
||||
static boolean flag=true; |
|
||||
static int size=0; |
|
||||
static String temp; |
|
||||
static String[] data; |
|
||||
|
|
||||
public static void main(String[] args) throws IOException { |
|
||||
System.out.println("Give students ID and the grades in this way.Spacifically 'AM course1 grade1 course2 grade2... and press ENTER'"); |
|
||||
System.out.println("To end the process type-> 000000 and press ENTER"); |
|
||||
BufferedReader input = new BufferedReader(new InputStreamReader(System.in)); |
|
||||
|
|
||||
// Reading data using readLine |
|
||||
while(flag) { |
|
||||
str=input.readLine(); |
|
||||
if(!str.startsWith(endstr)) { |
|
||||
students.add(str); |
|
||||
size++; |
|
||||
} |
|
||||
else { |
|
||||
flag=false; |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
System.out.println("The process of reading students' data finished"); |
|
||||
System.out.println("The calculation of average will start!"); |
|
||||
|
|
||||
for(int i=0;i<size;i++) { |
|
||||
temp=students.get(i); |
|
||||
data=temp.split("[ \t]"); |
|
||||
|
|
||||
for(int j=2;j<data.length;j=j+2) |
|
||||
{ |
|
||||
// calculate the average |
|
||||
average=average+Float.parseFloat(data[j]); |
|
||||
count++; |
|
||||
} |
|
||||
average=average/count; |
|
||||
System.out.println("Average of student "+data[0]+": "+average); |
|
||||
average=0; |
|
||||
count=0; |
|
||||
|
|
||||
} |
|
||||
|
|
||||
System.out.println("Reading of grades was completed successfully!"); |
|
||||
} |
|
||||
|
|
||||
} |
|
Loading…
Reference in new issue