-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCalculator.java
More file actions
167 lines (143 loc) · 4.83 KB
/
Calculator.java
File metadata and controls
167 lines (143 loc) · 4.83 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
161
162
163
164
165
166
167
import java.util.Scanner;
public class Calculator
{
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
//This tells if a number is even.
System.out.print("Please type a number and I will tell you if it is even: ");
int userNum = input.nextInt();
System.out.println("commencing tests...");
System.out.println(userNum + " is even: " + isEven(userNum));
System.out.println("3 is even: " + isEven(3));
System.out.println("");
System.out.println("8 is dividable by 5 : " + isDivisable(8,5));
System.out.println("");
//This will tell if a number given by user is in a range given by user.
System.out.print("Please type a number you would like to use as your number. ");
int userInt = input.nextInt();
System.out.print("Please type a number you want to use as your maximum of your range. ");
int userMax = input.nextInt();
System.out.print("Please type a number you want to use as your minimum of your range. ");
int userMin = input.nextInt();
System.out.println(inRange(userInt, userMin, userMax));
//This will print out two numbers inclusive sum of the intagers.
System.out.print("PLease give me a number. ");
int firstNum = input.nextInt();
System.out.print("Please give me another number. ");
int secondNum = input.nextInt();
System.out.println("The sum of the numbers bettween them is " + sumFrom(firstNum, secondNum));
//This will print out weather a number is divisable by another number.
System.out.print("Give me a dividend. ");
int dividend = input.nextInt();
System.out.print("Give me a divisor. ");
int divisor = input.nextInt();
System.out.println("Dividend is divisable by divisor: " + isDivisable(dividend, divisor));
//This will give the user the number provided in celcious.
System.out.print("What number would you like in Celcious. ");
double f = input.nextDouble();
System.out.println("Your number in celcious is " + fahrenheitToCelsius(f));
//This will calculate the number squared.
System.out.print("What number would you like to square. ");
int square = input.nextInt();
System.out.println("Your number squared is " + square(square));
//This will claculate the average of the two numbers.
System.out.print("What is your first average number. ");
int firstAverage = input.nextInt();
System.out.print("What is your second average number. ");
int secondAverage = input.nextInt();
System.out.println("Your average of the two numbers is "+ average(firstAverage, secondAverage));
//This will multiply two numbers given.
System.out.print("What is the number you want to multiply. ");
int firstMult = input.nextInt();
System.out.print("What is the other number you want to multiply. ");
int secondMult = input.nextInt();
System.out.println("Your product is " + multiply(firstMult, secondMult));
//This will add ten to a given number.
System.out.print("What is the number you want to add ten to? ");
int userTen = input.nextInt();
System.out.println("Your number + ten is " + add10(userTen));
//This will double a numher.
System.out.print("What is your number you want to double? ");
int userDouble = input.nextInt();
System.out.println("Your number doubled is " +doubleNumber(userDouble));
}
//this will print out weather a number is false or true
public static boolean isEven(int n)
{
if(n % 2 == 0)
{
return true;
}
else
{
return false;
}
}
//This will print out weather a number is divisable by another number.
public static boolean isDivisable(int num, int divisor)
{
if(num % divisor == 0)
{
return true;
}
else
{
return false;
}
}
public static boolean inRange(int num, int min, int max)
{
if(num>=min && num<=max)
{
return true;
}
else
{
return false;
}
}
public static int sumFrom(int a, int b)
{
int i = (((b-a+1)*(a+b))/2);
return i;
}
public static boolean isDivisible(int a, int b)
{
if((a%b)==0)
{
return true;
}
else
{
return false;
}
}
public static double fahrenheitToCelsius(double degrees)
{
double i = 5;
double o = 9;
double t = i/o;
double c = ((t)*(degrees-32));
return c;
}
public static int square(int x)
{
return x*x;
}
public static double average(double x,double y)
{
return (x+y)/2;
}
public static int multiply(int a, int b)
{
return a*b;
}
public static int add10(int a)
{
return a+10;
}
public static int doubleNumber(int x)
{
return 2 * x;
}
}