Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner; //importing scanner
- public class itec133_quiz3 { //program begins
- public static void main(String[] args) { //main method begins
- Scanner input = new Scanner (System.in); //scanner declaration
- double [] num = new double [8]; //double array declaration
- for(int i=0; i<num.length; i++) { //for loop being used to populate the array num
- System.out.println("Enter a decimal number: ");
- num[i] = input.nextDouble();
- } //for loop ends
- //output statement showing the smallest value of the array
- System.out.println("The smallest number of the array is: " +getSmallest(num));
- double marks; //variable declaration
- //input statement for the user to enter the student's mark
- System.out.println("Please enter a mark from 0 - 100: ");
- marks = input.nextDouble();
- System.out.println(+getGrade(marks));
- } //main method ends
- //method called getSmallest, takes on the argument which is an array. this method sorts the array in ascending order and returns the smallest value ONLY of the array.
- public static double getSmallest(double [] array) {
- double smallest = 0; //variable declaration
- //for loop 'j' used to go through the array.length elements
- for(int j=0; j<array.length; j++) {
- //for loop 'k' used to sort the array in ascending order
- for(int k=j+1; k<array.length; k++) {
- //if statement to sort the array
- if (array[j] < array[k]) {
- smallest = array[j]; //stores the first element in smallest
- array[j] = array[k]; //replaces array[j] with array[k]
- array[k] = smallest; //puts smallest in array[k]
- } //if statement ends
- } //for loop 'k' ends
- } //for loop 'j' ends
- return smallest; //returns the smallest value when method is called
- } //method getSmallest ends
- //method called getGrade, takes on the double argument mark. this method goes through a series of if statements to assign and return a letter grade to the mark value.
- public static double getGrade(double mark) {
- //if statements to determine the letter grade the mark value should be assigned to
- if(mark >= 90 && mark <= 100) {
- System.out.println("A");
- }
- else
- if(mark >= 85 && mark <= 89) {
- System.out.println("B+");
- }
- else
- if(mark >= 80 && mark <= 85) {
- System.out.println("B");
- }
- else
- if(mark >= 75 && mark <= 80) {
- System.out.println("C+");
- }
- else
- if(mark >= 70 && mark <= 75) {
- System.out.println("C");
- }
- else
- if(mark >= 65 && mark <= 70) {
- System.out.println("D+");
- }
- else
- if(mark >= 60 && mark <= 65) {
- System.out.println("D");
- }
- else
- if(mark < 60) {
- System.out.println("F");
- }
- return mark; //returns the letter grade when method is called
- } //method getGrade ends
- } //program ends
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement