forked from haonlywan/CodeHS-Java-APCSA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2.5.8 More Operations (Part 2)
52 lines (44 loc) · 1.24 KB
/
2.5.8 More Operations (Part 2)
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
public class Calculator
{
// This class does not need instance variables!
// Prints the sum of x and y
public void sum(double x, double y)
{
double result = x + y;
System.out.print(x);
System.out.print(" + ");
System.out.print(y);
System.out.print(" = ");
System.out.println(result);
}
// Prints the product of x and y
public void multiply(double x, double y)
{
double result = x * y;
System.out.print(x);
System.out.print(" * ");
System.out.print(y);
System.out.print(" = ");
System.out.println(result);
}
// Prints the quotient of x and y
public void divide(double x, double y)
{
double result = x / y;
System.out.print(x);
System.out.print(" / ");
System.out.print(y);
System.out.print(" = ");
System.out.println(result);
}
// Prints the difference of x and y
public void subtract(double x, double y)
{
double result = x - y;
System.out.print(x);
System.out.print(" - ");
System.out.print(y);
System.out.print(" = ");
System.out.println(result);
}
}