Skip to main content

Java Progarm to accept the name, class, roll no and 3 subject marks and display all the details with total and average marks

import java.util.*;
public class Mark{
    Scanner scan=new Scanner(System.in);
    int rollNo, clas;
    String name;
    float mark1, mark2, mark3, total, average;
    public void input(){
        try{
            System.out.println("Enter the Name of the Student: ");
            name=scan.nextLine();
        }
        catch(Exception e){
            System.out.println("Error Code: "+e);
            System.exit(0);
        }
        try{
            System.out.println("Enter "+name+"'s Class: ");
            clas=scan.nextInt();
            System.out.println("Enter "+name+"'s Roll No: ");
            rollNo=scan.nextInt();
            System.out.println("Enter 1st Subject Marks: ");
            mark1=scan.nextFloat();
            System.out.println("Enter 2nd Subject Marks: ");
            mark2=scan.nextFloat();
            System.out.println("Enter 3rd Subject Marks: ");
            mark3=scan.nextFloat();
        }
        catch(NumberFormatException E){
            System.out.println("Error Code: "+E);
            System.exit(0);
        }
    }

    public void compute(){
        total=mark1+mark2+mark3;
        average=total/3;
    }

    public void details(){
        System.out.println("\n\nDetails you entered:- ");
        System.out.println("Name: "+name);
        System.out.println("Class: "+clas);
        System.out.println("Roll No: "+rollNo);
        System.out.println("1st Subject Marks: "+mark1+"\n2nd Subject Marks: "+mark2+"\n3rd Subject Marks: "+mark3);
        System.out.println("Total: "+total+"\nAverage: "+average);
    }

    public static void main(String[] args){
        Mark details=new Mark();
        details.input();
        details.compute();
        details.details();
    }
}

Output:-
Enter the Name of the Student:
Jean
Enter Jean's Class:
10
Enter Jean's Roll No:
08
Enter 1st Subject Marks:
89
Enter 2nd Subject Marks:
87
Enter 3rd Subject Marks:
79


Details you entered:-
Name: Jean
Class: 10
Roll No: 8
1st Subject Marks: 89.0
2nd Subject Marks: 87.0
3rd Subject Marks: 79.0
Total: 255.0
Average: 85.0

Comments

Popular posts from this blog

Java Program to calculate the Run Rate per over in a cricket match

import java.io.*; import java.util.*; public class RunRate{     Scanner scan=new Scanner(System.in);     int runs, balls;     float runRate;     public void input(){         try{             System.out.println("Enter Runs Scored: ");             runs=scan.nextInt();             System.out.println("Enter Balls Delivered: ");             balls=scan.nextInt();         }         catch(NumberFormatException e){             System.out.println("Error Code: "+e);             System.exit(0);   ...

Vanilla Javascript each()

JQuery's each() is very useful when iterating through elements. But you don't want to use JQuery in your project you can simply add the following javascript code which works somewhat similar to the JQuery's each function. Here the fnc parameter is the function string which is converted to a valid function call replacing all the $(this) with this /**  * This function binds a particular function to every element with the specified selector. It is somewhat same as JQuery's each() with less functionality  * @param {String|DOMElement} selector  * @param {Function} fnc  */ function each(selector, fnc) {     var elem;     if (typeof selector === "string") {         elem = $_(selector);     } else {         elem = selector;     }     fnc = (fnc.toString().replace("$(this)", "elem") + "();").replace("function () {", "").replac...

Java Program to display Welcome Message

import java.io.*;// I/O package imported. public class Welcome{        //class name is "Welcome"     public Welcome(){      //constructor declaired to print the message.         System.out.println("Welcome to Java Programming Language!");/* System.out.println is used for output. Welcome Message is written within " ".*/     }//display() closes here.     public static void main(String[] args){        //main() is declaired to declair an object in it.         Welcome obj=new Welcome();  //Object "Obj" is bean created.     }//main() closes. }//class "Welcome" ends here. Above program displays the message which is written by you in " ".  In programs "/*" and "*/" are use for multiple line comment(s) and "//" is use for single line comment. Code line "Welc...