Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

16. Book Club Points Serendipity Booksellers has a book club that awards points

ID: 3900934 • Letter: 1

Question

16. Book Club Points Serendipity Booksellers has a book club that awards points to its customers based on the number of books purchased each month. The 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 pur- chased this month and then displays the number of points awarded

Explanation / Answer

CODE:

import java.util.*;
import java.lang.*;
import java.io.*;
// import takes the definition of all the pre-defined functions of a class.
// so we can use them without having to define them everytime


class Ideone
{
   public static void main (String[] args) throws java.lang.Exception
   {
       int books = 2;
       String temp = "You have earned "; // just writing this so it makes it easier to print
       System.out.print("Enter the number of book you've bought this month : ");
       Scanner reader = new Scanner(System.in); // Reading from System.in
       books = reader.nextInt(); // Scans the next token of the input as an int.
       reader.close();// closes the scanner as we don't need it anymore
       if(books > 4)// doing this so we dont need more than 1 cases for the last case( books >= 4)
            books = 4;
       System.out.println();
       switch (books)
       {
            case 0: System.out.println(temp + "0 points");
                    break;
           case 1: System.out.println(temp + "5 points");
                   break;
           case 2: System.out.println(temp + "15 points");
                   break;
           case 3: System.out.println(temp + "30 points");
                   break;
           case 4: System.out.println(temp + "60 points");
                   break;
           default: System.out.println("Invalid Data");
       }
   }
}

*******************
If you have any doubt regarding anything in this code, reply in the comments.
If every doubt is cleared, Please give a positive feedback. :)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote