1. Write a java program that calculate the percentage of marks obtained in three subjects (each out of 100) by student A and in four subjects (each out of 100) by student B. Create an abstract class 'Marks' with an abstract method 'getPercentage'. It is inherited by two other classes 'A' and 'B' each having a method with the same name which returns the percentage of the students. The constructor of student A takes the marks in three subjects as its parameters and the constructor of student B takes the marks in four subjects as its parameters. Create an object for each of the two classes and print the percentage of marks for both the students.
Answers
Answer:
// Java program to find Total Average and percentage of Five Subjects
import java.util.Scanner;
public class Total of 5subjects1 {
private static Scanner sc;
public static void main(String[] args)
{
int english, chemistry, computers, physics, maths;
float total, Percentage, Average;
sc = new Scanner(System.in);
System.out.print(" Please Enter the Five Subjects Marks : ");
english = sc.nextInt();
chemistry = sc.nextInt();
computers = sc.nextInt();
physics = sc.nextInt();
maths = sc.nextInt();
total = english + chemistry + computers + physics + maths;
Average = total / 5;
Percentage = (total / 500) * 100;
System.out.println(" Total Marks = " + total);
System.out.println(" Average Marks = " + Average);
System.out.println(" Marks Percentage = " + Percentage);
}
}
Answer:
bhai harsh ke alava app mein sab coding ka C bhi nahi jantey