Question

package week_4; import static input.InputUtils.*; /** * You are a runner, and you are in training...

package week_4;

import static input.InputUtils.*;

/**
 *
 You are a runner, and you are in training for a race. You'd like to keep track of all of your
 times for your training runs. You only like to run around lakes. Here's some example data.
 
 For this program, we'll assume that these are decimal values of minutes, not minutes and seconds,
 and the math will be more straightforward.
 
 
 Cedar, 45.15
 Cedar, 43.32
 Harriet, 49.34
 Harriet, 44.43
 Harriet, 46.22
 Como, 32.11
 Como, 28.14

 Write a program that enables you to enter the names of lakes and times, and store it all of this
 data in data structure(s).
 
 Your data structure should save EVERY time entered for each lake.

 Don't store it in individual variables. Your program should still work if you started running
 around another lake too (e.g. Lake of the Isles, or Lake Phalen).

 Your program should be able to analyze the data that you have stored.
 
 You should be able to print your fastest time for each lake you ran around.
 So, for the data above, your program will calculate something like

 Cedar, 43.32
 Harriet, 44.43
 Como, 28.14

 You should also be able to calculate the average time. So, for the same data as above,
 your program will calculate something like this (you may truncate, or round numbers to 2 decimal places)
 Again, we'll assume that these are decimal values of minutes, so you can figure out the regular average of the numbers.
 
 Cedar, 44.23
 Harriet, 46.66
 Como, 30.12
 
 Your program should be case-insensitive. So "Como" is the same lake as "como" or "COMO".

 
 Print all of the the data - Lake Name, Average, and Fastest Time, in a table.
 
 
 Your program should use the generic types of data structures.
 You should use methods to organize your program.
 Hint: you may need to combine more than one type of data structure.
 
 

 */
public class Question_5_Lake_Running {

    // TODO create a global data structure to store all of your lakes and times here.
    // You methods will read and write to this data structure.


    public static void main(String[] args) {
        new Question_5_Lake_Running().running();
    }

    public void running() {

        while (moreLakes())  {
            String name = stringInput("Enter lake name");
            double time = positiveDoubleInput("Enter time for running lake " + name);
            addLake(name, time);
        }

        printReportForAllLakes();

    }




    public void printReportForAllLakes() {

        // TODO read data from your data structure, and print the average and fastest time for each lake.
        /* Your output should look something like this, with the average, followed by the fastest.

        Lake       Average      Fastest
        Cedar      44.23        43.32
        Harriet    46.66        44.43
        Como       30.12        28.12


        */

        // Use the fastestTimeForLake method, and averageTimeForLake method to help.


    }


    public double fastestTimeForLake(String lakeName) {
        // TODO read data from your data structure, and find the fastest time for the lake of this name.

        // Your lake name should not be case sensitive. "Como" is the same as "como".

        // If the lake is not in your data structure, return -1 to indicate it was not found.

        return 0; // replace with your code

    }


    public double averageTimeForLake(String lakeName) {
        // TODO read data from your data structure, and find the average time for the lake of this name.

        // Your lake name should not be case sensitive. "Como" is the same as "como".

        // If the lake is not in your data structure, return -1 to indicate it was not found.

        return 0; // replace with your code

    }



    public void addLake(String name, double time) {
        // TODO Add the data for this lake to your data structure
        // Your lake name should not be case sensitive. "Como" is the same as "como".
    }




    // You don't need to modify this method.
    private boolean moreLakes() {
        return yesNoInput("More lake data to add?");
    }


}
0 0
Add a comment Improve this question Transcribed image text
Answer #1
import java.util.ArrayList;
import java.util.TreeMap;

public class Question_5_Lake_Running {

    private TreeMap<String, ArrayList<Double>> timings = new TreeMap<>();

    public static void main(String[] args) {
        new Question_5_Lake_Running().running();
    }

    public void running() {

        while (moreLakes()) {
            String name = stringInput("Enter lake name");
            double time = positiveDoubleInput("Enter time for running lake " + name);
            addLake(name, time);
        }

        printReportForAllLakes();

    }

