Skip to main content

Write a Java program to create a Package “SY” which has a class SYMarks (members – ComputerTotal, MathsTotal, and ElectronicsTotal). Create another package TY which has a class TYMarks (members – Theory, Practicals). Create n objects of Student class (having rollNumber, name, SYMarks and TYMarks). Add the marks of SY and TY computer subjects and calculate the Grade (‘A’ for >= 70, ‘B’ for >= 60 ‘C’ for >= 50 , Pass Class for > =40 else ‘FAIL’) and display the result of the student in proper format.

StudentMarks.java

import SY.*;
import TY.*;
import java.io.*;

class StudentInfo
{
     int rollno;
     String name,grade;
     public float gt,tyt,syt;
     public float per;
     public void get() throws IOException
     {
          System.out.println("Enter roll no and name of the student :");
          BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
          rollno=Integer.parseInt(br.readLine());
          name=br.readLine();
     }
}
public class StudentMarks
{
     public static  void main(String [] args) throws IOException
     {
         BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
         System.out.println("Enter the number of students :");
         int n=Integer.parseInt(br.readLine());
         SYMarks sy[]=new SYMarks[n];
         TYMarks ty[]=new TYMarks[n];
         StudentInfo(n);
         
         for (int i=0; i<n; i++)
         {
              si[i]=new StudentInfo();
              sy[i]=new SYMarks();
              ty[i]=new TYMarks();
             
              si[i].get();
              sy[i].get();
              ty[i].get();
             
              si[i].syt=sy[i].ct+sy[i].et+sy[i].mt;
              si[i].tyt=ty[i].pm+ty[i].tm;
              si[i].gt=si[i].syt+si[i].tyt;
              si[i].per=(si[i].gt/1200)*100;
              if (si[i].per>=70)
                 si[i].grade="A";
              else if (si[i].per>=60)
                 si[i].grade="B";  
              else if (si[i].per>=50)
                 si[i].grade="C";
              else if (si[i].per>=40)
                 si[i].grade="Pass";
              else si[i].grade="Fail";
         }
         
         System.out.println("RollNo\t Name\t SyTotal\t Tytotal\t GrandeTotal\t Percentage\t Grade");
         for (int i=0; i<n; i++)
         {
             System.out.println(si[i].rollno + "\t" + si[i].name + "\t" + si[i].syt + "\t" + si[i].tyt + "\t" + si[i].gt + "\t" + si[i].per + "\t" + si[i].grade);
         }
     }
}


SyMarks.java

//SyMarks.java
package SY;
import java.io.BufferedReader;
import java.io.*;

public class SyMarks
{
     public int ct,mt,et;
     public void get() throws IOException
     {
          System.out.println("Enter marks of students for computer,maths and electronics subject out of 200");
          BufferedReader br = new BufferedReader(new InputSystemReader(System.in));
          ct=Integer.parseInt(br.readLine());
          mt=Integer.parseInt(br.readLine());
          et=Integer.parseInt(br.readLine());
     }
}

TyMarks.java

//TyMarks.java
package TY;
import java.io.BufferedReader;
import java.io.*;


public class TyMarks
{
      public int tm,pm;
      public void get() throws IOException
      {
          System.out.println("Enter marks of the theory out of 400 and practicals out of 200");
          BufferedReader br = new BufferedReader(new InputSystemReader(System.in));
          tm=Integer.parseInt(br.readLine());
          pm=Integer.parseInt(br.readLine());
      }
}  

Comments

Popular posts from this blog

Write a program to read book information (bookid, bookname, bookprice, bookqty) in file “book.dat”. Write a menu driven program to perform the following operations using Random access file: i. Search for a specific book by name. ii. Display all book and total cost

  import java . io .*; import java . util .*; class Book {       String name , id ;       int qty ;       double price , total ;       Book ( String i , String n , String p , String q )      {               name = n ;               id = i ;               qty = Integer . parseInt ( q );               price = Double . parseDouble ( p );               total = qty * price ;      }       public String toString ()      {               System . out . println ( "name\t id\t qty\t price\t total" );               String s = name + "\t" + id + "\t" + qty + "\t" + price + "\t" + total ;           ...

Define a class MyDate (day, month, year) with methods to accept and display a MyDate object. Accept date as dd, mm, yyyy. Throw user defined exception “InvalidDateException” if the date is invalid. Examples of invalid dates : 03 15 2019, 31 6 2000, 29 2 2021

  import java . io .*; import java . util .*; class InvalidDateException extends Exception {       InvalidDateException ()       {               System . out . println ( "Invalid Date" );       } } class MyDate {       int day , mon , yr ;       void accept ( int d , int m , int y )       {             day = d ;             mon = m ;             yr = y ;       }       void display ()       {             System . out . println ( "Date is valid : " + day + "/" + mon + "/" + yr );       } } class Date {       public static void main ( String args []) throws Exception       {             Scanner sc = new Sca...

Write a Java program to design a screen using Awt that will take a user name and password. If the user name and password are not same, raise an Exception with appropriate message. User can have 3 login chances only. Use clear button to clear the TextFields.

  import java . awt .*; import java . awt . event .*; import javax . swing .*; class InvalidPasswordException extends Exception {       InvalidPasswordException ()       {             System . out . println ( "Username and password is not same" );       } } public class Password extends Frame implements ActionListener {       Label uname , upass ;       TextField nametext ;       TextField passtext , msg ;       Button login , Clear ;       Panel p ;       int attempt = 0 ;       char c = '*' ;             public void login ()       {             p = new Panel ();             uname = new Label ( "Username : " , Label . CENTER );             upass = n...