Skip to content

Instantly share code, notes, and snippets.

@claraj
Created March 15, 2017 16:52
Show Gist options
  • Save claraj/e72c8815d98f43ffc4a92ffd68eb1dd8 to your computer and use it in GitHub Desktop.
Save claraj/e72c8815d98f43ffc4a92ffd68eb1dd8 to your computer and use it in GitHub Desktop.
/** LakeRunMain.java */
package Lakes;
/* Will create RunningLaps objects and store them in a list
*
* Will ask the user for input
*
* Will print out data, like the fastest time for each lake
*
* */
import java.util.Scanner;
public class LakeRunMain {
static Scanner stringScanner = new Scanner(System.in);
static Scanner numberscanner = new Scanner(System.in);
//todo make list of RunningLaps objects, and store all of your RunningLakes.
// todo or a HashMap<String, RunningLaps> with keys == lakeNames.
public static void main(String[] args) {
// todo a loop that asks the user for input (lake, time for that lake), until they are done.
System.out.println("What is the name of the lake you are running around?");
String name = stringScanner.nextLine();
System.out.println("What was the time for your run?");
double time = numberscanner.nextDouble();
RunningLaps newLake = new RunningLaps(name, time);
System.out.println("RunningLaps created for this lake and time ");
System.out.println("(Assuming you ran this lake again, What was the time for your next run?");
time = numberscanner.nextDouble();
newLake.addNewTime(time);
}
}
/* New file; RunningLaps.java */
package Lakes;
/*
* This class represents all of the times for one lake.
* It will store the lake name and a list of times (0 or more) for that lake.
*
* And, calculate the best time.
* */
import java.util.LinkedList;
public class RunningLaps {
private String name;
private LinkedList<Double> times;
RunningLaps(String name, Double time){
// Initialize times list
times = new LinkedList<Double>();
// Set this object's name to the name provided
this.name = name;
// Add time to times list
times.add(time);
}
public void addNewTime(double newTime) {
times.add(newTime);
}
public double getBestTime(){
return 0; //todo replace with code to figure out best time
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment