Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Book Club Points

  1. #1
    Junior Member
    Join Date
    Jul 2014
    Posts
    2
    My Mood
    Amazed
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Book Club Points

    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;
        }
    }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Book Club Points

    Do you gave any specific questions about your assignment?
    What problems are you having?
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Jul 2013
    Posts
    8
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Default Book Club Points

    As Norm says you haven stated what problems your having.

    But looking through your code - I would have another "else if" statement for numberofbooks == 4, and then have another else as an invalid number entered. That's what I would do if it were me.

Similar Threads

  1. [SOLVED] Club Membership Registration client-server database problem
    By hofamilyiiii in forum What's Wrong With My Code?
    Replies: 0
    Last Post: April 21st, 2014, 04:24 AM
  2. Replies: 1
    Last Post: November 6th, 2013, 02:48 AM
  3. Is it possible to print a spade, club, heart, or diamond in java?
    By BC2210 in forum Java Theory & Questions
    Replies: 1
    Last Post: October 2nd, 2009, 08:35 PM