All pastes #762407 Raw Edit

Someone

public text v1 · immutable
·published 2007-11-05 17:31 UTC
rendered paste body
ITCS Programming Assignment 4

This project uses concepts from chapter six in our Gaddis textbook.  You will be writing the equals( ), compareTo( ) and toString( ) methods for several classes. You will also become familiar with the has-a relationship between objects. We will talk more about this when we get back from break and I will be online over break.

Create a project that has four classes:

Book class:
	six fields:
			title:String
			author:Author
			ISBN:String
			price:double
                                    quantity: double
                                    publisher:Publisher

             one static field:
                                   static int holdings

           write a constructor that takes no arguments-sets the fields to null and 0
           write a second overloaded constructor that takes values for each of the six  fields
           and increments the holdings field
           write a setPrice( ) method
           write a changeQuantity( ) method
           write an equals( ) method that uses the ISBN to determine if two book objects are 
           the same
           write a compareTo( ) method that compares two books using the title field
           write a toString( ) method that returns a string holding the title, author, price and 
          quantity.
          write a static method called getHoldings( ) which returns the value of the static   
          holdings field

Author class:
           three fields
		       lastName:String
		       firstName:String
		       yearBorn:int

          write a constructor that takes no arguments
          write a second overloaded constructor that takes values for each of the three  fields
          write an equals( ) method that determines if two authors are the same based on all 
          three fields
          write a compareTo( ) method that compares two Author objects based on lastName 
          and then firstName (that means if two authors have the same last name, then check 
          the first names)
         write a toString( ) method that returns a string containing the values of all three 
         fields





Publisher class:
      three fields
		  publisherName:String
		  address:String
		  phoneNumber:String

     write a constructor that takes no arguments
     write a second overloaded constructor that takes values for each of the three  fields
    write an equals( ) method that determines if two Publisher objects are the same based   
     on the publisherName field
    write a compareTo( ) method that compares two Publisher objects based on  
    publisherName         
    write a toString( ) method that returns a string containing the values of all three fields

Driver class:

     This class contains the main( ) method for testing. Create three Book objects.
     Check to see if two of them are equal and then check to see if one Book object  is less   
     than or greater than the other two Book objects. Print the book info for each Book 
     object and print the number of holdings.


Where to start:

    First write the Author and the Publisher classes.
    Then you can write the Book class.
    The Book class has an Author as a field and a Publisher as a field, this is the has-a 
    relationship.

    The Book class can call the method of the other classes that are its fields.
    For example:
     public String toString( )
     {
          return title + “  “  +  author.toString( ) + “  “ +  price + “  “ + quantity;
     }

   author.toString( ) will call the toString method of the Author class.
   You can do something similar in the equals( ) and compareTo( ) methods.