hello friends.i need to write an interactive program using java in that when i output it it borrows me details that i should enter and at long last it outputs all those details together.Example a program that will calculate the grades of students in a class.this is are some of the details.Name of student,registration number, marks obtained per subject,grade per subject,total marks,general grade.and this is how it will go when you execute it.it will ask you to enter the name of the student,after that his/her registration number, marks per subject.then this program will calculate grades per subject and the final grade.lastly it will give all this details together.please contribute something
Hi Friend,
Try the following code:
import java.util.*; public class StudentResult{ String studentID; String name; double hindi; double maths; double science; double total; String grade; public void setStudentID(String studentID){ this.studentID=studentID; } public String getStudentID(){ return studentID; } public void setName(String name){ this.name=name; } public String getName(){ return name; } public void setHindi(double hindi){ this.hindi=hindi; } public double getHindi(){ return hindi; } public void setMaths(double maths){ this.maths=maths; } public double getMaths(){ return maths; } public void setScience(double science){ this.science=science; } public double getScience(){ return science; } public void setTotal(double total){ this.total=total; } public double getTotal(){ return total; } public void setGrade(String grade){ this.grade=grade; } public String getGrade(){ return grade; } public static void main(String[]args){ Scanner input=new Scanner(System.in); System.out.print("No of students in a class: "); int menu = input.nextInt(); System.out.println(); StudentResult data[]=new StudentResult[menu]; for (int i=0; i<data.length; i++) { int j=i+1; System.out.println(); System.out.println("********Student "+j+"*********"); System.out.println("Enter Registration No:"); String no=input.next(); System.out.println("Enter Name: "); String n=input.next(); System.out.println("Marks in Hindi:"); double m1=input.nextDouble(); System.out.println("Marks in Maths:"); double m2=input.nextDouble(); System.out.println("Marks in Science"); double m3=input.nextDouble(); double tmarks=m1+m2+m3; double tm=tmarks/3; data[i] = new StudentResult(); data[i].setStudentID(no); data[i].setName(n); data[i].setHindi(m1); data[i].setMaths(m2); data[i].setScience(m3); data[i].setTotal(tmarks);
continue.........
if(tm<40){ data[i].setGrade("Fail"); } if(tm>40&&tm<60){ data[i].setGrade("D"); } if(tm>60&&tm<70){ data[i].setGrade("C"); } if(tm>70&&tm<90){ data[i].setGrade("B"); } if(tm>90){ data[i].setGrade("A"); } } System.out.println(); String g1="",g2="",g3=""; for(int i=0;i<menu;i++){ StudentResult show = data[i]; String ide=show.getStudentID(); String nn=show.getName(); double mar1=show.getHindi(); double mar2=show.getMaths(); double mar3=show.getScience(); double tot=show.getTotal(); String g = show.getGrade(); System.out.println("Result of Student "+(i+1)); System.out.print("Registration Number: "+ide+"\n"); System.out.print("Student Name: "+nn+"\n"); if(mar1<40){ g1="Fail"; } if(mar1>=40&&mar1<=60){ g1="D"; } if(mar1>60&&mar1<=70){ g1="C"; } if(mar1>70&&mar1<=90){ g1="B"; } if(mar1>90){ g1="A"; } if(mar2<40){ g2="Fail"; } if(mar2>40&&mar2<60){ g2="D"; } if(mar2>60&&mar2<70){ g2="C"; } if(mar2>70&&mar2<90){ g2="B"; } if(mar2>90){ g2="A"; } if(mar3<40){ g3="Fail"; } if(mar3>40&&mar3<60){ g3="D"; } if(mar3>60&&mar3<70){ g3="C"; } if(mar3>70&&mar3<90){ g3="B"; } if(mar3>90){ g3="A"; } System.out.print("Marks in Hindi: "+mar1+"\n"); System.out.print("Grade in Hindi: "+g1+"\n"); System.out.print("Marks in Maths: "+mar2+"\n"); System.out.print("Grade in Maths: "+g2+"\n"); System.out.print("Marks in Science: "+mar3+"\n"); System.out.print("Grade in Science: "+g3+"\n"); System.out.print("Total Marks: "+tot+"/300\n"); System.out.print("Final Grade: "+g+"\n"); System.out.println(); } } }
Thanks