Interactive program

Ads

 
 

Share on Google+Share on Google+

Timothy Ouko Omare
Interactive program
2 Answer(s)      7 years ago
Posted in : Java Beginners

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

Ads
View Answers

November 16, 2010 at 1:23 PM


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);


November 16, 2010 at 1:24 PM


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


Ads









Related Tutorials/Questions & Answers:
Interactive program
Interactive program  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
Interactive map
Interactive map  hi........ i require map to be zoom in and enlarge the area and show its detail. Can anyone tel me how can this be done using java swings .... plz help
Advertisements
Interactive Maps
Interactive Maps  Hi....................... How can u make maps interactive using java code. I mean if a map of some location is stored in database then when we retrieve it and display on java form then when a click
Interactive Maps ways
Interactive Maps ways  hi........ Is there any way to make interactive in project i mean how to do some event on maps to make them interactive..??????????/ can anyone tel me how to do that.......??????? using java swings plz
Interactive, Non-Interactive Gauge Example
Interactive, Non-Interactive Gauge Example   ... to draw the interactive and non-interactive gauge which is used to display... as: Gauge(String label, boolean interactive, int maxValue, int initialValue
Artifacts of com.forest-interactive
List of Artifacts of com.forest-interactive maven depenency
JSP - Abobe Interactive Forms - JSP-Servlet
JSP - Abobe Interactive Forms  Dear Gurus, Hi! I have a problem... to fill a form. I have used Abobe Interactive Form for that and I am using Apache... running your program at that time automatically write XML coding by j2ee
Version of com.nativelibs4java>javacl-interactive-image-demo dependency
List of Version of com.nativelibs4java>javacl-interactive-image-demo dependency
Version of com.nativelibs4java>javacl-interactive-image-demo dependency
List of Version of com.nativelibs4java>javacl-interactive-image-demo dependency
Version of com.nativelibs4java>javacl-interactive-image-demo-jna dependency
List of Version of com.nativelibs4java>javacl-interactive-image-demo-jna dependency
Version of com.nativelibs4java>javacl-interactive-image-demo-jna dependency
List of Version of com.nativelibs4java>javacl-interactive-image-demo-jna dependency
program
program  any program of hotel or school management
program
program  program of jdbc using ms access for creating table
program
program  write a javascript program to create a application form with validation
program
program  write a html program in show table and this word in box
program
program  write a program different between to dates in terms of days in java
program
program   Write a program to find the difference between sum of the squares and the square of the sums of n numbers
program
program  write a program reversee a string. input-hi this is roseindia output-roseindia is this hi
program
program  develop a servlet to insert the data in the database from our program in the table stored in the database
program
program  WAP a java program to form 1/2+3/4+5/6+7/8 series
INTERACTIVE TRANSMISSION OF JPEG2000 IMAGES USING WEB - JSP-Servlet
INTERACTIVE TRANSMISSION OF JPEG2000 IMAGES USING WEB  Hello Friend, I want INTERACTIVE TRANSMISSION OF JPEG2000 IMAGES USING WEB using jsp .. Can you help me
program
program   An old-style movie theater has a simple profit program. Each customer pays $5 per ticket. Every performance costs the theater $20, plus $.50 per attendee. Develop the program calculateTotalProfit that consumes
program
program  explanation of program on extending thread class   Hi Friend, Please go through the following link: Java Threads Thanks
program
program  Develop the program calculateCylinderArea, which accepts radius of the cylinder's base disk and its height and computes surface area of the cylinder
program
program  write a java program to input a no. and print wheather the no. is a special no or not. (special no. are those no whose factorial of the sum of digit of the no is same as the original
program
program  Develop a program that computes the distance a boat travels across a river, given the width of the river, the boat's speed perpendicular to the river, and the river's speed. Speed is distance/time, and the Pythagorean
Program
Program  a program to prove that default constructor of super class is available to subclass by default. Define a parameterize constructor for super class to store name = ‚??Tommy‚?? age=‚??23‚?? and call this constructor
program
program  how to improve programming skills plss tell some tips..i am understanding concepts but unable to write program so,pls give some guideness plsss
Program
Program  a program to create two classes Commercial and Domestic. Override the method calculatebill() of Commercial class(Rs.8 per unit) into Domestic class(Rs 6 per unit) to compute electricity bill for both classes
program
program  no i want a program that shows how merge sort algorithm works in graphical representations like numbers are taken in circles and computation... in rectangles or circles wat ever it may be. the theme of program is to show algorithm

Ads

 
Advertisement null

Ads