Professional Documents
Culture Documents
Activity 7 - Padawan & Pahl BSM-CS 2C G2 PDF
Activity 7 - Padawan & Pahl BSM-CS 2C G2 PDF
Activity 7 - Padawan & Pahl BSM-CS 2C G2 PDF
Inside the powerpoint do the Practice Exercise, named it Activity_7. The Activity_7 is
still by pair.
Activity Code:
package activity_7_v2;
import java.io.*; import java.text.DecimalFormat;
public class Activity_7_v2 {
public static void main(String[] args) throws IOException {
/*First, we've prepare all of our variables that we will use on our program*/
/*Next, we've used "do while" loop for the Restriction 1 and 2 for extra feature
of our program, where every time the user will input an integer less than 0
it will notify the user that the entry was invalid and it will loop back
from the start of the program*/
do{
/*Next, we've put the "input statements" inside the "do while" loop alongside
with some "if" statements*/
//Restriction #1
System.out.print("Enter a number of Student/s: ");
//Restriction #2
System.out.print("Enter a number of Subject/s: ");
Subjects = Integer.parseInt(input.readLine());
if(Students > 0 && Subjects > 0){
break;
}
else{
System.out.println("Invalid Entry! Please Try Again.");
System.out.println();
}
}while(!(Students > 0 && Subjects > 0));
/*Afterwards, we've used "for loop", inside of the loop is where the
"input statements" are located. For the condition inside the "for loop"
we've used the user defined inputs for the loop*/
}
System.out.println();
System.out.println("----------------------------------------------------------");
System.out.println();
for(int a = 0; a < Students; a++){
float sum = 0;
System.out.print("Name: ");
Name [a] = input.readLine();
for(int b = 0; b < Subjects; b++){
//Restriction #2
do{
System.out.print("Grade in " +Subject[b] +": ");
Grade [a][b] = Integer.parseInt(input.readLine());
if(Grade[a][b] >= 1 && Grade[a][b] <= 100){
break;
}
else{
System.out.println();
/*For the elements of the Avarage array, we've used the Quotient
of the sum and the Subject, and we also introduce an new variable with
a data type of "float", this is also equal to the quotient of the sum and
subjects, we've used "float" so it can show it's decimal value when
it is printed*/
//Restriction #4
Average [a] = sum/Subjects;
float Av = 0; Av = sum/Subjects;
System.out.println("Average Grade: " +oneDcPt.format(Av));
System.out.println();
}
/*Then, we've used "if statement" for an extra feature where when the user
input a single student, then it will only print the general average of the
single student, this is located at the "else" of the "if statement"*/
//Restriction #5
if (Students != 1){
/*Thereafter, we've used the "for loop" again, in order to access the grades
of the Students using the Two Dimentional array, we've used this type of array
previously above this code at the Grade array, by using two dimentional array
we can access the Grades of different students easily, with the help of
"for loop"*/
//Restriction #6
System.out.println("Grade Chart:"); System.out.println();
System.out.println("Subject Name\t\tNo. of Students who Passed");
System.out.println();
/*By analyzing the code, we can see that we've used the 1st "for loop"
//Restriction #7
System.out.println("Summary Records:"); System.out.println();
Name/s: Date: 3 / 18 / 2020
Padawan, Reggie C.
Pahl, George Christopher A.
Activity Number: 7
Section: BSM – CS – 2C Instructor: Mrs. Robethel Andres
System.out.println("Name\t\t\tSubject\t\t\tGrade\t\t\tRemarks"); System.out.println();
for(int f = 0; f < Students; f++){
for (int s = 0; s < Subjects; s++){