@NanaOhene_Nyark/

InnocentQuickFile

Java

No description

fork
loading
Files
  • Main.java
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
import java.util.Scanner;
public class Lab04  {
   public static Scanner keyboard = new Scanner(System.in);
   public static void main(String[] args){
   
      while (true){ //infinite while loop
         System.out.println("MAIN MENU");
         System.out.println("---------");
         System.out.println("Enter 1 for addition");
         System.out.println("Enter 2 for subtraction");
         System.out.println("Enter 3 for multiplication");
         System.out.println("Enter 4 for division");
         System.out.println("Enter 5 to exit");
         System.out.println("Enter 6 to raise to the power");
         System.out.println("Enter 7 to squareroot");
         System.out.println("Enter 8 to Round the number");
         System.out.println("Enter 9 for absolute value");
         System.out.println("Enter 10 for generate a random number within a user-defined range");
        
         int choice = keyboard.nextInt();
         if (choice == 1){
            addition();
         }
         else if (choice == 2){
            subtraction();
         }
         else if (choice == 3){
            multiplication();
         }
         else if (choice == 4){
            division();
         }
         else if (choice == 5){
            System.out.println("Good-bye!");
            System.exit(0);
         }
         else if (choice == 6){
         power();
         }
         else if (choice == 7){
         squareroot();
         }
         else if (choice == 8){
         round();
         }
         else if (choice == 9){
         absolutevalue();
         }
         else if (choice == 10){
         range();
         }
         else{
            System.out.println("Error: Invalid choice");
            System.out.println();
         }
      }
   }
   public static void addition(){
      System.out.println("Enter first number:");
      double num1 = keyboard.nextDouble();
      System.out.println("Enter second number:");
      double num2 = keyboard.nextDouble();
      System.out.println();
      System.out.println(num1 + " + " + num2 + " = " + (num1 + num2));
      System.out.println();
   }

  public static void subtraction(){
      System.out.println("Enter first number:");
      double num1 = keyboard.nextDouble();
      System.out.println("Enter second number:");
      double num2 = keyboard.nextDouble();
      System.out.println();
      System.out.println(num1 + " - " + num2 + " = " + (num1 - num2));
      System.out.println();
      }
public static void multiplication(){
      System.out.println("Enter first number:");
      double num1 = keyboard.nextDouble();
      System.out.println("Enter second number:");
      double num2 = keyboard.nextDouble();
      System.out.println();
      System.out.println(num1 + " * " + num2 + " = " + (num1 * num2));
      System.out.println();
      }
public static void division(){
      System.out.println("Enter first number:");
      double num1 = keyboard.nextDouble();
      System.out.println("Enter second number:");
      double num2 = keyboard.nextDouble();
      System.out.println();
      System.out.println(num1 + " / " + num2 + " = " + (num1 / num2));
      System.out.println();
      }
public static void power(){
      System.out.println("Enter first number:");
      double num1 = keyboard.nextDouble();
      System.out.println("Enter second number:");
      double num2 = keyboard.nextDouble();
      System.out.println();
      System.out.println(num1 + " ^ " + num2 + " = " + (Math.pow(num1,num2)));
      System.out.println();
      }
public static void squareroot(){
      System.out.println("Enter first number:");
      double num1 = keyboard.nextDouble();
      System.out.println();
      System.out.println("Squareroot of " + num1 + " is " + " = " + (Math.sqrt(num1)));
      System.out.println();
}
public static void round(){
      System.out.println("Enter first number:");
      double num1 = keyboard.nextDouble();
      System.out.println();
      System.out.println(" Your number rounded " + num1 + " is " + " = " + (Math.round(num1)));
      System.out.println();
}
public static void absolutevalue(){
      System.out.println("Enter first number:");
      double num1 = keyboard.nextDouble();
      System.out.println();
      System.out.println(" The absolute vaule of " + num1 + " is " + " = " + (Math.abs(num1)));
      System.out.println();
}
public static void range(){
      System.out.println("Enter first number:");
      double num1 = keyboard.nextDouble();
      System.out.println("Enter second number:");
      double num2 = keyboard.nextDouble();
      System.out.println();
      System.out.println(num1 + " < x < " + num2 + " = " + (Math.random()*num1 + num2));
      System.out.println();
      }
       }