-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathStudent_method_overlaoding.java
More file actions
60 lines (54 loc) · 1.88 KB
/
Student_method_overlaoding.java
File metadata and controls
60 lines (54 loc) · 1.88 KB
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
import java.util.Scanner;
public class Student {
private String name;
private int age;
private String address;
public Student() {
this.name = "Unknown";
this.age = 0;
this.address = "Not Available";
}
public void setInfo(String name, int age) {
this.name = name;
this.age = age;
}
public void setInfo(String name, int age, String address) {
this.name = name;
this.age = age;
this.address = address;
}
public static void main(String[] args) {
Student arr[] = new Student[10];
Scanner sc = new Scanner(System.in);
for (int student = 1; student <= 10; student++) {
arr[student - 1] = new Student();
System.out.println("Enter option 1 for 2 inputs and 2 for 3 inputs- ");
int option = sc.nextInt();
sc.nextLine();
switch (option) {
case 1:
System.out.println("Enter name and age - ");
String name = sc.nextLine();
int age = sc.nextInt();
sc.nextLine();
arr[student - 1].setInfo(name, age);
break;
case 2: {
System.out.println("Enter name and age and address - ");
String name1 = sc.nextLine();
int age1 = sc.nextInt();
sc.nextLine();
String address1 = sc.nextLine();
arr[student - 1].setInfo(name1, age1, address1);
break;
}
}
}
for (int i = 0; i < 10; i++) {
System.out.println("Student info");
System.out.println("Name - " + arr[i].name);
System.out.println("Age - " + arr[i].age);
System.out.println("Address - " + arr[i].address);
}
}
}