Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
6 views5 pages

My Code

The Java program allows users to store and manage student records, including personal details and grades. Users can view stored records, add new student information, and compute average grades with corresponding remarks. The program handles input validation and limits the number of stored records to 10 students.

Uploaded by

balbinlaurence0
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views5 pages

My Code

The Java program allows users to store and manage student records, including personal details and grades. Users can view stored records, add new student information, and compute average grades with corresponding remarks. The program handles input validation and limits the number of stored records to 10 students.

Uploaded by

balbinlaurence0
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

MY CODE

import java.util.Scanner;

public class Compli3D {

public static void main(String args[]) {

Scanner in = new Scanner(System.in);

//Tatanungin kung Ilang Student ang Ma sstored

System.out.print("How many Student to Stored?: ");

int numstudents = in.nextInt();

// 3D array to store records (it depends to user how many students, 1 row, 9 fields per student)

String[][][] rec = new String[numstudents][1][10]; // Added index for number of subjects

int rep = 0; // Bilang ng estudyanteng na stored

/* rec[i][0][0] // Student ID

rec[i][0][1] Lastname

rec[i][0][2] Firstname

rec[i][0][3] Middlename

rec[i][0][4] Contact Number

rec[i][0][5] Address

rec[i][0][6] Bilang ng Subjects (Number of Subjects)

rec[i][0][7] Average Grade (Computed from subject grades)

rec[i][0][8] Remarks (FAILED, PASSED, VERY GOOD, EXCELLENT */

while (true) {

System.out.println("\nEnter number of Choice:");

System.out.println("1) View Records");

System.out.println("2) Add/Insert");

System.out.println("3) Exit");

System.out.print("Choice: ");

int choice = in.nextInt();

in.nextLine(); // To avoid input issue


switch (choice) {

case 1: // Pakita ang records ng estudyante kung mayroon nang na stored

if (rep == 0) {

System.out.println("\nNO RECORDED!");

} else {

System.out.println("\
n============================================================== STUDENT RECORDS
========================================================");

System.out.printf("%-15s %-15s %-15s %-15s %-20s %-15s %-15s %-15s %-10s\n",

"Student ID", "Lastname", "Firstname", "Middlename", "Contact Number", "Address",


"Subjects", "Average", "Remarks");

for (int i = 0; i < rep; i++) {

double avg = Double.parseDouble(rec[i][0][7]);// Kinukuha ang average ng grades

String remark = rec[i][0][8];

System.out.printf("%-15s %-15s %-15s %-15s %-20s %-15s %-15s %-15s %-10s\n",

rec[i][0][0], rec[i][0][1], rec[i][0][2], rec[i][0][3],

rec[i][0][4], rec[i][0][5], rec[i][0][6], rec[i][0][7], remark);

System.out.println("\
n===============================================================================
========================================================");

break;

case 2: // Paglalagay ng mga Informations

if (rep < 10) {

System.out.println("\nEnter Student Details:");

System.out.print("Enter Student ID: ");

rec[rep][0][0] = in.nextLine();

System.out.print("Enter Lastname: ");

rec[rep][0][1] = in.nextLine();

System.out.print("Enter Firstname: ");


rec[rep][0][2] = in.nextLine();

System.out.print("Enter Middlename: ");

rec[rep][0][3] = in.nextLine();

System.out.print("Enter Contact Number: ");

rec[rep][0][4] = in.nextLine();

System.out.print("Enter Address: ");

rec[rep][0][5] = in.nextLine();

// Tatanungin kung ilang subjects ang mayroon

int numSubjects;

while (true) {

System.out.print("Enter Number of Subjects: ");

if (in.hasNextInt()) {

numSubjects = in.nextInt();

if (numSubjects > 0) {

in.nextLine(); // To avoid input issue

break;

} else {

System.out.println("Invalid number! Please enter a valid number of subjects.");

} else {

System.out.println("Invalid input! Please enter a number.");

in.next(); // Tatanggalin ang maling input

rec[rep][0][6] = String.valueOf(numSubjects); // Store kung gaano kadami ang subjects

// Kukunin ang grades ng bawat subject and to compute to get the average

double totalGrades = 0;

for (int i = 1; i <= numSubjects; i++) {

int grd;

while (true) {

System.out.print("Enter Grade for Subject " + i + " (0-100): ");


if (in.hasNextInt()) {

grd = in.nextInt();

if (grd >= 0 && grd <= 100) {

totalGrades += grd;

in.nextLine(); // To avoid input issue

break;

} else {

System.out.println("Invalid grade! Please enter a number between 0 and 100.");

} else {

System.out.println("Invalid input! Please enter a number.");

in.next(); // Tatanggalin ang maling input

double average = totalGrades / numSubjects;

rec[rep][0][7] = String.format("%.2f", average); // Store kung gaano kadami ang subjects

// It gives remarks batay sa average ng grades

String remark;

if (average < 75) {

remark = "FAILED";

} else if (average <= 90) {

remark = "PASSED";

} else if (average <= 95) {

remark = "VERY GOOD";

} else {

remark = "EXCELLENT";

rec[rep][0][8] = remark; // Store remarks

rep++;
System.out.println("\nRecord added successfully!");

} else {

System.out.println("Record storage is full!");

break;

case 3: //Exit Case

System.out.println("Exiting program...");

in.close();

return;

default:

System.out.println("Invalid choice! Please enter 1, 2, or 3.");

You might also like