-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExtra_q_day_1.java
188 lines (188 loc) · 5.33 KB
/
Extra_q_day_1.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
/* 1. A company decided to give bonus of 5% to employee if his/her year of service is more than 5 years. Ask user for their salary and year of service and print the net bonus amount.
2. Take values of length and breadth of a rectangle from user and check if it is square or not.
3. Take two int values from user and print greatest among them.
4. A school has following rules for grading system:
a. Below 25 - F
b. 25 to 45 - E
c. 45 to 50 - D
d. 50 to 60 - C
e. 60 to 80 - B
f. Above 80 - A
Ask user to enter marks and print the corresponding grade.
5. Take input of age of 3 people by user and determine oldest and youngest among them.
6. Write a program to print absolute value of a number entered by user. E.g.-
INPUT: 1 OUTPUT: 1
INPUT: -1 OUTPUT: 1*/
import java.util.Scanner;
public class Extra_q_day_1 {
void age()
{
Scanner obj = new Scanner(System.in);
System.out.print("Enter your 1st member's age :\n>>");
int a = obj.nextInt();
System.out.print("Enter your 2nd member's age :\n>>");
int b = obj.nextInt();
System.out.print("Enter your 3rd member's age :\n>>");
int c = obj.nextInt();
if (a > b) {
if (c > a) {
System.out.println("person with age " + c + " is older");
} else {
System.out.println("person with age " + a + " is older");
}
if (c > b) {
System.out.println("person with age " + b + " is younger");
} else {
System.out.println("person with age " + c + " is younger");
}
} else {
if (c > b) {
System.out.println("person with age " + c + " is older");
} else {
System.out.println("person with age " + b + " is older");
}
if (c > a) {
System.out.println("person with age " + a + " is younger");
} else {
System.out.println("person with age " + c + " is younger");
}
}
obj.close();
}
void absolute()
{
Scanner obj = new Scanner(System.in);
System.out.print("Enter your number \n>>");
int num=obj.nextInt();
System.out.print("Absolute value is : ");
if ( num < 0 )
{
System.out.println(num*-1);
}
else
{
System.out.println(num);
}
obj.close();
}
void grade()
{
Scanner obj = new Scanner(System.in);
System.out.print("Enter your mark\n>>");
int num=obj.nextInt();
System.out.print("Your grade is : ");
if ( num < 25 )
{
System.out.println("F");
}
else if ( num < 45 )
{
System.out.println("E");
}
else if ( num < 50 )
{
System.out.println("D");
}
else if ( num < 60 )
{
System.out.println("C");
}
else if ( num < 80 )
{
System.out.println("B");
}
else
{
System.out.println("A");
}
obj.close();
}
void bonus()
{
Scanner obj = new Scanner(System.in);
System.out.print("Enter your Salary \n>>");
int salary=obj.nextInt();
System.out.print("How many years have you worked here ? \n>>");
int year=obj.nextInt();
if ( year > 5 )
{
System.out.println("Your Bonus is "+(float)salary/20);
}
else
{
System.out.println("Workk HArd to earn bonus!!!");
}
obj.close();
}
void square()
{
Scanner obj = new Scanner(System.in);
System.out.print("Enter length \n>>");
int length=obj.nextInt();
System.out.print("Enter breadth\n>>");
int breadth=obj.nextInt();
if ( length==breadth )
{
System.out.println("Square");
}
else
{
System.out.println("Rectangle");
}
obj.close();
}
void greatest_num()
{
Scanner obj = new Scanner(System.in);
System.out.print("Enter your 1st number \n>>");
int num_1=obj.nextInt();
System.out.print("Enter your 2nd number \n>>");
int num_2=obj.nextInt();
if ( num_1 > num_2 )
{
System.out.println(num_1+" is bigger");
}
else
{
System.out.println(num_2+" is bigger");
}
obj.close();
}
public static void main(String[] args) {
Extra_q_day_1 test = new Extra_q_day_1();
System.out.println("Choose your program");
System.out.println("1.Bonus calculator");
System.out.println("2.Is it a SQUARE !?");
System.out.println("3.Find the greatest number");
System.out.println("4.Grade System");
System.out.println("5.Find Oldest and Youngest Among Us");
System.out.println("6.Absolute value finder");
System.out.print("Enter your choice :\n>>");
Scanner obj = new Scanner(System.in);
int a = obj.nextInt();
switch (a)
{
case 1:
test.bonus();
break;
case 2:
test.square();
break;
case 3:
test.greatest_num();
break;
case 4:
test.grade();
break;
case 5:
test.age();
break;
case 6:
test.absolute();
break;
default:
System.out.println("Invalid option");
}
obj.close();
}
}