[go: up one dir, main page]

0% found this document useful (0 votes)
14 views4 pages

Slip 14

Uploaded by

pragati pawar
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)
14 views4 pages

Slip 14

Uploaded by

pragati pawar
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/ 4

import java.util.

Scanner;

// Custom Exception Class


class ZeroNumberException extends Exception {
public ZeroNumberException(String message) {
super(message);
}
}

public class PrimeNumberCheck_slip_14 {

// Static method to check if a number is prime


public static boolean isPrime(int number) {
if (number <= 1) {
return false; // 0 and 1 are not prime numbers
}
for (int i = 2; i <= Math.sqrt(number); i++) {
if (number % i == 0) {
return false; // Not prime
}
}
return true; // Prime
}

// Main method to accept input and check for zero or prime


public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter a number: ");
int number = scanner.nextInt();

try {
// Throw exception if the number is zero
if (number == 0) {
throw new ZeroNumberException("Number is 0");
}

// Check if the number is prime


if (isPrime(number)) {
System.out.println(number + " is a prime number.");
} else {
System.out.println(number + " is not a prime number.");
}
} catch (ZeroNumberException e) {
System.out.println(e.getMessage());
} finally {
// Close the scanner
scanner.close();
}
}
}
package SY;

public class SYMarks {


public int ComputerTotal;
public int MathsTotal;
public int ElectronicsTotal;

// Constructor to initialize SY marks


public SYMarks(int computer, int maths, int electronics) {
this.ComputerTotal = computer;
this.MathsTotal = maths;
this.ElectronicsTotal = electronics;
}
}
package TY;

public class TYMarks {


public int Theory;
public int Practicals;

// Constructor to initialize TY marks


public TYMarks(int theory, int practicals) {
this.Theory = theory;
this.Practicals = practicals;
}
}
import SY.SYMarks;
import TY.TYMarks;
import java.util.Scanner;

class Student {
private int rollNumber;
private String name;
private SYMarks syMarks;
private TYMarks tyMarks;

// Constructor to initialize student details and marks


public Student(int rollNumber, String name, SYMarks syMarks, TYMarks tyMarks) {
this.rollNumber = rollNumber;
this.name = name;
this.syMarks = syMarks;
this.tyMarks = tyMarks;
}

// Method to calculate total Computer marks and grade


public void calculateGrade() {
// Total Computer Marks = SY Computer + TY Theory + TY Practicals
int totalComputerMarks = syMarks.ComputerTotal + tyMarks.Theory +
tyMarks.Practicals;
String grade;

// Determine grade based on totalComputerMarks


if (totalComputerMarks >= 70) {
grade = "A";
} else if (totalComputerMarks >= 60) {
grade = "B";
} else if (totalComputerMarks >= 50) {
grade = "C";
} else if (totalComputerMarks >= 40) {
grade = "Pass Class";
} else {
grade = "FAIL";
}

// Display result
System.out.println("Student Roll No: " + rollNumber);
System.out.println("Student Name: " + name);
System.out.println("Total Computer Marks: " + totalComputerMarks);
System.out.println("Grade: " + grade);
}
}

public class Main {


public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);

System.out.print("Enter the number of students: ");


int n = scanner.nextInt();
scanner.nextLine(); // Consume newline

Student[] students = new Student[n];

// Accept details of each student


for (int i = 0; i < n; i++) {
System.out.println("\nEnter details for Student " + (i + 1));

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


int rollNumber = scanner.nextInt();
scanner.nextLine(); // Consume newline

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


String name = scanner.nextLine();

// Accept SY Marks
System.out.println("Enter SY Marks:");
System.out.print("Computer Total: ");
int syComputer = scanner.nextInt();
System.out.print("Maths Total: ");
int syMaths = scanner.nextInt();
System.out.print("Electronics Total: ");
int syElectronics = scanner.nextInt();
SYMarks syMarks = new SYMarks(syComputer, syMaths, syElectronics);

// Accept TY Marks
System.out.println("Enter TY Marks:");
System.out.print("Theory: ");
int tyTheory = scanner.nextInt();
System.out.print("Practicals: ");
int tyPracticals = scanner.nextInt();
TYMarks tyMarks = new TYMarks(tyTheory, tyPracticals);

// Create student object


students[i] = new Student(rollNumber, name, syMarks, tyMarks);
}

// Display the result for each student


System.out.println("\nStudent Results:");
for (int i = 0; i < n; i++) {
students[i].calculateGrade();
System.out.println("-------------------------");
}

// Close scanner
scanner.close();
}
}

You might also like