Mark calculating system
package twelfth;
import java.util.InputMismatchException;
import java.util.Scanner;
public class TwelfthMark {
static String School = "Good Hope Higher secondary school";
String name;
int marks[] = new int[6];
public void getName(Scanner sc) {
while (true) {
System.out.println("Enter the student name");
name = sc.nextLine();
if (!name.isBlank()) {
break;
}
System.out.println("\"Name cannot be empty\"");
}
}
public void printScore(double sum) {
System.out.println("Total mark scored " + sum);
System.out.printf("Average :%.2f\n", (sum / 6));
double percentage = (sum / 600) * 100.0;
System.out.printf("Percentage: %.2f%%", percentage);
}
public static void main(String[] args) {
String group1[] = { "Biology", "English", "Tamil", "Maths", "Physics", "Chemistry" };
String group2[] = { "Computer Science", "English", "Tamil", "Maths", "Physics", "Chemistry" };
String group3[] = { "Accountancy", "English", "Tamil", "Business Studies", "Computer Science/Math",
"Economics" };
TwelfthMark twelfth = new TwelfthMark();
Scanner sc = new Scanner(System.in);
twelfth.getName(sc);
System.out.println("Enter the group name-a.1st Group b.2nd Group c.3rd Group");
String group = sc.nextLine();
double sum = 0;
switch (group.toLowerCase()) {
case "1st Group", "a", "1" -> {
try {
for (int i = 0; i <= 5; i++) {
System.out.println("Enter the mark of " + group1[i]);
twelfth.marks[i] = sc.nextInt();
sum = sum + twelfth.marks[i];
}
twelfth.printScore(sum);
} catch (InputMismatchException e) {
System.out.println("\"Enter only numbers\"");
}
}
case "2nd Group", "b", "2" -> {
try {
for (int i = 0; i <= 5; i++) {
System.out.println("Enter the mark of " + group2[i]);
twelfth.marks[i] = sc.nextInt();
sum = sum + twelfth.marks[i];
}
twelfth.printScore(sum);
} catch (InputMismatchException e) {
System.out.println("Enter only numbers");
}
}
case "3rd Group", "c", "3" -> {
try {
for (int i = 0; i <= 5; i++) {
System.out.println("Enter the mark of " + group3[i]);
twelfth.marks[i] = sc.nextInt();
sum = sum + twelfth.marks[i];
}
twelfth.printScore(sum);
} catch (InputMismatchException e) {
System.out.println("Enter only numbers");
}
}
default -> System.out.println("Enter valid group ");
}
sc.close();
}
}
Top comments (0)