Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

There is a theory that the being taller is an advantage in a U.S. presidential election. It contains a text file with a list of

There is a theory that the being taller is an advantage in a U.S. presidential election. It contains a text file with a list of all presidents and their heights, and also a starter program. The entries in the presidents_by_height.txt file have this format

Abraham Lincoln 6 ft 4 in 193 cm Lyndon B. Johnson 6 ft 3.5 in 192 cm 

Create a project with the files and complete the PresidentAverageHeight class to find the average height in centimeters of all US presidents to date (or 0 if the file is empty). Print with 2 decimal places.

You will use nextLine, split, and Integer.parseInt()

*****************president_by_height*******************

Abraham Lincoln 6 ft 4 in 193 cm

Lyndon B. Johnson 6 ft 3.5 in 192 cm

Donald Trump 6 ft 3 in 191 cm

Thomas Jefferson 6 ft 2.5 in 189 cm

George Washington 6 ft 2 in 188 cm

Chester A. Arthur 6 ft 2 in 188 cm

Franklin D. Roosevelt 6 ft 2 in 188 cm

George H. W. Bush 6 ft 2 in 188 cm

Bill Clinton 6 ft 2 in 188 cm

Andrew Jackson 6 ft 1 in 185 cm

Ronald Reagan 6 ft 1 in 185 cm

Barack Obama 6 ft 1 in 185 cm

James Monroe 6 ft 0 in 183 cm

John Tyler 6 ft 0 in 183 cm

James Buchanan 6 ft 0 in 183 cm

James A. Garfield 6 ft 0 in 183 cm

Warren G. Harding 6 ft 0 in 183 cm

John F. Kennedy 6 ft 0 in 183 cm

Gerald Ford 6 ft 0 in 183 cm

William Howard Taft 5 ft 11.5 in 182 cm

Herbert Hoover 5 ft 11.5 in 182 cm

George W. Bush 5 ft 11.5 in 182 cm

Grover Cleveland 5 ft 11 in 180 cm

Richard Nixon 5 ft 11 in 180 cm

Woodrow Wilson 5 ft 11 in 180 cm

Dwight D. Eisenhower 5 ft 10.5 in 179 cm

Franklin Pierce 5 ft 10 in 178 cm

Andrew Johnson 5 ft 10 in 178 cm

Theodore Roosevelt 5 ft 10 in 178 cm

Calvin Coolidge 5 ft 10 in 178 cm

Jimmy Carter 5 ft 9.5 in 177 cm

Millard Fillmore 5 ft 9 in 175 cm

Harry S. Truman 5 ft 9 in 175 cm

Rutherford B. Hayes 5 ft 8.5 in 174 cm

William Henry Harrison 5 ft 8 in 173 cm

James K. Polk 5 ft 8 in 173 cm

Zachary Taylor 5 ft 8 in 173 cm

Ulysses S. Grant 5 ft 8 in 173 cm

John Quincy Adams 5 ft 7.5 in 171 cm

John Adams 5 ft 7 in 170 cm

William McKinley 5 ft 7 in 170 cm

Benjamin Harrison 5 ft 6 in 168 cm

Martin Van Buren 5 ft 6 in 168 cm

James Madison 5 ft 4 in 163 cm

***************************************************************

**************presidentAverageHeight********************

import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner;

public class PresidentAverageHeight { public static void main(String[] args) throws FileNotFoundException { File inputFile = new File("presidents_by_height.txt"); Scanner in = new Scanner(inputFile, "UTF-8"); double total = 0; int count = 0; while (in.hasNextLine()) { String line = in.nextLine(); //Use split

} //compute the average in.close(); } }

*********************************************************

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored 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

Recommended Textbook for

DATABASE Administrator Make A Difference

Authors: Mohciine Elmourabit

1st Edition

B0CGM7XG75, 978-1722657802

More Books

Students also viewed these Databases questions