    public void printReportForAllLakes() {

        /*
         * Your output should look something like this, with the average, followed by
         * the fastest.
         * 
         * Lake Average Fastest Cedar 44.23 43.32 Harriet 46.66 44.43 Como 30.12 28.12
         * 
         */

        // Use the fastestTimeForLake method, and averageTimeForLake method to help.
        System.out.printf("%-15s%-16s%-16s\n", "Lake", "Average", "Fastest");
        for (String name : timings.keySet()) {
            System.out.printf("%-15s%-16.2f%-16.2f\n", name, averageTimeForLake(name), fastestTimeForLake(name));
        }

    }

    public double fastestTimeForLake(String lakeName) {
        // Your lake name should not be case sensitive. "Como" is the same as "como".

        // If the lake is not in your data structure, return -1 to indicate it was not
        // found.

        String name = lakeName.toLowerCase();
        if (!timings.containsKey(name)) {
            return -1;
        }

        double min = timings.get(name).get(0);
        for (double t : timings.get(name)) {
            if (t < min) {
                min = t;
            }
        }
        return min;
    }

    public double averageTimeForLake(String lakeName) {
        // Your lake name should not be case sensitive. "Como" is the same as "como".

        // If the lake is not in your data structure, return -1 to indicate it was not
        // found.
        String name = lakeName.toLowerCase();
        if (!timings.containsKey(name)) {
            return -1;
        }

        double sum = 0.0;
        for (double t : timings.get(name)) {
            sum += t;
        }
        return sum / timings.get(name).size();
    }

    public void addLake(String name, double time) {
        name = name.toLowerCase();
        if (!timings.containsKey(name)) {
            timings.put(name, new ArrayList<>());
        }
        timings.get(name).add(time);
    }

    // You don't need to modify this method.
    private boolean moreLakes() {
        return yesNoInput("More lake data to add?");
    }

}


Hi. Please find the answer above.. In case of any doubts, you may ask in comments. You may upvote the answer if you feel i did a good work!

