Java Program To Calculate Internal Marks of Student Using Objects And Classes

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package payroll;
//classes and objects  - Accessing instance variables and methods of an object using reference.

import java.lang.*;
import java.io.*;
import java.util.*;

class StudentRec
{
int regNo, test1Marks, test2Marks, quizMarks, assMarks, homeAssgnMarks, attPer =0;
int attMarks = 0;
double weightedAverageTestMarks, totalMarks;

double computeInternalMarks()
{
if (test1Marks>test2Marks)
weightedAverageTestMarks = (0.75*test1Marks)+(0.25*test2Marks);
else
weightedAverageTestMarks = (0.25*test1Marks)+(0.75*test2Marks);
totalMarks = weightedAverageTestMarks+quizMarks+homeAssgnMarks+assMarks+attMarks;
return totalMarks;
}
}


public class StudentRecDemo
{
   public static void main(String args[])   throws IOException
{
int num;
double internalMarks;
StudentRec  record = new StudentRec(); // create an object
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.print("enter student id ");
num = Integer.parseInt(br.readLine());
record.regNo = num;

while(true)
{
System.out.print("Enter test1 marks (0-20) : ");
num = Integer.parseInt(br.readLine());
if(num>=0 && num<=20)
{
         record.test1Marks=num;
break;
}
if(num>20) System.out.println("Invalid Test 1 Marks: Marks are too high");
if(num<0) System.out.println("Invalid Test 1 Marks: -ve Marks can not be asccepted");
System.out.println("Please enter correct Values");
}
while(true)
{
System.out.print("Enter test2 marks (0-20) : ");
num = Integer.parseInt(br.readLine());
if(num>=0 && num<=20)
{
         record.test2Marks=num;
break;
}
if(num>20) System.out.println("Invalid Test 2 Marks: Marks are too high");
if(num<0) System.out.println("Invalid Test 2 Marks: -ve Marks can not be asccepted");
System.out.println("Please enter correct Values");
}
while(true)
{
System.out.print("Enter quiz marks (0-5) : ");
num = Integer.parseInt(br.readLine());
if(num>=0 && num<=5)
{
         record.quizMarks=num;
break;
}
if(num>5) System.out.println("Invalid quiz Marks: Marks are too high");
if(num<0) System.out.println("Invalid quiz Marks: -ve Marks can not be asccepted");
System.out.println("Please enter correct Values");
}
while(true)
{
System.out.print("Enter ass marks (0-5) : ");
num = Integer.parseInt(br.readLine());
if(num>=0 && num<=5)
{
         record.assMarks=num;
break;
}
if(num>5) System.out.println("Invalid ass Marks: Marks are too high");
if(num<0) System.out.println("Invalid ass Marks: -ve Marks can not be asccepted");
System.out.println("Please enter correct Values");
}
while(true)
{
System.out.print("Enter homeAssgnMarks (0-5) : ");
num = Integer.parseInt(br.readLine());
if(num>=0 && num<=5)
{
         record.homeAssgnMarks=num;
break;
}
if(num>5) System.out.println("Invalid homeAssgnMarks: Marks are too high");
if(num<0) System.out.println("Invalid homeAssgnMarks: -ve Marks can not be asccepted");
System.out.println("Please enter correct Values");
}
while(true)
{
System.out.println("enter Attendance Percentage (0-100)");
num= Integer.parseInt(br.readLine());
if(attper>=0 && attper<=100)
{
         record.attper=num;
break;
}
if(num>100) System.out.println("Invalid attper: percentage are too high");
if(num<0) System.out.println("Invalid attper: -ve  percentage can not be asccepted");
System.out.println("Please enter correct Values");
}

if (num >= 95)
record.attMarks = 5;
else if (num >= 90)
       record.attMarks = 4;
else if (num >=85)
record.attMarks = 3;
else if (num >= 80)
record.attMarks = 2;
else if (num >= 75)
record.attMarks = 1;
else if (num <75 && num>=65)
{
record.attMarks = 0;
System.out.println(" Student is eligible for Exam by paying  Condonation Fee and producing Medical Certificate");
}
else
{
record.attMarks = 0;
System.out.println("Student is detained");
}
record.attPer = num;

internalMarks = record.computeInternalMarks();
System.out.println(" The Internal Marks of the Student = " +internalMarks);
}
}
Bhanu Namikaze

Bhanu Namikaze is an Ethical Hacker, Web Developer, Student and Mechanical Engineer. He Enjoys writing articles, Blogging, Solving Errors and Social Networking. Feel Free to let me know any of your concerns about hacking or let me know if you need any more methods on hacking anything. Enjoy Learning

No comments:

Post a Comment