-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.java
155 lines (119 loc) · 5.03 KB
/
Main.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
import java.util.ArrayList;
import java.util.Scanner;
import javax.swing.JOptionPane;
public class Main{
public static void Simple_Details() {
Scanner scanner = new Scanner(System.in);
scanner.close();
System.out.println("What is your name?");
String name = scanner.nextLine();
System.out.println("Hello "+name);
System.out.println("What is your age?");
int age = scanner.nextInt();
System.out.println("You are "+age+" years old");
}
public static void Address(){
Scanner scanner = new Scanner(System.in);
scanner.close();
// printf = "System.out.print"
System.out.println("Enter your Address Details: \n");
System.out.print("Door No: ");
String DoorNo = scanner.nextLine();
System.out.print("Street: ");
String Street = scanner.nextLine();
System.out.print("City: ");
String City = scanner.nextLine();
System.out.print("Pin Code: ");
int Pin = scanner.nextInt();
System.out.println();
System.out.println("Address Details: \n");
System.out.printf("Door No: %s\nStreet: %s\nCity: %s\nPin code: %d", DoorNo, Street, City, Pin);
System.out.print("\n\n\n");
}
public static void AreaOfCircle(){
Scanner scanner = new Scanner(System.in);
scanner.close();
System.out.print("\nEnter the radius of the Circle: ");
double radius = scanner.nextDouble();
double area = 3.14*radius*radius;
System.out.printf("\nArea of the Circle: %.3f", area);
System.out.print("\n\n");
}
public static void SimpleInterest() {
Scanner scanner = new Scanner(System.in);
scanner.close();
System.out.print("\nEnter the Principle Amount: ");
double Principle = scanner.nextDouble();
System.out.print("Enter the Interest: ");
double Rate = scanner.nextDouble();
System.out.print("Enter the Tenure: ");
double Tenure = scanner.nextDouble();
double Interest = (Principle+Rate+Tenure)/100;
System.out.printf("Interest for %.1f years = %.3f\n", Tenure, Interest);
}
public static void Arrays_Example(){
Integer ArraySize = Integer.valueOf(JOptionPane.showInputDialog("Enter the number of elements: "));
Integer[] elements = new Integer[ArraySize];
for(int i=0; i<ArraySize; i++){
elements[i] = Integer.valueOf(JOptionPane.showInputDialog("Enter the element at index " + i + ": "));
}
System.out.print("The elements are...\n");
for(int i=0; i<ArraySize; i++){
System.out.print(elements[i]+"\t");
}
}
public static void Array_List_Example(){
ArrayList<String> fruitList = new ArrayList<>();
fruitList.add("Apple");
fruitList.add("Banana");
fruitList.add("Cherry");
fruitList.add("Dragon fruit");
System.out.print("The fruit list is...\n");
// for(int i = 0; i < fruitList.size(); i++){
// System.out.print(fruitList.get(i)+"\t");
// }
System.out.println(fruitList);
fruitList.remove("Dragon fruit");
System.out.print("After removing, the fruit list is...\n");
// for(int i = 0; i < fruitList.size(); i++){
// System.out.print(fruitList.get(i)+"\t");
// }
System.out.println(fruitList);
}
public static void Find_Hypotenuse(){
Scanner scanner = new Scanner(System.in);
scanner.close();
System.out.print("Enter the adjacent side : ");
double x = scanner.nextDouble();
System.out.print("Enter the opposite side : ");
double y = scanner.nextDouble();
double z = Math.sqrt((x*x)+(y*y));
System.out.print("The Hypotenuse side is "+z);
}
public static void main(String[] args){
System.out.println();
Scanner scanner = new Scanner(System.in);
scanner.close();
boolean exit = false;
do{
System.out.println("\n1. Address");
System.out.println("2. Area of Circle");
System.out.println("3. Simple Interest");
System.out.println("0. Exit");
System.out.print("Enter the program number :");
int program = scanner.nextInt();
scanner.nextLine();
switch (program) {
case 1 -> Address();
case 2 -> AreaOfCircle();
case 3 -> SimpleInterest();
case 0 -> {
System.out.println("Exiting...\n");
exit = true;
}
default -> System.out.println("Enter a valid number");
}
}while (exit != true);
System.out.println();
}
}