Add a comment
Know the answer?
Add Answer to:
package week_4; import static input.InputUtils.*; /** * You are a runner, and you are in training...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • package week_4; import input.InputUtils; import java.lang.reflect.Array; import java.util.ArrayList; import java.util.Random; import static input.InputUtils.positiveIntInput; import static input.InputUtils.yesNoInput;...

    package week_4; import input.InputUtils; import java.lang.reflect.Array; import java.util.ArrayList; import java.util.Random; import static input.InputUtils.positiveIntInput; import static input.InputUtils.yesNoInput; /** Write a program to roll a set of dice. Generate a random number between 1 and 6 for each dice to be rolled, and save the values in an ArrayList. Display the total of all the dice rolled. In some games, rolling the same number on all dice has a special meaning. In your program, check if all dice have the same value,...

  • package week_3; import java.util.Scanner; import java.util.*; //import java.lang.*; //import java.io.*; /** Write a program that can...

    package week_3; import java.util.Scanner; import java.util.*; //import java.lang.*; //import java.io.*; /** Write a program that can help decide if a particular programming project is best solved using a Waterfall or Agile methodology. Your program should ask the user: • How many programmers will be on the team [ More than 30 programmers -> Waterfall ] • If there needs to be firm deadlines and a fixed schedule [ Yes - > Waterfall ] • If the programmers have experience in...

  • package week_3; /** Write a program that can help decide if a particular programming project is...

    package week_3; /** Write a program that can help decide if a particular programming project is best solved using a Waterfall or Agile methodology. Your program should ask the user: • How many programmers will be on the team [ More than 30 programmers -> Waterfall ] • If there needs to be firm deadlines and a fixed schedule [ Yes - > Waterfall ] • If the programmers have experience in requirements, analysis and testing as well as coding...

  • Fix this program package chapter8_Test; import java.util.Scanner; public class Chapter8 { public static void main(String[] args)...

    Fix this program package chapter8_Test; import java.util.Scanner; public class Chapter8 { public static void main(String[] args) { int[] matrix = {{1,2},{3,4},{5,6},{7,8}}; int columnChoice; int columnTotal = 0; double columnAverage = 0; Scanner input = new Scanner(System.in); System.out.print("Which column would you like to average (1 or 2)? "); columnChoice = input.nextInt(); for(int row = 0;row < matrix.length;++row) { columnTotal += matrix[row][columnChoice]; } columnAverage = columnTotal / (float) matrix.length; System.out.printf("\nThe average of column %d is %.2f\n", columnAverage, columnAverage); } } This program...

  • import java.util.Scanner; import class17.HeapPriorityQueue; import class17.PriorityQueue; /*************** * Homework D * * * Remove any initial...

    import java.util.Scanner; import class17.HeapPriorityQueue; import class17.PriorityQueue; /*************** * Homework D * * * Remove any initial package declaration that might be added to your file in * case you edit it in eclipse. * * The goal of the homework is to create two ArrayList based implementations of * a Priority Queue as explained in Section 9.2 (in 9.2.4 and 9.2.5) of the * textbook. * * These are to be made by completing the classes PQunsorted and PQsorted as...

  • For this project you will be writing up a simple Clock program to keep track of...

    For this project you will be writing up a simple Clock program to keep track of time. SimpleClock.java - contains your implementation of the SimpleClock class. You will need to provide the code for a constructor as well as the mutator methods set and tick and the accessor method toString. Look at the comments for each method to see how they should be implemented - the trickiest method is probably tick, which requires that you deal with the changing of...

  • Solver.java package hw7; import java.util.Iterator; import edu.princeton.cs.algs4.Graph; import edu.princeton.cs.algs4.BreadthFirstPaths; public class Solver {    public static...

    Solver.java package hw7; import java.util.Iterator; import edu.princeton.cs.algs4.Graph; import edu.princeton.cs.algs4.BreadthFirstPaths; public class Solver {    public static String solve(char[][] grid) {        // TODO        /*        * 1. Construct a graph using grid        * 2. Use BFS to find shortest path from start to finish        * 3. Return the sequence of moves to get from start to finish        */               // Hardcoded solution to toyTest        return...

  • departmentstore: package departmentstorepkg; import java.util.ArrayList; public class DepartmentStore {    private static final int DEFAULT_SIZE =...

    departmentstore: package departmentstorepkg; import java.util.ArrayList; public class DepartmentStore {    private static final int DEFAULT_SIZE = 10; private StaffMember [] myEmployees; private int myNumberEmployees; private String myFileName; private StaffMember[] employee; public DepartmentStore (String filename){ myFileName = filename; myEmployees = employee;    } public String toString(){ return this.getClass().toString() + ": " + myFileName; } public void addEmployee(Employee emp){ } /** * prints out all the employees in the array list held in this class */ public void print(){ for(int i =...

  • Language is Java, any help is appreciated. Thank you! WHERE TO START FROM: import java.util.ArrayList; //PartTest.java...

    Language is Java, any help is appreciated. Thank you! WHERE TO START FROM: import java.util.ArrayList; //PartTest.java //package simple; public class PartTest { public static void main(String[] args) { ArrayList<ExpendablePart> system=new ArrayList<ExpendablePart>();   // creating Part Object Part part1 = new ExpendablePart("Last, First"); part1.setNumber("AX-34R"); part1.setNcage("MN34R"); part1.setNiin("ABCD-RF-WDE-KLJM"); // printing information System.out.println(part1.toString());       //Create a part2 object of class Part Part part2=new ConsumablePart("Widget, purple"); part2.setNumber("12345"); part2.setNcage("OU812"); part2.setNiin("1234-12-123-1234");    // printing information System.out.println(part2.toString());    //checking equality of two Part class objects if(part1.equals(part2)) System.out.println("part1 and...

  • Java debugging in eclipse package edu.ilstu; import java.util.Scanner; /** * The following class has four independent...

    Java debugging in eclipse package edu.ilstu; import java.util.Scanner; /** * The following class has four independent debugging * problems. Solve one at a time, uncommenting the next * one only after the previous problem is working correctly. */ public class FindTheErrors { public static void main(String[] args) { Scanner keyboard = new Scanner(System.in); /* * Problem 1 Debugging * * This problem is to read in your first name, * last name, and current year and display them in *...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT