RunningTheRace.java - import [email protected] Lemuel M [email protected] Book Title From Control Structures through Objects by Tony Gaddis Page

RunningTheRace.java - import [email protected]

This preview shows page 1 - 2 out of 2 pages.

import javax.swing.JOptionPane; /** * @author Lemuel M. Uhuru * @Date June 14, 2013 * Book Title: From Control Structures through Objects by Tony Gaddis * Page: 190 Problem 11: Running the Race * @Description Write a program that asks for the names of three * runner and the time, in minutes, it took each of them to finish * a race. The program should display the names of the runners in the * order that they finished. */ public class RunningTheRace { public static void main(String[] args) { // Declare variables to store user input String name1, name2, name3, time1, time2, time3; // Declare time variables to store converted // user input double t1, t2, t3; // Prompt user for the three runners names name1 = JOptionPane.showInputDialog("Enter the first runners name"); name2 = JOptionPane.showInputDialog("Enter the second runners name"); name3 = JOptionPane.showInputDialog("Enter the third runners name"); // Prompt the user for the time each runner finished the race. time1 = JOptionPane.showInputDialog("Enter the time runner 1 finished the race"); time2 = JOptionPane.showInputDialog("Enter the time runner 2 finished the race"); time3 = JOptionPane.showInputDialog("Enter the time runner 3 finished the race");
Image of page 1
Image of page 2

You've reached the end of your free preview.

Want to read both pages?

Unformatted text preview: // Convert time values to data-type double for evaluation // in decision structure. t1 = Double.parseDouble(time1); t2 = Double.parseDouble(time2); t3 = Double.parseDouble(time3); // Use decision structure to determine the order of display // for runners with the best time to the least. if (t1 > t2 && t1 > t3) { if (t2 > t3) { JOptionPane.showMessageDialog(null, "1st Place: " + name1 + "\n2nd Place: " + name2 + "\n3rd Place: " + name3); } else { JOptionPane.showMessageDialog(null, "1st Place: " + name1 + "\n2nd Place: " + name3 + "\n3rd Place: " + name2); } } else if (t2 > t1 && t2 > t3) { if (t1 > t3) { JOptionPane.showMessageDialog(null, "1st Place: " + name2 + "\n2nd Place: " + name1 + "\n3rd Place: " + name3); } else { JOptionPane.showMessageDialog(null, "1st Place: " + name2 + "\n2nd Place: " + name3 + "\n3rd Place: " + name1); } } else if (t3 > t2 && t3 > t1) { if (t2 > t1) { JOptionPane.showMessageDialog(null, "1st Place: " + name3 + "\n2nd Place: " + name2 + "\n3rd Place: " + name1); } else { JOptionPane.showMessageDialog(null, "1st Place: " + name3 + "\n2nd Place: " + name1 + "\n3rd Place: " + name2); } } } }...
View Full Document

  • Spring '08
  • Garcia,D
  • Java Programming, Java Code, The Runners, \n2nd Place, \n3rd Place

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern

Stuck? We have tutors online 24/7 who can help you get unstuck.
A+ icon
Ask Expert Tutors You can ask You can ask You can ask (will expire )
Answers in as fast as 15 minutes
A+ icon
Ask Expert Tutors