Hi i am new on this forum but i really need help with my code that i am working on i have spent over 2 hours trying to figure this out plz help me thanks in advanced here is the question
A bookseller has a book club that awards points to its customers based on the number of books they purchase each month. Points are awarded as follows:
• If a customer purchases 0 books, he or she earns 0 points.
• If a customer purchases 1 book, he or she earns 5 points.
• If a customer purchases 2 books, he or she earns 15 points.
• If a customer purchases 3 books, he or she earns 30 points.
• If a customer purchases 4 or more books, he or she earns 60 points.
Write a program that asks the user to enter the number of books that he or she has purchased this month and then displays the number of points awarded.
The program should use a switch statement.
My code is// INSERT THE CORRECT import STATEMENT FOR THE Scanner CLASS /** Chapter 3, Programming Challenge 16 Book club Points */ public class BookClubPoints { public static void main(String[] args) { // Variables int books; // Number of books purchased int points; // Points awarded // Create a Scanner object for keyboard input. // INSERT THE MISSING STATEMENT TO CREATE A Scanner object called keyboard // Get the number of books purchased this month. System.out.print("How many books have you purchased " + "this month? "); // INSERT THE MISSING STATEMENT TO RECEIVE INTEGER INPUT FROM THE keyboard into books books = keyboard.nextInt(); // Determine the number of points to award. if (books < 1) points = 0; // INSERT THREE else if AND ONE else TO COMPLETE THE points ASSIGNMENTS // Display the points earned. System.out.println("You've earned " + points + " points."); } }
and then this is the final code that i have made !!
// INSERT THE CORRECT import STATEMENT FOR THE Scanner CLASS /** Chapter 3, Programming Challenge 16 Book club Points */ public class BookClubPoints { public static void main(String[] args) { // Define variables int numberOfBooksPurchased; int pointsAwarded; // Create a Scanner object for keyboard input. Scanner keyboard = new Scanner(System.in); // Get the number of books purchased this month. System.out.print("How many books have you purchased? "); numberOfBooksPurchased = keyboard.nextInt(); keyboard.close(); // Determine the number of points to award. pointsAwarded = getPointsEarned(numberOfBooksPurchased); // Display the points earned. System.out.println("You've earned " + pointsAwarded + " points."); } /** * Method should return the number of points earned based on the number of * books purchased * * @param numberOfBooksPurchased * @return points earied */ public static int getPointsEarned(int numberOfBooksPurchased) { if (numberOfBooksPurchased < 1) { return 0; } else if (numberOfBooksPurchased == 1) { return 5; } else if (numberOfBooksPurchased == 2) { return 15; } else if (numberOfBooksPurchased == 3) { return 30; } else { return 60; } }