0% found this document useful (0 votes)
79 views2 pages

Program 2.a Write A Program For Class Student, Accept Name, Roll No, Marks of Three Subjects, Calculate Total and Display The Complete Information. Use Constructor

The program defines a Student class with name, roll number, class, and marks in 3 subjects as properties. It accepts student details from the user, calculates the total marks, and displays the student's name, class, roll number, individual subject marks, and total marks.

Uploaded by

Manvi Gour
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
79 views2 pages

Program 2.a Write A Program For Class Student, Accept Name, Roll No, Marks of Three Subjects, Calculate Total and Display The Complete Information. Use Constructor

The program defines a Student class with name, roll number, class, and marks in 3 subjects as properties. It accepts student details from the user, calculates the total marks, and displays the student's name, class, roll number, individual subject marks, and total marks.

Uploaded by

Manvi Gour
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Name: Manvi Gour

Program 2.a Write a program for class Student, accept name, roll no,marks of three
subjects, Calculate total and display the complete information. use Constructor.

import java.util.Scanner;
class Student1{
String Name;
int Roll_No;
String Class;
int m1;
int m2;
int m3;
int t;
public Student1() {
}
public Student1(String initName, int initRoll_No, String initClass, int initm1, int initm2, int initm3, int
initt) {

Name = initName;
Roll_No = initRoll_No;
Class = initClass;
m1 = initm1;
m2 = initm2;
m3 = initm3;
t = initt;
}
}

public class Student {

public static void main(String args[]) {

Scanner in = new Scanner(System.in);

System.out.print("Enter name of student: ");


String Name = in.nextLine();
System.out.print("Enter class of student: ");
String Class = in.nextLine();
System.out.print("Enter roll no of student: ");
int Roll_No = in.nextInt();
System.out.print("Enter marks in 1st subject: ");
int m1 = in.nextInt();
System.out.print("Enter marks in 2nd subject: ");
int m2 = in.nextInt();
System.out.print("Enter marks in 3rd subject: ");
int m3 = in.nextInt();
int t = m1 + m2 + m3;

System.out.println("The Details of Student are: ");


System.out.println("Name = " + Name);
System.out.println("Class = " + Class );
System.out.println("Roll No = " + Roll_No);
System.out.println("m1 = " + m1);
System.out.println("m2 = " + m2);
System.out.println("m3 = " + m3);
System.out.println("Total Marks = " + t);
}
}

OUTPUT:-

You might also like