Programming Drill #15

Due: Monday, November 5
Goal:  Use an array of objects

Listed below is our old Beer class.    In the main method is some code that stores 4 types of Beer in an array. Complete the code in the main method so it outputs the name of the beer with the highest percentage of alcohol. The code should use a loop to find the beer with the highest percentage, so if the array of beers is changed to something else the program should still correctly output the beer with the highest percentage. .

public class Beer
{
	private String name;
	private double alcohol;

	// Constructors
	public Beer()
	{
		name = "Generic Brand";
		alcohol = 0.05;
	}

	public Beer(String newName, double newAlcohol)
	{
		name = newName;
		alcohol = newAlcohol;
	}

	// Accessors
	public String getName()
	{
		return name;
	}
	public double getAlcohol()
	{
		return alcohol;
	}
	// Mutators
	public void setName(String newName)
	{
		name = newName;
	}
	public void setAlcohol(double newAlcohol)
	{
		alcohol = newAlcohol;
	}

	// How many drinks a person of "weight" can drink before intoxicated
	public double intoxicated(double weight)
	{
		double numDrinks;
		// This is a simplification of the Widmark formula
		numDrinks =  (0.08 + 0.015) * weight / (12 * 7.5 * alcohol);
		return numDrinks;
	}


	/////////////////////////////////////////////////////////////////
	// Main Method
	/////////////////////////////////////////////////////////////////

	public static void main(String[] args)
	{
		// Array to hold 4 Beer objects
		Beer[] drinks = new Beer[4];

		// Create a Beer object and put it into the array.  Note that we have to
		// create a "new" Beer object before adding it into the array
		drinks[0] = new Beer("Guiness",0.074);
		drinks[1] = new Beer("Sam Adams Triple Bock", 0.175);
		drinks[2] = new Beer("Alaskan Amber", 0.05);
		drinks[3] = new Beer("Bud Light", 0.042);

		// *** TO DO HERE ***
		// Make a loop that goes through the array of Beer objects and
		// remembers the beer with the highest percentage of alcohol and
		// the name of the beer with the highest percentage of alcohol.
		// After the loop is over, output the name of the beer.  In the example
		// above, it would output Sam Adams Triple Bock.  But your code should
		// work for any array of Beers, for example, if Bud Light had 0.18 percent
		// alcohol, then your code would have output Bud Light instead.


	}
}
    

Show your completed program to your instructor or email it to kenrick@uaa.alaska.edu by the end of the day.