[go: up one dir, main page]

0% found this document useful (0 votes)
13 views3 pages

S 14

The document contains Java code to calculate grades of students based on their marks in different subjects. It defines classes to get marks for different years and calculates total and grade. The main method accepts student details and displays their final grade.

Uploaded by

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

S 14

The document contains Java code to calculate grades of students based on their marks in different subjects. It defines classes to get marks for different years and calculates total and grade. The main method accepts student details and displays their final grade.

Uploaded by

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

//*************************************************************************

import java.io.*;

class NumberZeroException extends Exception {


public String toString() {
return ("Number is 0");
}
}

class PrimeNumber {
int a;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

PrimeNumber() {
try {
System.out.print("Enter any integer to check prime: ");
a = Integer.parseInt(br.readLine());
if (a == 0)
throw new NumberZeroException();
else
prime();
} catch (NumberZeroException ex) {
System.out.println(ex);
} catch (IOException ex1) {
System.out.println("Enter proper number");
}
}

public void prime() {


int cnt = 0;
for (int i = 2; i <= a / 2; i++)
if (a % i == 0) {
cnt++;
break;
}
if (cnt == 0)
System.out.println(a + " Number is prime");
else
System.out.println(a + " Number is not prime");
}

public static void main(String args[]) {


PrimeNumber pn = new PrimeNumber();
}
}

//***************************************************************************

package SY;

import java.util.Scanner;

public class SYMarks {


double ComputerTotal, MathsTotal, ElectronicsTotal;
Scanner sc = new Scanner(System.in);
public double sytotal;

public SYMarks(){
System.out.print("Enter Computer total marks: ");
ComputerTotal = sc.nextDouble();
System.out.print("Enter Maths total marks: ");
MathsTotal = sc.nextDouble();
System.out.print("Enter Electronics total marks: ");
ElectronicsTotal = sc.nextDouble();
sytotal = (ComputerTotal + MathsTotal + ElectronicsTotal) / 3;
}

public void display() {


System.out.println("Total SY Computer Science marks: " +
ComputerTotal);
System.out.println("Total SY Maths marks: " + MathsTotal);
System.out.println("Total SY Electronics marks: " + ElectronicsTotal);
}
}

package TY;

import java.util.Scanner;

public class TYMarks {


double Theory, Practicals;
Scanner sc = new Scanner(System.in);
public double tytotal;

public TYMarks(){
System.out.print("Enter theory marks: ");
Theory = sc.nextDouble();
System.out.print("Enter practicals marks: ");
Practicals = sc.nextDouble();
tytotal = (Theory + Practicals)/2;
}

public void display() {


System.out.println("Total TY Theory marks: " + Theory);
System.out.println("Total TY Practical marks: " + Practicals);
}
}

import java.util.Scanner;
import SY.SYMarks;
import TY.TYMarks;

public class Stud {


int rollNumber;
String name;
SYMarks sy;
TYMarks ty;
double total;
char grade;

Stud(int rno, String n){


rollNumber = rno;
name = n;
sy = new SYMarks();
ty = new TYMarks();
this.grade();
}

void display() {
System.out.println("Roll number: " + rollNumber);
System.out.println("Name: " + name);
sy.display();
ty.display();
System.out.println("Your final grade is: " + grade);
}

void grade() {
total = (sy.sytotal + ty.tytotal) / 2;
if (total>=70)
grade = 'A';
else if(total >= 60)
grade = 'B';
else if(total >= 50)
grade = 'C';
else if(total >= 40)
grade = 'D';
else
grade = 'F';

}
public static void main(String[] args) {
int i, n, rno;
String name;
Scanner sc = new Scanner(System.in);
System.out.print("Enter number of students: ");
n = sc.nextInt();
Stud s[] = new Stud[n];

for(i=0;i<n;i++) {
System.out.println("\nEnter student " + (i+1) + " details-->");
System.out.print("Enter roll no: ");
rno = sc.nextInt();
System.out.print("Enter name: ");
name = sc.next();
s[i] = new Stud(rno,name);
}

for(i=0;i<n;i++) {
System.out.println("\nStudent " + (i+1) + "Details");
s[i].display();
}
}
}

You might also like