Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

CSC120 2023S Lab No.4 Comparison Instructor: Mitsu Ogihara The goal of this lab is to write a program that compares four people using three quantities

image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
CSC120 2023S Lab No.4 Comparison Instructor: Mitsu Ogihara The goal of this lab is to write a program that compares four people using three quantities about them. The user provides the name, the height in inches, and the weight in pounds for the four people. Then the program ranks the four people in the increasing order of height, in the increasing order of weight, and in the increasing order of BMI. The information to use consists of four four-member variable groups. For the first person, the program may use four variables String name1, double height1, double veight1, and double bmi1 For the second, the third, ad the fourth persons, the program may use four variales String name2, dolible height2, double weight2, double bmi2 String name3, double height3, double veight3, double bmi3 String name4, double height 4 , double veight4, double bmi4. What the user provides are only the names, the heights, and the weights, and so the program must compute the BMI values. Recall that the formula for BMI is bmi=703,0weight/(height2) Here is an example of how the program works. The first four lines collect information from the user. The program then produces the ranking based on height, weight, and BMI. Name, Height, Weight for Person 1: Joseph 67167 Name, Height, Weight for Person 2: Greg 70170 Name, Height, Weight for Person 3: Michael 72172 Name, Height, Weight for Person 4: Nick 75175 --- Ranking by Height Joseph for 67.00 Greg for 70.00 Michael for 72.00 \begin{tabular}{r|l} 7 & Josepn ror ol. UU \\ 7 & Greg for 70.00 \\ 8 & Michael for 72.00 \\ 9 & Nick for 75.00 \\ 10 & Ranking by Weight \\ 11 & Joseph for 167.00 \\ 12 & Greg for 170.00 \\ 13 & Michael for 172.00 \\ 14 & Nick for 175.00 \\ 15 & -manking by BMI \\ 16 & Nick for 21.87 \end{tabular} Michael for 23.32 Greg for 24.39 Joseph for 26.15 Comparing Four Numbers After receiving the input and computing the BMI values, the program ranks the people in the increasing order with respect to each of the three quantities. A key method we will write is the on that will receive pairs of String and double for 2,3 , or 4 people and make the comparison among them. There are 4321=24 distinct orderings of 4 items, and so we may need to identify the After receiving the input and computing the BMI values, the program ranks the people in the increasing order with respect to each of the three quantities. A key method we will write is the on that will receive pairs of String and double for 2,3 , or 4 people and make the comparison among them. There are 4321=24 distinct orderings of 4 items, and so we may need to identify the 24 cases. However, we can determine the ordering in a different way. 1. Find the minimum of the four, report the minimum, remove the minimum from consideration. 2. Find the minimum of the remaining three, report the minimum as the 2 nd smallest, remove the minimum from consideration. 3. Find the minimum of the remaining two, report the minimum as the 3rd smallest, and report the other as the 4 th smallest. We give these tasks to three separate methods, find1st (),f ind2nd () , and find3rdAnd4th. The headers of the three methods can He as follows: public static void find1st ( String 1, double a1, String 2, double a2, String 3, double a3, String 4, double a4) \& public static void find2nd( String 1, double a1, String 2, double a2, String 3, double a3) \{ public static void find3rdAnd 4 th( String 1, double a1, String 2, double a2) \{ For f ind1st () , we first obtain the minimum of the four doubles. The global minimum is the , minimum of the minimum of the first two and the minimum of the last two. Then, we execute the following: - If the global minimum is equal a1, state the first pair (the name and the value) and then call find2nd() with the remaining three pairs. 2 - Otherwise, if the global minimum is equal to a2, state the second pair (the name and the value) and then call find2nd( ) with the remaining three pairs. - Otherwise, if the global minimum is equal to a3, state the third pair (the name and the value) and then call f ind2nd() with the remaining three pairs. - Otherwise, state the fourth pair (the name and the value) and then call find2nd() with the remaining three pairs. We can write find2nd() with a similar idea, which states the global minimum of the three and calls find3rdAnd4th() with the remaining two pairs. The action of find3rdAnd4th() is to find the smaller of the two, state the smaller and then state the other. Report the name and data of a pair, write a method report that takes the two parameters and executes System, out.printf( " % s for %.2f%n",x, a ); System. out,printf( "% for %.2f%n,x, a ) where x is the String parameter and a the double parameter. For example, if x1 has "Joseph" as its value and a1 has 176.0 as its value, a call to report (x1, a1 ) will produce Joseph for 167.00 The diagram below shows how f ind 2 nd may operate. String 1, double a1, Strina 2 2 double a2. The design for find1st may follow the same structure with an additional branch and the design for find3rdAnd4th may follow the same structure with one fewer branch with each of the bottom boxes replaced with a call to report ()

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

What is what-is analysis?

Answered: 1 week ago