0

Paint Costs || Java | What did i wrong?

import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner input = new Scanner(System.in); int totalColor = input.nextInt(); double canvasAndBrushes = 40.0; double purchase = canvasAndBrushes + totalColor; double finishedPurcase = purchase *110/100; System.out.println(finishedPurcase ); } }

18th Apr 2021, 3:36 PM
Chris Güler
Chris Güler - avatar
18 Antworten
+ 2
import java.util.*; public class Program { public static void main(String[] args) { Scanner sc=new Scanner (System.in); int n=sc.nextInt();//20 double p=5*n+40;//here each colour costs Rs.5 so number of colours*5+additional charges for canvas and brushes(40) int r=(int)(Math.rint (p+(10*p/100)));//here 10%tax is collected and round off function is used so that it should give the floor values of decimals System.out.println(r); } }
19th Apr 2021, 9:18 AM
Atul [Inactive]
+ 1
you did everything right, but he will not appreciate it and will not remember it. it is much more useful to push for a solution than to give a ready-made one. what do you think, if you are a fisherman and know how to fish. a hungry man will approach you and ask you to feed him. what's better in the long run? give him a fish or teach him how to fish?
18th Apr 2021, 4:34 PM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
+ 1
better tell us how to convert float to int, since the program will not pass the test
18th Apr 2021, 4:36 PM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
+ 1
"Tell me and I forget, teach me and I remember, involve me and I learn" - Benjamin Franklin
18th Apr 2021, 4:41 PM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
+ 1
Because test cases require to be in integers
18th Apr 2021, 5:37 PM
Atul [Inactive]
0
Hi! you made a slight mistake in the first formula. explain how you calculate the total cost? brushes and colors? Hint question: how much does one color cost?
18th Apr 2021, 3:56 PM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
0
Atul, I asked you not to give direct answers, you are thus disrupting the learning process
18th Apr 2021, 4:28 PM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
0
Ярослав Вернигора(Yaroslav Vernigora) Sorry as he showed his attempt and tried to accomplish his work so I helped him a bit because he was missing one mathematical function only. I beg your pardon if any wrong I did
18th Apr 2021, 4:30 PM
Atul [Inactive]
0
Why float to int?
18th Apr 2021, 4:45 PM
Chris Güler
Chris Güler - avatar
0
because you won't pass the tests. you will have the result with a decimal part. and the answer must be a whole. do you know how to do this? and you found your mistake in the formula?
18th Apr 2021, 4:53 PM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
0
So I solved the main problem. But test case 3 and 4 are almost hidden. import java.util.Scanner; public class LearningJava { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int colors = scanner.nextInt(); int costs = (40 + 5 * colors); int tax = costs*10/100; int cost = tax + costs; System.out.println(cost); } }
18th Apr 2021, 6:29 PM
Chris Güler
Chris Güler - avatar
0
most likely, the data should be float, but the final result, according to the conditions of the problem, should be rounded to the nearest integer. make all the values float (so that there is something to round). round the final result to the nearest integer
18th Apr 2021, 8:44 PM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
0
First do all tasks in double or float but atlast round of it ceiling value
19th Apr 2021, 3:26 AM
Atul [Inactive]
0
Thank you. It worked. But can you explain me more exact, why float and not int?
19th Apr 2021, 9:00 AM
Chris Güler
Chris Güler - avatar
0
Hope this helps you
19th Apr 2021, 9:18 AM
Atul [Inactive]
0
Bcoz rezult must be rounded to the nearest int
19th Apr 2021, 9:34 AM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
0
"Output Format A number that represents the cost of your purchase rounded up to the nearest whole number."
19th Apr 2021, 9:35 AM
Yaroslav Vernigora
Yaroslav Vernigora - avatar