Asked by Fed
How to create a two dimensional arrays that stored the score of 3 subjects of 2 semesters, and score will added by users and program should do
- Calculate the average scores of each semester
- The maximum score of each semester
- The mininum score of each semester
- Calculate the average scores of each semester
- The maximum score of each semester
- The mininum score of each semester
Answers
Answered by
Alex
JUST COPY PAST TO ECLIPSE (OR WHATEVER ELSE U USE)
I KNOW THIS WAS POSTED LIKE A WEEK AFTER BUT I DID THIS MOSTLY TO PRACTICE, HOPE IT WAS USEFULL
import java.util.Scanner;
public class Array {
public static void main(String[] args) {
//JUST GETTING SOME INPUT FIRST
System.out.println("E- = 1\nE = 2\nE+ = 3\nD- = 4\nD = 5\nD+ = 6\nC- = 7\nC = 8\nC+ = 9\nB- = 10\nB = 11\nB+ = 12\nA- = 13\nA = 14\nA+ = 15");
Scanner scannerCommand = new Scanner(System.in);
System.out.println("\nPlease entre the First Semester grade of Subject 1 (as a number): ");
int fSemfSub = scannerCommand.nextInt();
System.out.println("\nPlease entre the First Semester grade of Subject 2 (as a number): ");
int fSemsSub = scannerCommand.nextInt();
System.out.println("\nPlease entre the First Semester grade of Subject 3 (as a number): ");
int fSemtSub = scannerCommand.nextInt();
//
System.out.println("\nPlease entre the Second Semester grade of Subject 1 (as a number): ");
int sSemfSub = scannerCommand.nextInt();
System.out.println("\nPlease entre the Second Semester grade of Subject 2 (as a number): ");
int sSemsSub = scannerCommand.nextInt();
System.out.println("\nPlease entre the Second Semester grade of Subject 3 (as a number): ");
int sSemtSub = scannerCommand.nextInt();
//NOW ONTO THE ARRAYS...
int results[][] = {
{0,0,0},
{0,0,0}
};
//Setting the scores to the array...
results[0][0] = fSemfSub;
results[0][1] = fSemsSub;
results[0][2] = fSemtSub;
results[1][0] = sSemfSub;
results[1][1] = sSemsSub;
results[1][2] = sSemtSub;
//Calculating the average scores per semester
int faverageSemOne = (results[0][0] + results[0][1] + results[0][2]);
int faverageSemTwo = (results[1][0] + results[1][1] + results[1][2]);
//Couldn't get the calculation to work on one line so I made it 2
int averageSemOne = faverageSemOne / 3;
int averageSemTwo = faverageSemTwo / 3;
System.out.println("The average score for semester one was " + averageSemOne);
System.out.println("The average score for semester two was " + averageSemTwo);
//Calculating the max and min score in semester one
int min, max;
min = max = results[0][0];
if(results[0][1] <= min){
min = results[0][1];
}
else{
max = results[0][1];
}
if(results[0][2] <= min){
min = results[0][2];
}
else{
if(results[0][2] >= max){
max = results[0][2];
}
}
System.out.println("The maximum score for Semester one was: " + max);
System.out.println("The minimum score for Semester one was: " + min);
//Calculating max and min score for semester two
min = max = results[1][0];
if(results[1][1] <= min){
min = results[1][1];
}
else{
max = results[1][1];
}
if(results[1][2] <= min){
min = results[1][2];
}
else{
if(results[1][2] >= max){
max = results[1][2];
}
}
System.out.println("The maximum score for Semester two was: " + max);
System.out.println("The minimum score for Semester two was: " + min);
}
}
I KNOW THIS WAS POSTED LIKE A WEEK AFTER BUT I DID THIS MOSTLY TO PRACTICE, HOPE IT WAS USEFULL
import java.util.Scanner;
public class Array {
public static void main(String[] args) {
//JUST GETTING SOME INPUT FIRST
System.out.println("E- = 1\nE = 2\nE+ = 3\nD- = 4\nD = 5\nD+ = 6\nC- = 7\nC = 8\nC+ = 9\nB- = 10\nB = 11\nB+ = 12\nA- = 13\nA = 14\nA+ = 15");
Scanner scannerCommand = new Scanner(System.in);
System.out.println("\nPlease entre the First Semester grade of Subject 1 (as a number): ");
int fSemfSub = scannerCommand.nextInt();
System.out.println("\nPlease entre the First Semester grade of Subject 2 (as a number): ");
int fSemsSub = scannerCommand.nextInt();
System.out.println("\nPlease entre the First Semester grade of Subject 3 (as a number): ");
int fSemtSub = scannerCommand.nextInt();
//
System.out.println("\nPlease entre the Second Semester grade of Subject 1 (as a number): ");
int sSemfSub = scannerCommand.nextInt();
System.out.println("\nPlease entre the Second Semester grade of Subject 2 (as a number): ");
int sSemsSub = scannerCommand.nextInt();
System.out.println("\nPlease entre the Second Semester grade of Subject 3 (as a number): ");
int sSemtSub = scannerCommand.nextInt();
//NOW ONTO THE ARRAYS...
int results[][] = {
{0,0,0},
{0,0,0}
};
//Setting the scores to the array...
results[0][0] = fSemfSub;
results[0][1] = fSemsSub;
results[0][2] = fSemtSub;
results[1][0] = sSemfSub;
results[1][1] = sSemsSub;
results[1][2] = sSemtSub;
//Calculating the average scores per semester
int faverageSemOne = (results[0][0] + results[0][1] + results[0][2]);
int faverageSemTwo = (results[1][0] + results[1][1] + results[1][2]);
//Couldn't get the calculation to work on one line so I made it 2
int averageSemOne = faverageSemOne / 3;
int averageSemTwo = faverageSemTwo / 3;
System.out.println("The average score for semester one was " + averageSemOne);
System.out.println("The average score for semester two was " + averageSemTwo);
//Calculating the max and min score in semester one
int min, max;
min = max = results[0][0];
if(results[0][1] <= min){
min = results[0][1];
}
else{
max = results[0][1];
}
if(results[0][2] <= min){
min = results[0][2];
}
else{
if(results[0][2] >= max){
max = results[0][2];
}
}
System.out.println("The maximum score for Semester one was: " + max);
System.out.println("The minimum score for Semester one was: " + min);
//Calculating max and min score for semester two
min = max = results[1][0];
if(results[1][1] <= min){
min = results[1][1];
}
else{
max = results[1][1];
}
if(results[1][2] <= min){
min = results[1][2];
}
else{
if(results[1][2] >= max){
max = results[1][2];
}
}
System.out.println("The maximum score for Semester two was: " + max);
System.out.println("The minimum score for Semester two was: " + min);
}
}
Answered by
Alex
Oh and ull need to format it, i don't think it will be formatted from here.
There are no AI answers yet. The ability to request AI answers is coming soon!
Submit Your Answer
We prioritize human answers over AI answers.
If you are human, and you can answer this question, please submit your answer.