• 5
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!
You can't complete this task, because you're not signed in.
  • Popular
  • New
  • Old
You must be signed in to leave a comment
Brandon LeirerLevel 7 , Keller
12 June, 21:13
writing (double)a and (double)b does the trick too.
NastyaLevel 17 , Moscow
7 May, 17:24
(a / 100.0) * b
Nickolas JohnsonLevel 8 , St. Louis
13 March, 20:07
Double.valueOf(a) you're my only friend.
Jackir MiahLevel 9 , London
25 January, 14:57
The last method has int as arguments but returns a double. Sneaky casting had me stumped.
TonatiuhLevel 12 , Mexico
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.
Almano Y'alanoLevel 7 , London
12 February 2019, 17:47
Almano Y'alanoLevel 7 , London
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 ?
SundaramLevel 12 , Chennai
28 January 2019, 18:12
I am a mathematician and I cannot appreciate the logic that b as a % of a is (b/100)*a. b as a percentage of a is always b/a * 100. For the sake of programming the rules of mathematics particularly as a major part of the world understands should not be changed. Please correct this error in your lessons.
RomanLevel 41
5 April 2019, 08:43
Thanks for the comment, we will clarify the condition.
Syed Tayyab ul MazharLevel 12 , Karachi
26 January 2019, 07:57
For the last task : The percent method must return b as a percentage of a. For example, the result for numbers 5 and 20 is 1, because 20% of 5 is 1.
AhmedLevel 23 , Amsterdam
3 May 2019, 12:41
Grigore TurcanLevel 9 , Chisinau
20 December 2018, 11:26
Why the method does not work