Question: Program Requirements Modify the program you wrote for Java Assn 3, as follows: 1. Define an additional Java class (File | New File | Java

Program Requirements Modify the program you wrote for Java Assn 3, as follows: 1. Define an additional Java class (File | New File | Java Class) named: Drinker Within the Drinker class, define the following private data fields to store properties about the person drinking: * drinker identifier (String) new! * weight in kilograms * height in meters * number of drinks consumed * elapsed time since drinking began in hours Remember that all private data fields defined at the class-level can be accessed by any method within the same class (without parameter passing). Also within the new Drinker class, you will define instance methods that can be used with an object of the Drinker class, as follows: *Define a default constructor with no parameters that will create the object with the following initial data values set: Drinker identifier set to "" (an empty String) Height and weight, both set to 0.0 Number of drinks consumed and elapsed time, both set to 0 *Create setters for each data field, as follows: o Setter for drinker identifier *Input parameters will be two Strings: *the drinkers last name *the drinkers 10-digit phone number, including dashes (e.g. 333-333-3333) *Use the built-in Java String methods to uppercase the last name, and then extract the first 3 letters of the last name and concatenate them with the last 4 digits of the phone number to create a unique identifier for the drinker. *Set the data field to this value. o Setter for weight *Input parameter will be weight in pounds * Define and use a local constant: the number of pounds in one kilogram (2.20462) * Method will convert the parameter weight to kilograms and then set the weight data field to that value. o Setter for height * Input parameter will be height in inches * Define and use a local constant: the number of inches in one meter (39.3701) * Method will convert the parameter height to meters and then set the height data field to that value. o Setter for number of drinks consumed * No input parameters * Use descriptive prompt and read number of drinks consumed * Set the data field to the value input by user o Setter for hours elapsed since drinking started * No input parameters * Use descriptive prompt and read hours passed while consuming the drinks * Set the data field to the value input by user * Create getters for the following data fields in the Drinker class. o Get the drinker identifier o Getter for number of drinks consumed o Getter for hours elapsed since drinking started Each getter should return the data fields current value. * Move the volume distribution calculation (methods 2 and 3) in Java Assn 3 from the BACcalculator class to the new Drinker class. Then modify the methods, so they can be used as instance methods in the new Drinker class, as follows: o Eliminate the static keyword (since they will now be used with objects) o Eliminate the parameter lists (since they will now use data fields). o Modify the formulas, so that they will directly use the object data fields, instead of parameters. * Move the BAC calculation (method 4) in Java Assn 3 from the BACcalculator class to the new Drinker class. This method will be modified to calculate and display the BAC, instead of returning the BAC. Modify the method, as follows: o Change the method header to indicate nothing will be returned. o Eliminate all parameters, except the volume distribution and metabolic rate to use. o Add a third parameter: * a gender string (which will contain either male or female) o Modify the conversion formula to convert the data field weight in kilograms to grams (instead of the previous conversion from pounds to grams) and store the new value. Then use the new value in the BAC formula. o After calculating the current BAC, display a description, including the gender, and the BAC value to 3 decimal places. Only one line will be displayed (see next page for examples). * NOTE: No decision statements will be necessary to do this! For example, if the gender parameter contains the word male and the current BAC is 0.0933333333, the output will be: But if the gender parameter contains the word female the output will be: a male has a current BAC of approximately 0.093 a female has a current BAC of approximately 0.093 2. Within the original BACcalculator class that contains the main method: *Make sure you deleted the old static calculation methods (2 4) from the BACcalculator class when you moved them to the Drinker class.

*Modify the assignment 3 static method (5) so that it will display only the drinkers information. The method will: o Have three parameters: * the Drinker object * the previously read height in inches * the previously read weight in pounds o Use the Drinker object and a getter to display the drinker identifier o Display the Drinkers height in inches and weight in pounds (originally read from user) o Use the Drinker object and the getters to display the number of drinks consumed and the elapsed time while drinking. Sample of Output from this method * Modify the main method to perform the following tasks (modified from Java Assn 3): o Remove the constants for converting the height and weight, since they are now located in the setters (but keep the metabolic rate constants). o After displaying program description, create an object of the new Drinker class type. o Use descriptive prompts to read: * the drinkers last name (you can assume there will be no spaces in the last name and that it will contain at least 3 letters). * the drinkers phone number o Same as in assn 3, use descriptive prompts to read: height in inches and weight in pounds. Sample Input read from main method o Use the Drinker object and the setters to set the values for all of the data fields of the object: * Be sure to pass any necessary parameters to the setters. * Note that the setters for the number of drinks and time elapsed will prompt the user for input. o After setting all the data fields, display a couple of blank lines to separate input and output. Enter the drinkers last name: Smith Enter the drinkers phone number: 222-222-2222 Enter drinker's height (in inches): 70 Enter the drinker's weight (in pounds): 180 Calculations for Drinker XYZ2345, who is 66 inches tall and weighs 150 pounds. After drinking 6 drinks, in 3 hours: o Using the Drinker object: * Call the volume distribution calculation method for men (method 2) to compute the volume distribution for men and save the result returned. * Call the volume distribution calculation method for women (method 3) to compute the volume distribution for women and save the result returned. o Call the static method to display the drinkers information. o Use the Drinker object to call the instance method to calculate and display the BAC twice: * The first call should pass in male as the gender String, the volume distribution computed for men, and the metabolic rate for men. * The second call should pass in female as the gender String, the volume distribution computed for women, and the metabolic rate for women. The main method code should not directly calculate any results, nor display any drinker information or BAC information. All this should be done from within methods that are called by the main method. Complete Sample Output Output from static method that displays drinker info Output line from first call to calculate and display BAC instance method Output line from second call to calculate and display BAC instance method Calculations for Drinker SMI2222, who is 70 inches tall and weighs 180 pounds. After drinking 4 drinks, in 2 hours: if male, current BAC is approximately 0.067 if female, current BAC is approximately 0.096

BAC CALCULATION METHOD

Anonymous answered this

Was this answer helpful?

1

0

2,599 answers

Anonymous

2,599 answers

import java.util.Scanner;

public class WilsonBACCalculator { // /** // * Main method, instantiates a scanner for input, sets some constants for calculations // * and calls the class methods for calculating // * @param args, the command line arguments // */ public static void main(String[] args) { // // set constant local vars for final double LBS_IN_KG = 2.20462D; final double INCHES_IN_METER = 39.3701D; final double MALE_METABOLIC_RATE = 0.015D; final double FEMALE_METABOLIC_RATE = 0.014D; // call description method describeProgram(); // // get input without type checking Scanner scanner = new Scanner(System.in); System.out.println("Please enter the person's height in inches: "); double height = scanner.nextDouble(); System.out.println("Please enter the person's weight, in pounds: "); double weight = scanner.nextDouble(); System.out.println("Please enter number of drinks consumed: "); int drinksConsumed = scanner.nextInt(); System.out.println("Please enter number of WHOLE hours elapsed since first drink was consumed: "); int hoursElapsed = scanner.nextInt(); // // convert weight to kg, and height to meters double heightMeters = height / INCHES_IN_METER; double weightKgs = weight / LBS_IN_KG; // // get volumes for both genders double maleVol = calculateMenVolume(weightKgs, heightMeters); double femaleVol = calculateWomenVolume(weightKgs, heightMeters); // get current BAC for both genders double maleCurrent = calculateCurrentBAC(weight, maleVol, MALE_METABOLIC_RATE, drinksConsumed, hoursElapsed); double femaleCurrent = calculateCurrentBAC(weight, femaleVol, FEMALE_METABOLIC_RATE, drinksConsumed, hoursElapsed); // display results displayResults(drinksConsumed, hoursElapsed, maleCurrent, femaleCurrent);

} // // /** // * Program description method, simply states what will be done // */ public static void describeProgram() { System.out.println("This program will calculate and show current BAC"); System.out.println("Based upon height, weight, and gender, drinks, and hours, the program will calculate BAC at this time:");

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!