Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

WilsonWorla

  • 3 years ago

import javax.swing.JOptionPane; public class BookClubPoint { public static void main(String[] args) { // TODO code application logic here String A = "You have earned 0 points"; String B = "You have earned 5 points"; String C = "You have earned 15 points"; String D = "You have earned 30 points"; String E = "Yo have earned 60 points"; int points; String Bkacess =JOptionPane.showInputDialog(null,"Enter the number of books: "); int books = Integer.parseInt(Bkacess); if( books >= 0) JOptionPane.showMessageDialog(null, A ); else if( books >= 1 ) JOptionPane.showMessageDialog(null, B ); else if ( books >= 2 ) JOptionPane.showMessageDialog(null,C); else if ( books >= 3); JOptionPane.showMessageDialog(null,D); else JOptionPane.showMessageDialog(null, E); } } my code doesn't run, why?

  • This Question is Open
  1. larrymud
    • 3 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    remove the semicolon after if(books>=3)

  2. larrymud
    • 3 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    also: string E should start with "You" not Yo. also: your first test will be true for any number of books so you will always get 0 points. Reverse the order of books or use a switch statement that defaults to max points,.

  3. larrymud
    • 3 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Above comment should read: reverse the order of if statements

  4. larrymud
    • 3 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    int books = Integer.parseInt(Bkacess); if( books > 3) JOptionPane.showMessageDialog(null, E); else if( books == 3 ) JOptionPane.showMessageDialog(null,D); else if ( books == 2 ) JOptionPane.showMessageDialog(null,C); else if ( books == 1) JOptionPane.showMessageDialog(null, B ); else JOptionPane.showMessageDialog(null,A);

  5. e.mccormick
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    This get bumped for a reason? Still need help?

  6. Not the answer you are looking for?
    Search for more explanations.

    • Attachments:

Ask your own question

Sign Up
Find more explanations on OpenStudy
Privacy Policy