Простой отчетный лист на Java
В прошлом семестре я изучал Java, поэтому решил сделать проект.
Я искал в Google проекты на Java и нашел:
Написать программу, которая принимает от пользователя оценки по двум предметам и выводит на экран Итого, Процент, Наибольший балл, Средний балл и Примечания.
Это было не так сложно, поэтому вот как я это сделал.
Сначала я импортировал эту библиотеку для приема данных от пользователей:
import java.util.Scanner;
Затем я создал файл с именем ‘marks’. Я знаю, что это имя файла не имеет смысла, но это нормально.
Java запускает шаблон:
public class marks {
public static void main(String args[]) {
// Code Here
}
}
Начиная свой код, я определил переменную ‘sc’ для класса Scanner, чтобы было проще получать ввод от пользователя
try (Scanner sc = new Scanner(System.in)) {
// Code Here
}
Я поместил вышеуказанную переменную в ‘try’, потому что Visual Studio выдавала ошибки.
Далее я отобразил в консоли то, что я хочу от них получить:
System.out.println("Enter the marks of 2 subjects (out of 100)");
Затем я попросил пользователя ввести два параметра
System.out.println("Enter the marks of subject 1:");
int sub1 = sc.nextInt();
System.out.println("Enter the marks of subject 2:");
int sub2 = sc.nextInt();
‘sc’ — это имя переменной, которую я объявил выше, а nextInt()
— это функция для приема значений в виде целого числа, которые будут сохранены в переменной ‘sub1’ и ‘sub2’ соответственно.
Итак, наступает важный этап, как вы знаете, вы не можете набрать больше 100 баллов по предмету, неважно, насколько вы гениальны. Поэтому я должен убедиться, что пользователь не сможет сложить числа больше 100.
Это условие гарантирует, что введенное значение меньше или равно 100.
if (sub1 <= 100 && sub2 <= 100) {
// This code will be executed if the condition is true
} else{
// This code will be executed if the condition if false
}
Отлично! Все меры приняты, пользователь также не может ввести никакое другое значение, кроме числа, если он попытается это сделать, то получит ошибку.
Теперь время для реального кода:
int total = sub1 + sub2;
System.out.println("Total = " + total);
Это сложит два значения и выведет Итого.
Этот код найдет процент, просто возьмите общую сумму, разделите ее на 200 (потому что есть 2 предмета, поэтому общая оценка будет 200), затем умножьте ее на 100. Все просто.
Примечание: ‘float’ используется потому, что ответ может быть десятичным, и он также умножается на ‘float’, чтобы преобразовать его в тип данных float. Как преобразовать Integer в Float.
float percent = (float) total / 200 * 100;
System.out.println("Percentage = " + percent);
Затем простой оператор if-else для получения наибольшего числа:
if (sub1 > sub2) {
System.out.println("Highest marks scored is " + sub1);
} else {
System.out.println("Highest marks scored is " + sub2);
}
Чтобы найти среднее значение, просто возьмите общее число и разделите его на 2:
float avg = (float) total / 2;
System.out.println("Average is " + avg);
Затем снова if-else для отображения примечаний. Если оценка равна 50 или меньше, то появится надпись «Вам нужно много работать!». Если оценка больше 80 или равна и меньше 90, то отобразится «Хорошие оценки», если больше 90, то отобразится «Отлично». Довольно просто.
if (percent <= 50) {
System.out.println("Remarks: You need to work hard!");
} else if (percent >= 80 && percent <= 90) {
System.out.println("Remarks: Good Marks :)");
} else if (percent >= 90) {
System.out.println("Remarks: Excellent");
} else {
System.out.println("Remarks: Good");
}
Вот так я его и сделал. Было очень весело. Кстати, спасибо, что посетили и прочитали 🙂
Исходный код:
import java.util.Scanner;
public class marks {
public static void main(String args[]) {
try (Scanner sc = new Scanner(System.in)) {
System.out.println("Enter the marks of 2 subjects (out of 100)");
System.out.println("Enter the marks of subject 1:");
int sub1 = sc.nextInt();
System.out.println("Enter the marks of subject 2:");
int sub2 = sc.nextInt();
if (sub1 <= 100 && sub2 <= 100) {
// Total
int total = sub1 + sub2;
System.out.println("Total = " + total);
// Percentage
float percent = (float) total / 200 * 100;
System.out.println("Percentage = " + percent);
// Highest Marks
if (sub1 > sub2) {
System.out.println("Highest marks scored is " + sub1);
} else {
System.out.println("Highest marks scored is " + sub2);
}
// Average
float avg = (float) total / 2;
System.out.println("Average is " + avg);
// Remarks
if (percent <= 50) {
System.out.println("Remarks: You need to work hard!");
} else if (percent >= 80 && percent <= 90) {
System.out.println("Remarks: Good Marks :)");
} else if (percent >= 90) {
System.out.println("Remarks: Excellent");
} else {
System.out.println("Remarks: Good");
}
} else {
System.out.println("Values are Greator!");
}
}
}
}
Выход:
Ух ты, здорово! Я смог сделать это, но это выглядит немного просто, давайте добавим некоторые сложные вещи.
Напишите программу, которая будет принимать от пользователя оценки по 15 предметам и выводить Итого, Процент, Наивысший балл, Средний балл и Примечания. Она также должна работать, если количество предметов меньше 15.
Хорошо. Выглядит неплохо. Итак, начинаем с форматирования старого кода.
Затем я взял переменную и спросил, сколько всего предметов:
System.out.println("How many subjects do you have? (Maximum 15, minimum 2)");
int sub_count = sc.nextInt();
Простое условие, чтобы убедиться, что минимальное количество предметов должно быть 2:
if (sub_count == 1) {
System.out.println("Atleast 2 subjects required");
}
Аналогично, я сделал условие else, которое будет выполняться, если количество предметов больше 15 или меньше 2 (также для отрицательных целых чисел, например -15, -27):
else {
System.out.println("Error: Number of subjects should not be more than 15 or not less than 0");
}
Я добавил еще 14 условий для различных входов, например, если количество предметов равно 2, будет выполнен этот код:
else if (sub_count == 2) {
System.out.println("Enter the marks of 2 subjects (out of 100)");
System.out.println("Enter the marks of subject 1:");
int sub1 = sc.nextInt();
System.out.println("Enter the marks of subject 2:");
int sub2 = sc.nextInt();
if (sub1 <= 100 && sub2 <= 100) {
// Total
int total = sub1 + sub2;
System.out.println("Total = " + total + "/200");
// Percentage
float percent = (float) total / 200 * 100;
System.out.println("Percentage = " + percent + "%");
// Highest Marks
if (sub1 > sub2) {
System.out.println("Highest marks scored is " + sub1);
} else {
System.out.println("Highest marks scored is " + sub2);
}
// Average
float avg = (float) total / 2;
System.out.println("Average is " + avg);
// Remarks
if (percent <= 50) {
System.out.println("Remarks: You need to work hard!");
} else if (percent >= 80 && percent <= 90) {
System.out.println("Remarks: Good Marks :)");
} else if (percent >= 90) {
System.out.println("Remarks: Excellent");
} else {
System.out.println("Remarks: Good");
}
} else {
System.out.println("Values are Greator!");
}
}
Я повторил тот же код с небольшими изменениями, например, если количество предметов равно 3, я создал еще одну переменную для этого и сохранил в ней значение:
System.out.println("Enter the marks of subject 3");
int sub3 = sc.nextInt();
Я добавил эту переменную в условие, чтобы значение не было больше 100:
if (sub1 <= 100 && sub2 <= 100 && sub3 <= 100) {
// Code
}
Добавил третью переменную:
int total = sub1 + sub2 + sub3;
System.out.println("Total = " + total + "/300");
То же самое в процентах:
float percent = (float) total / 300 * 100;
System.out.println("Percentage = " + percent + "%");
А для самых высоких оценок сначала я сравнил оценки по первым двум предметам и добавил большее значение к другой переменной, затем сравнил большее из двух с оценкой по третьему предмету:
int max1 = Math.max(sub1, sub2);
System.out.println("Highest Marks = " + Math.max(max1, sub3));
То же самое со средним значением:
float avg = (float) total / 3;
System.out.println("Average is " + avg);
Больше ничего не изменилось, самое важное в высших оценках, если количество предметов равно 4, то вот как будет выглядеть код высших оценок:
int max1 = Math.max(sub1, sub2);
int max2 = Math.max(max1, sub3);
System.out.println("Highest Marks = " + Math.max(max2, sub4));
Сравнил первые 2, сохранил больший в переменную, сравнил переменную с предметом 3, сохранил больший в max2
и сравнил с четвертым предметом. Посмотрите этот вопрос на stackoverflow, чтобы узнать больше: https://stackoverflow.com/questions/4982210/find-the-max-of-3-numbers-in-java-with-different-data-types.
Вот как выглядит код, если общее количество субъектов равно 15:
else if (sub_count == 15) {
System.out.println("Enter the marks of 10 subjects (out of 100)");
System.out.println("Enter the marks of subject 1:");
int sub1 = sc.nextInt();
System.out.println("Enter the marks of subject 2:");
int sub2 = sc.nextInt();
System.out.println("Enter the marks of subject 3");
int sub3 = sc.nextInt();
System.out.println("Enter the marks of subject 4");
int sub4 = sc.nextInt();
System.out.println("Enter the marks of subject 5");
int sub5 = sc.nextInt();
System.out.println("Enter the marks of subject 6");
int sub6 = sc.nextInt();
System.out.println("Enter the marks of subject 7");
int sub7 = sc.nextInt();
System.out.println("Enter the marks of subject 8");
int sub8 = sc.nextInt();
System.out.println("Enter the marks of subject 9");
int sub9 = sc.nextInt();
System.out.println("Enter the marks of subject 10");
int sub10 = sc.nextInt();
System.out.println("Enter the marks of subject 11");
int sub11 = sc.nextInt();
System.out.println("Enter the marks of subject 12");
int sub12 = sc.nextInt();
System.out.println("Enter the marks of subject 13");
int sub13 = sc.nextInt();
System.out.println("Enter the marks of subject 14");
int sub14 = sc.nextInt();
System.out.println("Enter the marks of subject 15");
int sub15 = sc.nextInt();
if (sub1 <= 100 && sub2 <= 100 && sub3 <= 100 && sub4 <= 100 && sub5 <= 100 && sub6 <= 100
&& sub7 <= 100 && sub8 <= 100 && sub9 <= 100 && sub10 <= 100 && sub11 <= 100 && sub12 <= 100
&& sub13 <= 100 && sub14 <= 100 && sub15 <= 100) {
// Total
int total = sub1 + sub2 + sub3 + sub4 + sub5 + sub6 + sub7 + sub8 + sub9 + sub10 + sub11 + sub12
- sub13 + sub14 + sub15;
System.out.println("Total = " + total + "/1500");
// Percentage
float percent = (float) total / 1500 * 100;
System.out.println("Percentage = " + percent + "%");
// Highest Marks
int max1 = Math.max(sub1, sub2);
int max2 = Math.max(max1, sub3);
int max3 = Math.max(max2, sub4);
int max4 = Math.max(max3, sub5);
int max5 = Math.max(max4, sub6);
int max6 = Math.max(max5, sub7);
int max7 = Math.max(max6, sub8);
int max8 = Math.max(max7, sub9);
int max9 = Math.max(max8, sub10);
int max10 = Math.max(max9, sub11);
int max11 = Math.max(max10, sub12);
int max12 = Math.max(max11, sub13);
int max13 = Math.max(max12, sub14);
System.out.println("Highest Marks = " + Math.max(max13, sub15));
// Average
float avg = (float) total / 15;
System.out.println("Average is " + avg);
// Remarks
if (percent <= 50) {
System.out.println("Remarks: You need to work hard!");
} else if (percent >= 80 && percent <= 90) {
System.out.println("Remarks: Good Marks :)");
} else if (percent >= 90) {
System.out.println("Remarks: Excellent");
} else {
System.out.println("Remarks: Good");
}
} else {
System.out.println("Values are Greator!");
}
}
Исходный код для 15 предметов
import java.util.Scanner;
public class marks {
public static void main(String args[]) {
try (Scanner sc = new Scanner(System.in)) {
System.out.println("How many subjects do you have? (Maximum 15, minimum 2)");
int sub_count = sc.nextInt();
if (sub_count == 1) {
System.out.println("Atleast 2 subjects required");
}
else if (sub_count == 2) {
System.out.println("Enter the marks of 2 subjects (out of 100)");
System.out.println("Enter the marks of subject 1:");
int sub1 = sc.nextInt();
System.out.println("Enter the marks of subject 2:");
int sub2 = sc.nextInt();
if (sub1 <= 100 && sub2 <= 100) {
// Total
int total = sub1 + sub2;
System.out.println("Total = " + total + "/200");
// Percentage
float percent = (float) total / 200 * 100;
System.out.println("Percentage = " + percent + "%");
// Highest Marks
if (sub1 > sub2) {
System.out.println("Highest marks scored is " + sub1);
} else {
System.out.println("Highest marks scored is " + sub2);
}
// Average
float avg = (float) total / 2;
System.out.println("Average is " + avg);
// Remarks
if (percent <= 50) {
System.out.println("Remarks: You need to work hard!");
} else if (percent >= 80 && percent <= 90) {
System.out.println("Remarks: Good Marks :)");
} else if (percent >= 90) {
System.out.println("Remarks: Excellent");
} else {
System.out.println("Remarks: Good");
}
} else {
System.out.println("Values are Greator!");
}
}
// 3 Subjects
else if (sub_count == 3) {
System.out.println("Enter the marks of 3 subjects (out of 100)");
System.out.println("Enter the marks of subject 1:");
int sub1 = sc.nextInt();
System.out.println("Enter the marks of subject 2:");
int sub2 = sc.nextInt();
System.out.println("Enter the marks of subject 3");
int sub3 = sc.nextInt();
if (sub1 <= 100 && sub2 <= 100 && sub3 <= 100) {
// Total
int total = sub1 + sub2 + sub3;
System.out.println("Total = " + total + "/300");
// Percentage
float percent = (float) total / 300 * 100;
System.out.println("Percentage = " + percent + "%");
// Highest Marks
int max1 = Math.max(sub1, sub2);
System.out.println("Highest Marks = " + Math.max(max1, sub3));
// Average
float avg = (float) total / 3;
System.out.println("Average is " + avg);
// Remarks
if (percent <= 50) {
System.out.println("Remarks: You need to work hard!");
} else if (percent >= 80 && percent <= 90) {
System.out.println("Remarks: Good Marks :)");
} else if (percent >= 90) {
System.out.println("Remarks: Excellent");
} else {
System.out.println("Remarks: Good");
}
} else {
System.out.println("Values are Greator!");
}
}
// 4 Subjects
else if (sub_count == 4) {
System.out.println("Enter the marks of 4 subjects (out of 100)");
System.out.println("Enter the marks of subject 1:");
int sub1 = sc.nextInt();
System.out.println("Enter the marks of subject 2:");
int sub2 = sc.nextInt();
System.out.println("Enter the marks of subject 3");
int sub3 = sc.nextInt();
System.out.println("Enter the marks of subject 4");
int sub4 = sc.nextInt();
if (sub1 <= 100 && sub2 <= 100 && sub3 <= 100 && sub4 <= 100) {
// Total
int total = sub1 + sub2 + sub3 + sub4;
System.out.println("Total = " + total + "/400");
// Percentage
float percent = (float) total / 400 * 100;
System.out.println("Percentage = " + percent + "%");
// Highest Marks
int max1 = Math.max(sub1, sub2);
int max2 = Math.max(max1, sub3);
System.out.println("Highest Marks = " + Math.max(max2, sub4));
// Average
float avg = (float) total / 4;
System.out.println("Average is " + avg);
// Remarks
if (percent <= 50) {
System.out.println("Remarks: You need to work hard!");
} else if (percent >= 80 && percent <= 90) {
System.out.println("Remarks: Good Marks :)");
} else if (percent >= 90) {
System.out.println("Remarks: Excellent");
} else {
System.out.println("Remarks: Good");
}
} else {
System.out.println("Values are Greator!");
}
// Subject 5
} else if (sub_count == 5) {
System.out.println("Enter the marks of 5 subjects (out of 100)");
System.out.println("Enter the marks of subject 1:");
int sub1 = sc.nextInt();
System.out.println("Enter the marks of subject 2:");
int sub2 = sc.nextInt();
System.out.println("Enter the marks of subject 3");
int sub3 = sc.nextInt();
System.out.println("Enter the marks of subject 4");
int sub4 = sc.nextInt();
System.out.println("Enter the marks of subject 5");
int sub5 = sc.nextInt();
if (sub1 <= 100 && sub2 <= 100 && sub3 <= 100 && sub4 <= 100 && sub5 <= 100) {
// Total
int total = sub1 + sub2 + sub3 + sub4 + sub5;
System.out.println("Total = " + total + "/500");
// Percentage
float percent = (float) total / 500 * 100;
System.out.println("Percentage = " + percent + "%");
// Highest Marks
int max1 = Math.max(sub1, sub2);
int max2 = Math.max(max1, sub3);
int max3 = Math.max(max2, sub4);
System.out.println("Highest Marks = " + Math.max(max3, sub5));
// Average
float avg = (float) total / 5;
System.out.println("Average is " + avg);
// Remarks
if (percent <= 50) {
System.out.println("Remarks: You need to work hard!");
} else if (percent >= 80 && percent <= 90) {
System.out.println("Remarks: Good Marks :)");
} else if (percent >= 90) {
System.out.println("Remarks: Excellent");
} else {
System.out.println("Remarks: Good");
}
} else {
System.out.println("Values are Greator!");
}
// Subject 6
} else if (sub_count == 6) {
System.out.println("Enter the marks of 6 subjects (out of 100)");
System.out.println("Enter the marks of subject 1:");
int sub1 = sc.nextInt();
System.out.println("Enter the marks of subject 2:");
int sub2 = sc.nextInt();
System.out.println("Enter the marks of subject 3");
int sub3 = sc.nextInt();
System.out.println("Enter the marks of subject 4");
int sub4 = sc.nextInt();
System.out.println("Enter the marks of subject 5");
int sub5 = sc.nextInt();
System.out.println("Enter the marks of subject 6");
int sub6 = sc.nextInt();
if (sub1 <= 100 && sub2 <= 100 && sub3 <= 100 && sub4 <= 100 && sub5 <= 100 && sub6 <= 100) {
// Total
int total = sub1 + sub2 + sub3 + sub4 + sub5 + sub6;
System.out.println("Total = " + total + "/600");
// Percentage
float percent = (float) total / 600 * 100;
System.out.println("Percentage = " + percent + "%");
// Highest Marks
int max1 = Math.max(sub1, sub2);
int max2 = Math.max(max1, sub3);
int max3 = Math.max(max2, sub4);
int max4 = Math.max(max3, sub5);
System.out.println("Highest Marks = " + Math.max(max4, sub6));
// Average
float avg = (float) total / 6;
System.out.println("Average is " + avg);
// Remarks
if (percent <= 50) {
System.out.println("Remarks: You need to work hard!");
} else if (percent >= 80 && percent <= 90) {
System.out.println("Remarks: Good Marks :)");
} else if (percent >= 90) {
System.out.println("Remarks: Excellent");
} else {
System.out.println("Remarks: Good");
}
} else {
System.out.println("Values are Greator!");
}
// Subject 7
} else if (sub_count == 7) {
System.out.println("Enter the marks of 7 subjects (out of 100)");
System.out.println("Enter the marks of subject 1:");
int sub1 = sc.nextInt();
System.out.println("Enter the marks of subject 2:");
int sub2 = sc.nextInt();
System.out.println("Enter the marks of subject 3");
int sub3 = sc.nextInt();
System.out.println("Enter the marks of subject 4");
int sub4 = sc.nextInt();
System.out.println("Enter the marks of subject 5");
int sub5 = sc.nextInt();
System.out.println("Enter the marks of subject 6");
int sub6 = sc.nextInt();
System.out.println("Enter the marks of subject 7");
int sub7 = sc.nextInt();
if (sub1 <= 100 && sub2 <= 100 && sub3 <= 100 && sub4 <= 100 && sub5 <= 100 && sub6 <= 100
&& sub7 <= 100) {
// Total
int total = sub1 + sub2 + sub3 + sub4 + sub5 + sub6 + sub7;
System.out.println("Total = " + total + "/700");
// Percentage
float percent = (float) total / 700 * 100;
System.out.println("Percentage = " + percent + "%");
// Highest Marks
int max1 = Math.max(sub1, sub2);
int max2 = Math.max(max1, sub3);
int max3 = Math.max(max2, sub4);
int max4 = Math.max(max3, sub5);
int max5 = Math.max(max4, sub6);
System.out.println("Highest Marks = " + Math.max(max5, sub7));
// Average
float avg = (float) total / 7;
System.out.println("Average is " + avg);
// Remarks
if (percent <= 50) {
System.out.println("Remarks: You need to work hard!");
} else if (percent >= 80 && percent <= 90) {
System.out.println("Remarks: Good Marks :)");
} else if (percent >= 90) {
System.out.println("Remarks: Excellent");
} else {
System.out.println("Remarks: Good");
}
} else {
System.out.println("Values are Greator!");
}
// subject 8
} else if (sub_count == 8) {
System.out.println("Enter the marks of 8 subjects (out of 100)");
System.out.println("Enter the marks of subject 1:");
int sub1 = sc.nextInt();
System.out.println("Enter the marks of subject 2:");
int sub2 = sc.nextInt();
System.out.println("Enter the marks of subject 3");
int sub3 = sc.nextInt();
System.out.println("Enter the marks of subject 4");
int sub4 = sc.nextInt();
System.out.println("Enter the marks of subject 5");
int sub5 = sc.nextInt();
System.out.println("Enter the marks of subject 6");
int sub6 = sc.nextInt();
System.out.println("Enter the marks of subject 7");
int sub7 = sc.nextInt();
System.out.println("Enter the marks of subject 8");
int sub8 = sc.nextInt();
if (sub1 <= 100 && sub2 <= 100 && sub3 <= 100 && sub4 <= 100 && sub5 <= 100 && sub6 <= 100
&& sub7 <= 100 && sub8 <= 100) {
// Total
int total = sub1 + sub2 + sub3 + sub4 + sub5 + sub6 + sub7 + sub8;
System.out.println("Total = " + total + "/800");
// Percentage
float percent = (float) total / 800 * 100;
System.out.println("Percentage = " + percent + "%");
// Highest Marks
int max1 = Math.max(sub1, sub2);
int max2 = Math.max(max1, sub3);
int max3 = Math.max(max2, sub4);
int max4 = Math.max(max3, sub5);
int max5 = Math.max(max4, sub6);
int max6 = Math.max(max5, sub7);
System.out.println("Highest Marks = " + Math.max(max6, sub8));
// Average
float avg = (float) total / 8;
System.out.println("Average is " + avg);
// Remarks
if (percent <= 50) {
System.out.println("Remarks: You need to work hard!");
} else if (percent >= 80 && percent <= 90) {
System.out.println("Remarks: Good Marks :)");
} else if (percent >= 90) {
System.out.println("Remarks: Excellent");
} else {
System.out.println("Remarks: Good");
}
} else {
System.out.println("Values are Greator!");
}
// subject 9
} else if (sub_count == 9) {
System.out.println("Enter the marks of 9 subjects (out of 100)");
System.out.println("Enter the marks of subject 1:");
int sub1 = sc.nextInt();
System.out.println("Enter the marks of subject 2:");
int sub2 = sc.nextInt();
System.out.println("Enter the marks of subject 3");
int sub3 = sc.nextInt();
System.out.println("Enter the marks of subject 4");
int sub4 = sc.nextInt();
System.out.println("Enter the marks of subject 5");
int sub5 = sc.nextInt();
System.out.println("Enter the marks of subject 6");
int sub6 = sc.nextInt();
System.out.println("Enter the marks of subject 7");
int sub7 = sc.nextInt();
System.out.println("Enter the marks of subject 8");
int sub8 = sc.nextInt();
System.out.println("Enter the marks of subject 9");
int sub9 = sc.nextInt();
if (sub1 <= 100 && sub2 <= 100 && sub3 <= 100 && sub4 <= 100 && sub5 <= 100 && sub6 <= 100
&& sub7 <= 100 && sub8 <= 100 && sub9 <= 100) {
// Total
int total = sub1 + sub2 + sub3 + sub4 + sub5 + sub6 + sub7 + sub8 + sub9;
System.out.println("Total = " + total + "/900");
// Percentage
float percent = (float) total / 900 * 100;
System.out.println("Percentage = " + percent + "%");
// Highest Marks
int max1 = Math.max(sub1, sub2);
int max2 = Math.max(max1, sub3);
int max3 = Math.max(max2, sub4);
int max4 = Math.max(max3, sub5);
int max5 = Math.max(max4, sub6);
int max6 = Math.max(max5, sub7);
int max7 = Math.max(max6, sub8);
System.out.println("Highest Marks = " + Math.max(max7, sub9));
// Average
float avg = (float) total / 8;
System.out.println("Average is " + avg);
// Remarks
if (percent <= 50) {
System.out.println("Remarks: You need to work hard!");
} else if (percent >= 80 && percent <= 90) {
System.out.println("Remarks: Good Marks :)");
} else if (percent >= 90) {
System.out.println("Remarks: Excellent");
} else {
System.out.println("Remarks: Good");
}
} else {
System.out.println("Values are Greator!");
}
// subject 10
} else if (sub_count == 10) {
System.out.println("Enter the marks of 10 subjects (out of 100)");
System.out.println("Enter the marks of subject 1:");
int sub1 = sc.nextInt();
System.out.println("Enter the marks of subject 2:");
int sub2 = sc.nextInt();
System.out.println("Enter the marks of subject 3");
int sub3 = sc.nextInt();
System.out.println("Enter the marks of subject 4");
int sub4 = sc.nextInt();
System.out.println("Enter the marks of subject 5");
int sub5 = sc.nextInt();
System.out.println("Enter the marks of subject 6");
int sub6 = sc.nextInt();
System.out.println("Enter the marks of subject 7");
int sub7 = sc.nextInt();
System.out.println("Enter the marks of subject 8");
int sub8 = sc.nextInt();
System.out.println("Enter the marks of subject 9");
int sub9 = sc.nextInt();
System.out.println("Enter the marks of subject 10");
int sub10 = sc.nextInt();
if (sub1 <= 100 && sub2 <= 100 && sub3 <= 100 && sub4 <= 100 && sub5 <= 100 && sub6 <= 100
&& sub7 <= 100 && sub8 <= 100 && sub9 <= 100 && sub10 <= 100) {
// Total
int total = sub1 + sub2 + sub3 + sub4 + sub5 + sub6 + sub7 + sub8 + sub9 + sub10;
System.out.println("Total = " + total + "/1000");
// Percentage
float percent = (float) total / 1000 * 100;
System.out.println("Percentage = " + percent + "%");
// Highest Marks
int max1 = Math.max(sub1, sub2);
int max2 = Math.max(max1, sub3);
int max3 = Math.max(max2, sub4);
int max4 = Math.max(max3, sub5);
int max5 = Math.max(max4, sub6);
int max6 = Math.max(max5, sub7);
int max7 = Math.max(max6, sub8);
int max8 = Math.max(max7, sub9);
System.out.println("Highest Marks = " + Math.max(max8, sub10));
// Average
float avg = (float) total / 10;
System.out.println("Average is " + avg);
// Remarks
if (percent <= 50) {
System.out.println("Remarks: You need to work hard!");
} else if (percent >= 80 && percent <= 90) {
System.out.println("Remarks: Good Marks :)");
} else if (percent >= 90) {
System.out.println("Remarks: Excellent");
} else {
System.out.println("Remarks: Good");
}
} else {
System.out.println("Values are Greator!");
}
// subject 11
} else if (sub_count == 11) {
System.out.println("Enter the marks of 10 subjects (out of 100)");
System.out.println("Enter the marks of subject 1:");
int sub1 = sc.nextInt();
System.out.println("Enter the marks of subject 2:");
int sub2 = sc.nextInt();
System.out.println("Enter the marks of subject 3");
int sub3 = sc.nextInt();
System.out.println("Enter the marks of subject 4");
int sub4 = sc.nextInt();
System.out.println("Enter the marks of subject 5");
int sub5 = sc.nextInt();
System.out.println("Enter the marks of subject 6");
int sub6 = sc.nextInt();
System.out.println("Enter the marks of subject 7");
int sub7 = sc.nextInt();
System.out.println("Enter the marks of subject 8");
int sub8 = sc.nextInt();
System.out.println("Enter the marks of subject 9");
int sub9 = sc.nextInt();
System.out.println("Enter the marks of subject 10");
int sub10 = sc.nextInt();
System.out.println("Enter the marks of subject 11");
int sub11 = sc.nextInt();
if (sub1 <= 100 && sub2 <= 100 && sub3 <= 100 && sub4 <= 100 && sub5 <= 100 && sub6 <= 100
&& sub7 <= 100 && sub8 <= 100 && sub9 <= 100 && sub10 <= 100 && sub11 <= 100) {
// Total
int total = sub1 + sub2 + sub3 + sub4 + sub5 + sub6 + sub7 + sub8 + sub9 + sub10 + sub11;
System.out.println("Total = " + total + "/1100");
// Percentage
float percent = (float) total / 1100 * 100;
System.out.println("Percentage = " + percent + "%");
// Highest Marks
int max1 = Math.max(sub1, sub2);
int max2 = Math.max(max1, sub3);
int max3 = Math.max(max2, sub4);
int max4 = Math.max(max3, sub5);
int max5 = Math.max(max4, sub6);
int max6 = Math.max(max5, sub7);
int max7 = Math.max(max6, sub8);
int max8 = Math.max(max7, sub9);
int max9 = Math.max(max8, sub10);
System.out.println("Highest Marks = " + Math.max(max9, sub11));
// Average
float avg = (float) total / 11;
System.out.println("Average is " + avg);
// Remarks
if (percent <= 50) {
System.out.println("Remarks: You need to work hard!");
} else if (percent >= 80 && percent <= 90) {
System.out.println("Remarks: Good Marks :)");
} else if (percent >= 90) {
System.out.println("Remarks: Excellent");
} else {
System.out.println("Remarks: Good");
}
} else {
System.out.println("Values are Greator!");
}
// subject 12
} else if (sub_count == 12) {
System.out.println("Enter the marks of 10 subjects (out of 100)");
System.out.println("Enter the marks of subject 1:");
int sub1 = sc.nextInt();
System.out.println("Enter the marks of subject 2:");
int sub2 = sc.nextInt();
System.out.println("Enter the marks of subject 3");
int sub3 = sc.nextInt();
System.out.println("Enter the marks of subject 4");
int sub4 = sc.nextInt();
System.out.println("Enter the marks of subject 5");
int sub5 = sc.nextInt();
System.out.println("Enter the marks of subject 6");
int sub6 = sc.nextInt();
System.out.println("Enter the marks of subject 7");
int sub7 = sc.nextInt();
System.out.println("Enter the marks of subject 8");
int sub8 = sc.nextInt();
System.out.println("Enter the marks of subject 9");
int sub9 = sc.nextInt();
System.out.println("Enter the marks of subject 10");
int sub10 = sc.nextInt();
System.out.println("Enter the marks of subject 11");
int sub11 = sc.nextInt();
System.out.println("Enter the marks of subject 12");
int sub12 = sc.nextInt();
if (sub1 <= 100 && sub2 <= 100 && sub3 <= 100 && sub4 <= 100 && sub5 <= 100 && sub6 <= 100
&& sub7 <= 100 && sub8 <= 100 && sub9 <= 100 && sub10 <= 100 && sub11 <= 100 && sub12 <= 100) {
// Total
int total = sub1 + sub2 + sub3 + sub4 + sub5 + sub6 + sub7 + sub8 + sub9 + sub10 + sub11 + sub12;
System.out.println("Total = " + total + "/1200");
// Percentage
float percent = (float) total / 1200 * 100;
System.out.println("Percentage = " + percent + "%");
// Highest Marks
int max1 = Math.max(sub1, sub2);
int max2 = Math.max(max1, sub3);
int max3 = Math.max(max2, sub4);
int max4 = Math.max(max3, sub5);
int max5 = Math.max(max4, sub6);
int max6 = Math.max(max5, sub7);
int max7 = Math.max(max6, sub8);
int max8 = Math.max(max7, sub9);
int max9 = Math.max(max8, sub10);
int max10 = Math.max(max9, sub11);
System.out.println("Highest Marks = " + Math.max(max10, sub12));
// Average
float avg = (float) total / 12;
System.out.println("Average is " + avg);
// Remarks
if (percent <= 50) {
System.out.println("Remarks: You need to work hard!");
} else if (percent >= 80 && percent <= 90) {
System.out.println("Remarks: Good Marks :)");
} else if (percent >= 90) {
System.out.println("Remarks: Excellent");
} else {
System.out.println("Remarks: Good");
}
} else {
System.out.println("Values are Greator!");
}
// subject 13
} else if (sub_count == 13) {
System.out.println("Enter the marks of 10 subjects (out of 100)");
System.out.println("Enter the marks of subject 1:");
int sub1 = sc.nextInt();
System.out.println("Enter the marks of subject 2:");
int sub2 = sc.nextInt();
System.out.println("Enter the marks of subject 3");
int sub3 = sc.nextInt();
System.out.println("Enter the marks of subject 4");
int sub4 = sc.nextInt();
System.out.println("Enter the marks of subject 5");
int sub5 = sc.nextInt();
System.out.println("Enter the marks of subject 6");
int sub6 = sc.nextInt();
System.out.println("Enter the marks of subject 7");
int sub7 = sc.nextInt();
System.out.println("Enter the marks of subject 8");
int sub8 = sc.nextInt();
System.out.println("Enter the marks of subject 9");
int sub9 = sc.nextInt();
System.out.println("Enter the marks of subject 10");
int sub10 = sc.nextInt();
System.out.println("Enter the marks of subject 11");
int sub11 = sc.nextInt();
System.out.println("Enter the marks of subject 12");
int sub12 = sc.nextInt();
System.out.println("Enter the marks of subject 13");
int sub13 = sc.nextInt();
if (sub1 <= 100 && sub2 <= 100 && sub3 <= 100 && sub4 <= 100 && sub5 <= 100 && sub6 <= 100
&& sub7 <= 100 && sub8 <= 100 && sub9 <= 100 && sub10 <= 100 && sub11 <= 100 && sub12 <= 100
&& sub13 <= 100) {
// Total
int total = sub1 + sub2 + sub3 + sub4 + sub5 + sub6 + sub7 + sub8 + sub9 + sub10 + sub11 + sub12
- sub13;
System.out.println("Total = " + total + "/1300");
// Percentage
float percent = (float) total / 1300 * 100;
System.out.println("Percentage = " + percent + "%");
// Highest Marks
int max1 = Math.max(sub1, sub2);
int max2 = Math.max(max1, sub3);
int max3 = Math.max(max2, sub4);
int max4 = Math.max(max3, sub5);
int max5 = Math.max(max4, sub6);
int max6 = Math.max(max5, sub7);
int max7 = Math.max(max6, sub8);
int max8 = Math.max(max7, sub9);
int max9 = Math.max(max8, sub10);
int max10 = Math.max(max9, sub11);
int max11 = Math.max(max10, sub12);
System.out.println("Highest Marks = " + Math.max(max11, sub13));
// Average
float avg = (float) total / 13;
System.out.println("Average is " + avg);
// Remarks
if (percent <= 50) {
System.out.println("Remarks: You need to work hard!");
} else if (percent >= 80 && percent <= 90) {
System.out.println("Remarks: Good Marks :)");
} else if (percent >= 90) {
System.out.println("Remarks: Excellent");
} else {
System.out.println("Remarks: Good");
}
} else {
System.out.println("Values are Greator!");
}
// subject 14
} else if (sub_count == 14) {
System.out.println("Enter the marks of 10 subjects (out of 100)");
System.out.println("Enter the marks of subject 1:");
int sub1 = sc.nextInt();
System.out.println("Enter the marks of subject 2:");
int sub2 = sc.nextInt();
System.out.println("Enter the marks of subject 3");
int sub3 = sc.nextInt();
System.out.println("Enter the marks of subject 4");
int sub4 = sc.nextInt();
System.out.println("Enter the marks of subject 5");
int sub5 = sc.nextInt();
System.out.println("Enter the marks of subject 6");
int sub6 = sc.nextInt();
System.out.println("Enter the marks of subject 7");
int sub7 = sc.nextInt();
System.out.println("Enter the marks of subject 8");
int sub8 = sc.nextInt();
System.out.println("Enter the marks of subject 9");
int sub9 = sc.nextInt();
System.out.println("Enter the marks of subject 10");
int sub10 = sc.nextInt();
System.out.println("Enter the marks of subject 11");
int sub11 = sc.nextInt();
System.out.println("Enter the marks of subject 12");
int sub12 = sc.nextInt();
System.out.println("Enter the marks of subject 13");
int sub13 = sc.nextInt();
System.out.println("Enter the marks of subject 14");
int sub14 = sc.nextInt();
if (sub1 <= 100 && sub2 <= 100 && sub3 <= 100 && sub4 <= 100 && sub5 <= 100 && sub6 <= 100
&& sub7 <= 100 && sub8 <= 100 && sub9 <= 100 && sub10 <= 100 && sub11 <= 100 && sub12 <= 100
&& sub13 <= 100 && sub14 <= 100) {
// Total
int total = sub1 + sub2 + sub3 + sub4 + sub5 + sub6 + sub7 + sub8 + sub9 + sub10 + sub11 + sub12
- sub13 + sub14;
System.out.println("Total = " + total + "/1400");
// Percentage
float percent = (float) total / 1400 * 100;
System.out.println("Percentage = " + percent + "%");
// Highest Marks
int max1 = Math.max(sub1, sub2);
int max2 = Math.max(max1, sub3);
int max3 = Math.max(max2, sub4);
int max4 = Math.max(max3, sub5);
int max5 = Math.max(max4, sub6);
int max6 = Math.max(max5, sub7);
int max7 = Math.max(max6, sub8);
int max8 = Math.max(max7, sub9);
int max9 = Math.max(max8, sub10);
int max10 = Math.max(max9, sub11);
int max11 = Math.max(max10, sub12);
int max12 = Math.max(max11, sub13);
System.out.println("Highest Marks = " + Math.max(max12, sub14));
// Average
float avg = (float) total / 14;
System.out.println("Average is " + avg);
// Remarks
if (percent <= 50) {
System.out.println("Remarks: You need to work hard!");
} else if (percent >= 80 && percent <= 90) {
System.out.println("Remarks: Good Marks :)");
} else if (percent >= 90) {
System.out.println("Remarks: Excellent");
} else {
System.out.println("Remarks: Good");
}
} else {
System.out.println("Values are Greator!");
}
// subject 15
} else if (sub_count == 15) {
System.out.println("Enter the marks of 10 subjects (out of 100)");
System.out.println("Enter the marks of subject 1:");
int sub1 = sc.nextInt();
System.out.println("Enter the marks of subject 2:");
int sub2 = sc.nextInt();
System.out.println("Enter the marks of subject 3");
int sub3 = sc.nextInt();
System.out.println("Enter the marks of subject 4");
int sub4 = sc.nextInt();
System.out.println("Enter the marks of subject 5");
int sub5 = sc.nextInt();
System.out.println("Enter the marks of subject 6");
int sub6 = sc.nextInt();
System.out.println("Enter the marks of subject 7");
int sub7 = sc.nextInt();
System.out.println("Enter the marks of subject 8");
int sub8 = sc.nextInt();
System.out.println("Enter the marks of subject 9");
int sub9 = sc.nextInt();
System.out.println("Enter the marks of subject 10");
int sub10 = sc.nextInt();
System.out.println("Enter the marks of subject 11");
int sub11 = sc.nextInt();
System.out.println("Enter the marks of subject 12");
int sub12 = sc.nextInt();
System.out.println("Enter the marks of subject 13");
int sub13 = sc.nextInt();
System.out.println("Enter the marks of subject 14");
int sub14 = sc.nextInt();
System.out.println("Enter the marks of subject 15");
int sub15 = sc.nextInt();
if (sub1 <= 100 && sub2 <= 100 && sub3 <= 100 && sub4 <= 100 && sub5 <= 100 && sub6 <= 100
&& sub7 <= 100 && sub8 <= 100 && sub9 <= 100 && sub10 <= 100 && sub11 <= 100 && sub12 <= 100
&& sub13 <= 100 && sub14 <= 100 && sub15 <= 100) {
// Total
int total = sub1 + sub2 + sub3 + sub4 + sub5 + sub6 + sub7 + sub8 + sub9 + sub10 + sub11 + sub12
- sub13 + sub14 + sub15;
System.out.println("Total = " + total + "/1500");
// Percentage
float percent = (float) total / 1500 * 100;
System.out.println("Percentage = " + percent + "%");
// Highest Marks
int max1 = Math.max(sub1, sub2);
int max2 = Math.max(max1, sub3);
int max3 = Math.max(max2, sub4);
int max4 = Math.max(max3, sub5);
int max5 = Math.max(max4, sub6);
int max6 = Math.max(max5, sub7);
int max7 = Math.max(max6, sub8);
int max8 = Math.max(max7, sub9);
int max9 = Math.max(max8, sub10);
int max10 = Math.max(max9, sub11);
int max11 = Math.max(max10, sub12);
int max12 = Math.max(max11, sub13);
int max13 = Math.max(max12, sub14);
System.out.println("Highest Marks = " + Math.max(max13, sub15));
// Average
float avg = (float) total / 15;
System.out.println("Average is " + avg);
// Remarks
if (percent <= 50) {
System.out.println("Remarks: You need to work hard!");
} else if (percent >= 80 && percent <= 90) {
System.out.println("Remarks: Good Marks :)");
} else if (percent >= 90) {
System.out.println("Remarks: Excellent");
} else {
System.out.println("Remarks: Good");
}
} else {
System.out.println("Values are Greator!");
}
}
else {
System.out.println("Error: Number of subjects should not be more than 15 or not less than 0");
}
// System.out.println("Enter the marks of 2 subjects (out of 100)");
// System.out.println("Enter the marks of subject 1:");
// int sub1 = sc.nextInt();
// System.out.println("Enter the marks of subject 2:");
// int sub2 = sc.nextInt();
// if (sub1 <= 100 && sub2 <= 100) {
// // Total
// int total = sub1 + sub2;
// System.out.println("Total = " + total);
// // Percentage
// float percent = (float) total / 200 * 100;
// System.out.println("Percentage = " + percent);
// // Highest Marks
// if (sub1 > sub2) {
// System.out.println("Highest marks scored is " + sub1);
// } else {
// System.out.println("Highest marks scored is " + sub2);
// }
// // Average
// float avg = (float) total / 2;
// System.out.println("Average is " + avg);
// // Remarks
// if (percent <= 50) {
// System.out.println("Remarks: You need to work hard!");
// } else if (percent >= 80 && percent <= 90) {
// System.out.println("Remarks: Good Marks :)");
// } else if (percent >= 90) {
// System.out.println("Remarks: Excellent");
// } else {
// System.out.println("Remarks: Good");
// }
// } else {
// System.out.println("Values are Greator!");
// }
}
}
}
Вывод 15 предметов
Первоначально опубликовано на: https://mayankvikash.ml/posts/simple-report-card-in-java.html
Посмотреть другие сообщения: https://mayankvikash.ml//posts/
Последние обновления: https://mayankvikash.ml//news/
HTML Sitemap: https://mayankvikash.ml/sitemap.html
Карта сайта: https://mayankvikash.ml/sitemap.xml
Сделано Mayank Vikash