The calculator is like a rite-of-passage in programming. Every decent noob simply must write a program that adds and subtracts. Now that we already know how to manipulate classes and static methods, we'll create a regular calculator with four arithmetic operations and even the ability to find a percentage of a number!
Calculator
- 5
Locked
Comments (25)
- Popular
- New
- Old
You must be signed in to leave a comment
Naughtless
7 May 2021, 14:30
Okay, the requirement checking on this one is really bad. Why do I have to convert integers a and b to double using (double)? Why is it an issue if I just change the input parameter datatype to double?
Again, this course has been fantastic thus far with the lessons and what not, but this one specifically is TERRIBAD.
+1
Libby
5 January 2021, 12:24
Is the third requirement not a/b? Why is it not working?
0
Maryem Vickers
7 October 2020, 18:33
Hey! I have found out how to solve the Calculator task simply! Here's should will help you so much!;
(This is a new concept. Keep that in mind. :).).
For the multiply and divide problems, use this to help you;
double k = (double)b / c;
Do you get it now?! :>. I hope you do understand!
+4
Brandon Leirer
12 June 2020, 21:13
writing (double)a and (double)b does the trick too.
+2
Maryem Vickers
7 October 2020, 18:33
I was going to say that...
0
Nastya
7 May 2020, 17:24
(a / 100.0) * b
+12
Nickolas Johnson
13 March 2020, 20:07
Double.valueOf(a) you're my only friend.
0
Maryem Vickers
7 October 2020, 18:37
(double)k is too.
0
Jackir Miah
25 January 2020, 14:57
The last method has int as arguments but returns a double. Sneaky casting had me stumped.
+1
Tonatiuh
23 October 2019, 00:52
Note that in the division and percent methods you need to convert them into double numbers. You can add a double in parenthesis next to at least one number. For example:
If a is an integer, then (double)a/3 gives you a double number.
And if you want the x percent of the y number. First you need to divide x/100 and then multiply it by y.
+5
Almano Y'alano
12 February 2019, 17:47
Done!
0
Almano Y'alano
12 February 2019, 14:45
The method percent returns a double but b is an int and you want the method to return b, how's that possible? Would you like us to cast b as a double ?
0