Answer to Question #211035 in Java | JSP | JSF for nimra

Question #211035

Write a class in java to get the name of Student and marks of three subjects. Calculate the total marks and average marks. Each subject has a maximum of 100 marks.


1
Expert's answer
2021-06-27T14:11:55-0400
/*
 * 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 student;


import java.util.Scanner;


/**
 *
 * @
 */
public class Student {
      private String name;
      private int  mark1 ;
      private int  mark2 ;
      private int  mark3 ;
     void setName(String n){
         name = n;
     }
     void setMark1(int mark){
         mark1 = mark;
     }
     void setMark2(int mark){
         mark2 = mark;
     }
     void setMark3(int mark){
         mark3 = mark;
     }
     int getMark1(){
         return mark1;
     }
     int getMark2(){
         return mark2;
     }
     int getMark3(){
         return mark3;
     }
     String getName(){
         return name;
     }
     void getAverage(){
         double sum = getMark3() + getMark1() + getMark2();
         System.out.println("The sum is\t" +sum);
         System.out.println("The average is\t" +sum / 3);
     }
     
      
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        Student t = new Student();
        Scanner input = new Scanner(System.in);
        String name;
        System.out.println("Enter the name of the student\n");
         name = input.next();
        System.out.println("Enter the first mark of the student\n");
        int mark1 = input.nextInt();
        System.out.println("Enter the second mark of the student\n");
        int mark2 = input.nextInt();
        System.out.println("Enter the third mark of the student\n");
        int mark3 = input.nextInt();
        if(mark1 < 100 && mark2 < 100 && mark3<100){
           System.out.println("The student name is\t" + name);
            System.out.println("The marks and average is a as follows:\n");
            t.setMark1(mark1);
            t.setMark2(mark2);
            t.setMark3(mark3);
            t.getAverage();
            
        }
        else{
             System.out.println("Marks cannot exceed 100");
        }
        
    }
    
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS