-
Notifications
You must be signed in to change notification settings - Fork 0
/
StdDetails1.java
80 lines (67 loc) · 2.24 KB
/
StdDetails1.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/*
Write a program for taking following inputs from user and display them
back
1. Name
2. Branch
3. Total Marks
4. Number of Subjects
5. Percentage
Do the program for a whole class by first asking "How many
students are there in the class?" User will input a number. Then take the
information for all students one by one and display.
*/
import java.util.Scanner;
class Student {
private String name;
private String branch;
private double totalMarks;
private int numSubjects;
private double percentage;
public Student() {
name = "NA";
branch = "NA";
totalMarks = 0.0;
numSubjects = 0;
percentage = 0.0;
}
public void input() {
Scanner in = new Scanner(System.in);
System.out.print("Name: ");
name = in.nextLine();
in.next();
System.out.print("Branch: ");
branch = in.nextLine();
System.out.print("Total Marks: ");
totalMarks = in.nextDouble();
System.out.print("Number of Subjects: ");
numSubjects = in.nextInt();
System.out.print("Percentage: ");
percentage = in.nextDouble();
in.nextLine();
}
public void display() {
System.out.println("-----------------------------");
System.out.println("Name: " + name);
System.out.println("Branch: " + branch);
System.out.println("Total Marks: " + totalMarks);
System.out.println("Number of Subjects: " + numSubjects);
System.out.println("Percentage: " + percentage + "%");
}
}
class StdDetails1 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter total number of students: ");
int totalStudents = sc.nextInt();
Student[] students = new Student[totalStudents];
for (int i = 0; i < totalStudents; i++) {
System.out.println("\nEnter details of student " + (i + 1) + ":");
students[i] = new Student();
students[i].input();
}
System.out.println("\nStudent Information:");
for (int i = 0; i < totalStudents; i++) {
students[i].display();
}
}
}