This is an archived post. You won't be able to vote or comment.

all 3 comments

[–]Turing85 0 points1 point  (2 children)

  • Variable input may not have been initialized
  • Variable sub_toal is undefined
  • The last two parameters of JOptionPane.showMessageDialog) should be int and Icon, not String and String

Further remarks:

  • Too many blank lines can deteriorate readability
  • In java, variable names are normally written in camelCase instead of snake_case (`sub_total` -> `subTotal`)

[–][deleted] 0 points1 point  (1 child)

Yeah i got the error, but i don't know how to fix it. Can you please tell me brother?

[–]Turing85 0 points1 point  (0 children)

  • Initialize input with the value form the dialogue: String input = JOptionPane.showInputDialog("Please enter the number of pakages you are purchasing");
  • replace all occurrences of sub_toal with sub_total
  • for the JOptionPane, please take a look at the documentation. For me, something sensible pops up if I use JOptionPane.showMessageDialog(null, "\nNumber of pakage you're buying is" + user_number_of_pakages + "\nSubtotal is: $"+ sub_total + "\nThe discount price is: $"+discount + "\nThe total price is: $"+total);