-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
160 lines (116 loc) · 4.63 KB
/
Copy pathMain.java
File metadata and controls
160 lines (116 loc) · 4.63 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
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
package LifeManager;
import java.util.Random;
import java.util.Scanner;
public class Main {
public static void main(String[] args) throws InterruptedException{
// Welcome to Life Manager
Scanner scanner = new Scanner(System.in);
String name;
int age;
boolean isStudent;
while(true){
// Input name
System.out.print("Enter your name: ");
name = scanner.nextLine();
if(name.isEmpty() || name.contains(" ")){
System.out.println("Name must not contains space and not be empty: ");
continue;
}
break;
}
while (true) {
// Input age
System.out.print("Enter Your age: ");
age = scanner.nextInt();
if(age <= 0){
System.out.println("AGE must me greater than zero!");
continue;
}
break;
}
System.out.print("Are you a student?:");
isStudent = scanner.nextBoolean();
while (true) {
System.out.println("-------Welcom to Life manager-------");
System.out.println("===Main Menu===");
System.out.println("1. BMI Calculator");
System.out.println("2. Study Time Calculator");
System.out.println("3. Random Motivation");
System.out.println("4. Countdown to Birthday");
System.out.println("5. Exit");
// Select option
int userChoice;
System.out.print("Select any one option: ");
userChoice = scanner.nextInt();
// Bmi Calculator
if(userChoice == 1){
while (true) {
double height; // meters
double weight; //kg
double bmi;
System.out.print("Enter your height:");
height = scanner.nextDouble();
System.out.print("Enter your weight:");
weight = scanner.nextDouble();
bmi = weight / (height * height);
if (bmi < 18.5) {
System.out.println("You are Underweight.");
}
else if (bmi <= 24.9) {
System.out.println("Your weight is Normal.");
}
else if (bmi <= 29.9) {
System.out.println("You are Overweight.");
}
else {
System.out.println("You are Obese.");
}
break;
}
}
// Study Time Calculator
double hours;
double weekly;
String student;
if (userChoice == 2){
if (isStudent){
System.out.print("How much hours you study per day?: ");
hours = scanner.nextDouble();
weekly = 7 * hours;
student = (weekly >= 40) ? "Beast mode" : "Needs focus";
System.out.println(student);
}
else{
System.out.println("You are not a student.");
}
}
// Random Motivation
if (userChoice == 3){
Random random = new Random();
int randomNumber = random.nextInt(1 , 4);
switch (randomNumber) {
case 1 -> System.out.println("Stay disciplined.");
case 2 -> System.out.println("Consistency beats intensity.");
case 3 -> System.out.println("Small progress daily.");
}
}
// Countdown to Birthday
if (userChoice == 4){
int days;
System.out.println("How many days is your birthday?");
days = scanner.nextInt();
for (int i = days ; i > 0 ; i -= 1){
System.out.println(i);
Thread.sleep(500);
}
System.out.println("🎉 Happy Early Birthday!");
}
// End of program
if(userChoice == 5){
System.out.println("Good bye, see you soon.");
break;
}
}
scanner.close();
}
}