Many of the FRQs on the AP exam contain a table which shows output or return values from methods in a class. In these practice exercises, you will be given a table that shows method calls and their output. You will need to write a class with the described methods that will produce the output shown in the table. Thank you to Sam Procopio from Bishop Blanchet High School in Seattle, WA, for these exercises.
Based on the table below, write a complete class called Book that has the appropriate instance variables and methods to produce the output described in the table.
Write a class called Present that describes a gift for an occasion. Use the method calls in the main method below to create the appropriate instance variables and methods for the Present class.
public static void main(String[] args)
{
//creates a Present object
Present gift = new Present("Birthday", 29.99, "Legos");
//prints out the gift name and cost
System.out.println("The gift is " + gift.getName()
+ ", and it costs $" + gift.getPrice() );
// prints out the reaction "Wow!"
System.out.println("The reaction when opening the gift was "
+ gift.reaction() );
// Prints out "Purchased at local store"
gift.purchasedAt("local store");
}
}
Activity3.16.3.
Write the class Present below with the appropriate instance variables, constructor, and methods described in main method.