- 1

Write a program to find and display an annual water tax based on the input value of water consumption

water consumption( in gallons) Tax rate( in Rs) per month more than 45 but 75 or less 475.00 more than 75 but 150 or less 750.00 more than 150 but 300 or less 1225.00 more than 300 but 350 or less 1750.00 import java.util.*; class a { public static void main () { Scanner sc=new Scanner(System.in); System.out.println("Enter amount of water consumed in gallons"); int a=sc.nextInt(); fl

22nd Jul 2021, 7:58 AM
Tanay Rastogi
Tanay Rastogi - avatar
7 Réponses
0
That would be 99.99$. 50$ advance payment and 50$ after program😄
22nd Jul 2021, 8:02 AM
Alaska
Alaska - avatar
0
import java.util.*; class a { public static void main () { Scanner sc=new Scanner(System.in); System.out.println("Enter amount of water consumed in gallons"); int a=sc.nextInt(); float t=0.0; if(a>45 && a<=75) { t=475.00; } else if(a>75 && a<=150) { t=750.00; } else if (a>150 &&a<=300) { t=12250.00; else (a>300 && a<=350) { t=1750.00; } System.out.println ("Total Tax="+t); } }//why this is not working
22nd Jul 2021, 8:06 AM
Tanay Rastogi
Tanay Rastogi - avatar
0
Main method requires an argument of type String. Put "String[] args" in main method. Logic seems good to me.
22nd Jul 2021, 8:09 AM
Alaska
Alaska - avatar
0
Alright got it. Problem is in condition after else. You shouldn't provide condition in else clause. And second, use double instead of float else it will lead to lossy conversion or you can write f behind values like t=0.0f like this. Without f java interprets it as double value and you can't assignment double to float.
22nd Jul 2021, 8:15 AM
Alaska
Alaska - avatar
0
can you please rewrite the program I didn't understand plz correct all errors and then give ans
22nd Jul 2021, 8:17 AM
Tanay Rastogi
Tanay Rastogi - avatar
- 2
https://code.sololearn.com/c71O2M0KDpeD/?ref=app This works perfectly. Additionally, try removing string args and it will say no output, I don't know reason about that. But yeah, you need string args
22nd Jul 2021, 8:20 AM
Alaska
Alaska - avatar
- 4
String args is not compulsory in main method
22nd Jul 2021, 8:10 AM
Tanay Rastogi
Tanay Rastogi - avatar