Sei sulla pagina 1di 2

import java.util.

Scanner; public class UserInput { public static void main(String[] args) { String name, matric,level,department,subjet; Scanner in = new Scanner(System.in); // Intro to the Programe solution System.out.println("You are Welcome to Sum & Average Solution Packege"); System.out.println("This program is written and designed by "); System.out.println("\t" +"FAGBAMILA ABAYOMI ISRAEL"); System.out.println("A student of University of EDUCATION WINNEBA, GHANA.") ; System.out.println("\t" +"Matric No: 410047054N"); System.out.println(""); System.out.println("Under the supervision of My Lecturer: Mr. Lawal- Java Programming Language"); System.out.println(""); System.out.println(""); System.out.println("\t" + "Brief intro"); System.out.println("\t" +"This program calculate the sum & Average No of 5 Subject"); System.out.println("requiring the Users input of subjects and scores simul tenously"); System.out.println("Numeric data is expected in the scores only to avoid E rror also avoid Space"); System.out.println(""); System.out.println(""); //Give your info System.out.print("Type your Name: "); name = in.next(); System.out.print("Type your Matric No: "); matric = in.next(); System.out.print("What level are you? "); level = in.next(); System.out.print("Type your Department: "); department = in.next(); System.out.println(""); System.out.println(""); System.out.println(" You are required to in put 5 of your Subject " + "and their corresponding scores."); System.out.println(""); // create an array of user's input int i = 5; String Subject[]= new String[i]; int score[] = new int[i]; //Input the subjects as well as the scores System.out.print("Type your 1st Subject: ");

Subject[0] = in.next(); System.out.print("Type the score of your 1st Subject: "); score[0] = in.nextInt(); System.out.print("Type your 2nd Subject: "); Subject[1] = in.next(); System.out.print("Type the score of your 2nd Subject: "); score[1] = in.nextInt(); System.out.print("Type your 3rd Subject: "); Subject[2] = in.next(); System.out.print("Type the score of your 3rd Subject: "); score[2] = in.nextInt(); System.out.print("Type your 4th Subject: "); Subject[3] = in.next(); System.out.print("Type the score of your 4th Subject: "); score[3] = in.nextInt(); System.out.print("Type your 5th Subject: "); Subject[4] = in.next(); System.out.print("Type the score of your 5th Subject: "); score[4] = in.nextInt(); //calculate sum from the array of scores int sum= 0; // Initialize score for (i=0; i<score.length; i++) { sum += score[i]; } // Print out the user info System.out.println(""); // Create a blank line space System.out.println(""); System.out.println("Name: " + name); System.out.println(""); // Create a blank line space System.out.println("Matric No: " + matric); System.out.println(""); // Create a blank line space System.out.println("Department: " + department); System.out.println(""); // Print out the user subject as well as the scores System.out.println("\t" +"Subject" +" " + "Score"); for (int j=0; j<Subject.length;j++) { System.out.println("\t" +Subject[j] +"\t" + "\t" + score[j]); } System.out.println(""); //Print sum of scores System.out.println("Total is " + sum); System.out.println(""); //Print Average System.out.println("Your average score is " + sum/Subject.length); } }

Potrebbero piacerti anche