-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDay23_prob1.java
More file actions
77 lines (59 loc) · 2.4 KB
/
Day23_prob1.java
File metadata and controls
77 lines (59 loc) · 2.4 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/*
Write a program to make "Employee" class consisting of following: -- instance variables --> id & age -- a parameterized constructor to initialize both instance variables.
Create array of "n" Employee objects (where "n" is no. of objects specified by user at run-time) and display the id and age of those employees whose age is less than 30.
Input Format
Program should take the inputs in following sequence: 1) In First input line, no. of Employee objects to create. i.e. value of "n". 2) In remaining input lines, enter id and age values of "n" Employee objects. For example, if no. of Employee-objects to be created are 2, then user-inputs should be as follows: 2 202 31 100 20
Constraints
1) No. of Employee objects range between 1 to 10, i.e. 1 <= n <= 10
2) All id & age values should be positive and range between: 10 <= id <= 1000 ; 18 <= age <= 50
Output Format
If no. of Employee-objects "n" is less than 1, then "Invalid input" should be displayed and no other input should be taken.
If any input value for id & age goes out-of-range (specified in constraints), then display "Invalid data" as overall output. Otherwise, display the id and age of those employees whose age is less than 30, such as follows:
100 20
Sample Input 0
2
202 31
100 20
Sample Output 0
100 20
*/
// kirtan jain
import java.io.*;
import java.util.*;
class Employee {
public int id, age;
Employee(int id, int age){
this.id=id;
this.age=age;
}
}
public class Solution {
public static void main(String[] args) {
/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
Scanner sc = new Scanner(System.in);
int n = sc.nextInt(), flag=0;
if(n<1 || n>10){
System.out.print("Invalid input");
return;
}
Employee[] emp = new Employee[n];
for(int i=0;i<n;i++){
int id=sc.nextInt(), age=sc.nextInt();
emp[i] = new Employee(id, age);
}
for(int i=0;i<n;i++){
if(emp[i].age>50 || emp[i].age<18 || emp[i].id<10 || emp[i].id>1000){
flag=1;
}
}
if(flag==1){
System.out.println("Invalid data");
return;
}
for(int i=0;i<n;i++){
if(emp[i].age<30){
System.out.println(emp[i].id+" "+emp[i].age);
}
}
}
}