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 2 of 2

Thread: Book class help

  1. #1
    Junior Member
    Join Date
    Feb 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Book class help

    This is the last part of my program, i am fairly new to java as this is my second project. I am not exactly sure how to set the limits for the class and how to go about doing this. Anything that would help me understand nd get started would be appreciated.

    Create a book class that has number of pages (between 32 and 1,200), and a retail price (between 3.95 and 120.00). The other methods allow changing the price (with the same limits) and returning the average price per page.

    here is code so far:

    public class Book
    {
    // instance variables - replace the example below with your own
    private double retailPrice;
    private int pages;

    /**
    * Constructor for objects of class Book
    */
    public Book()
    {
    // initialise instance variables

    }

    /**
    * An example of a method - replace this comment with your own
    *
    * @param y a sample parameter for a method
    * @return the sum of x and y
    */
    public boolean setData(int pages, double retailPrice)
    {
    // put your code here
    return true;
    }

    /**
    *
    */
    public double getPrice()
    {
    return retailPrice;
    }

    /**
    *
    */
    public double getPricePerPage()
    {
    double temp = retailPrice/pages;
    return temp;
    }

    /**
    *
    */
    public boolean changePrice(double retailPrice)
    {
    return true;
    }


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

    Default Re: Book class help

    how to set the limits for the class
    Can you explain what you mean?
    Are you talking about testing the value of a variable? The if statement would be useful for that.

    Please edit your post and wrap your code with
    [code=java]
    <YOUR CODE HERE>
    [/code]
    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Replies: 2
    Last Post: November 15th, 2012, 02:58 PM
  2. need to make basic class and implementation class (base class without void main)
    By javanewbie101 in forum Object Oriented Programming
    Replies: 1
    Last Post: September 19th, 2012, 08:03 PM
  3. CLASS BOOK HELP. Please. Please.
    By ITshard in forum Object Oriented Programming
    Replies: 3
    Last Post: August 27th, 2012, 11:04 AM
  4. Class that will simulate a book catalog system
    By fatika26 in forum Object Oriented Programming
    Replies: 4
    Last Post: November 17th, 2011, 08:34 AM
  5. Replies: 6
    Last Post: July 21st, 2011, 07:45 AM