Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- import java.io.File;
- import java.io.FileNotFoundException;
- import java.io.IOException;
- import java.io.FileWriter;
- /**
- * Assignment #2</p>
- * @author Swattw</p>
- * Student ID: 403620022</p>
- * Description: This program can calculate score.</p>
- * Time Spent: 180 minutes.</p> *
- *
- */
- public class scorecal {
- /**
- * Collect the data and output the resluts.
- * @param args the main program
- * @param i as the length of array
- */
- public static void main(String[] args)
- {
- //
- int a[]=new int[1024];
- //Declare the new array within 1024 numbers for unknown data.
- int i;
- Scanner input =new Scanner(System.in);
- System.out.println("Please enter the scores:");
- for( i = 0; i < 1023; i++)
- {
- int c = input.nextInt();
- if (c==-1)
- {
- // as the request. when the program find "-1" than don't put it in the array and stop collecting numbers.
- break;
- }
- a[i] = c;
- // collect the value of the scores which user inputs.
- }
- input.close();
- int result1 = minScore(a,i);
- // collect the minscore which found in the method.
- int result2 = maxScore(a,i);
- // collect the maxscore which found in the method.
- int result3 = avgScore(a,i);
- // collect the avgscore which calculated in the method.
- int result4 = numOfNinety(a,i);
- // collect the numOfNinety which counted in the method.
- boolean result5 = improve(a,i);
- // collect the boolean value which tested in the method.
- System.out.println("The min score is:"+result1);
- System.out.println("The max score is:"+result2);
- System.out.println("The avg score is:"+result3);
- System.out.println("The number of score 90 is:"+result4);
- if (result5==true )
- {
- System.out.println("Scores improving!");
- }
- if (result5==false)
- {
- System.out.println("Scores NOT improving!");
- }
- }
- /**
- Find the minimal score in the array.
- @param a[] is the value of the array
- @param i is the length of the array
- @return the minScore of the array
- */
- public static int minScore(int a[], int i)
- {
- int minScore=a[0];
- for (int j=1; j<i;j++)
- {
- if (a[j]<minScore)
- {
- minScore = a[j];
- }
- }
- return minScore;
- }
- /**
- Find the maximal score in the array.
- @param a[] is the value of the array
- @param i is the length of the array
- @return the maxScore of the array
- */
- public static int maxScore(int a[], int i)
- {
- int maxScore=a[0];
- for (int j=1; j<i;j++)
- {
- if (a[j]>maxScore)
- {
- maxScore = a[j];
- }
- }
- return maxScore;
- }
- /**
- Calculate the average score in the array.
- @param int is the value of the array
- @param int is the length of the array
- @return the average of the array
- */
- public static int avgScore(int a[], int i)
- {
- int avgScore=a[0];
- int sum=0;
- for (int j=0; j<=i;j++)
- {
- sum+=a[j];
- avgScore = sum/i;
- if (sum%i !=0)
- {
- avgScore ++;
- }
- }
- return avgScore;
- }
- /**
- Find the numbers of score over 90 in the array.
- @param a[] is the value of the array
- @param i is the length of the array
- @return the numOfNinety of the array
- */
- public static int numOfNinety(int a[], int i)
- {
- int numOfNinety = 0 ;
- for (int j=0;j<i;j++)
- if (a[j]>=90)
- {
- numOfNinety++;
- }
- return numOfNinety;
- }
- /**
- Test if the score is improving.
- @param a[] is the value of the array
- @param i is the length of the array
- @return the improve boolean of the array
- */
- public static boolean improve (int a[], int i)
- {
- boolean improve = false;
- for (int j=1;j<i;j++)
- {
- if (a[j-1]<a[j])
- {
- improve = true;
- }
- if (a[j-1]>=a[j])
- {
- improve = false;
- break;
- }
- }
- return improve;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment