Lab two solution

Rewriting lab two with methods

In today's lab exercise we are going to redo the program I had you write for lab two. This time around we are going to make use of several methods to solve the problem.

As the starting point for your work I have provided my solution for lab two above. You will be rewriting this program to make use of several methods.

What to do

In this lab exercise you are going to write the code for four methods. Then, you are going to write code in your main method that calls these methods to solve the postage problem from lab two.

The first method you are going to write is

public static boolean isOversized(double length,double height,double weight)

This method takes the dimensions and weight of an item as its parameters and returns true if the item is oversized and false if the item is normal sized.

The second method you will write is

public static int normalPostage(double weight)

This method computes the postage for a normal sized item based on its weight. This method should return the postage as an integer number of cents. For example, if a normal sized item weighs 2.4 ounces, this method would return a postage of 55 + (3-1)*15 = 85 cents.

The third method is

public static int oversizedPostage(double weight)

This method computes the postage for an oversized sized item based on its weight. This method should return the postage as an integer number of cents. For example, if an oversized sized item weighs 4.2 ounces, this method would return a postage of 100 + (5-1)*20 = 180 cents.

The fourth method is

public static int stampsNeeded(int postage)

This method computes and returns the number of 55 cent stamps needed to meet or exceed the given amount of postage. For example, for an item with a postage of 180 cents this method would return 4, because 3*55 = 165 and 4*55 = 220.

Once you have written the code for these methods, you will write code in your main method that calls these methods to determine the postage of the item and how many stamps are needed to send the item.