+ 2

Guys can you fix my code .. i dont know what is the problem with it..

import java.util.Scanner; public class GrossBill { public static void main(String[] args) { double servicecharge; double salestax; double grossbill; double netbill; double amount; double change; Scanner keyboard = new Scanner(System.in); System.out.print("Enter the Grossbill."); servicecharge = 0.12 * grossbill; salestax = 0.07 * grossbill; grossbill = keyboard.nextDouble(); keyboard.nextLine(); System.out.print("Enter your Money."); amount = keyboard.nextDouble(); netbill = grossbill + servicecharge + salestax; change = amount - netbill; if (amount >= netbill) { System.out.printf("Your Net Bill is : %.2f %n", netbill); System.out.printf("Your Change is :%.2f" , change); } else{ System.out.print("Your money is not enough."); } System.exit(0); } }

3rd Oct 2020, 1:27 AM
Diether Absalon
Diether Absalon - avatar
3 odpowiedzi
+ 8
Diether Absalon Your program runs fine.. Only problem was grossbill wasn't initialised. Write it like this. grossbill = keyboard.nextDouble(); servicecharge = 0.12 * grossbill; salestax = 0.07 * grossbill; Also maybe you don't need keyboard.nextLine() ?
3rd Oct 2020, 1:46 AM
Minho
Minho - avatar
+ 7
You're welcome Diether Absalon 😊
3rd Oct 2020, 1:55 AM
Minho
Minho - avatar
+ 1
thanks man
3rd Oct 2020, 1:52 AM
Diether Absalon
Diether Absalon - avatar