Question
Program 2 (30 points) Valid Phone Numbers.... in java Phone number can have one of several valid formats: In particular, strings like 419-460-1212 (419)460-1212 460-1212
Program 2 (30 points) Valid Phone Numbers.... in java
Phone number can have one of several valid formats: In particular, strings like
419-460-1212 (419)460-1212 460-1212
are valid but strings like
419-460 (419)460-a321 46012-12
are not. Write a program to read in a string and check whether it has the format
ddd-ddd-dddd
where each d is a digit.
Program 3 (90 points) FastestRunner.java A group of 16 students decided to run in the Columbus Marathon. Their names and times (in minutes) are below:
Name Time (minutes)
Elena | 341 |
Thomas | 273 |
Hamilton | 278 |
Suzie | 329 |
Phil | 445 |
Matt | 402 |
Alex | 388 |
Emma | 275 |
John | 243 |
James | 334 |
Jane | 412 |
Emily | 393 |
Daniel | 299 |
Neda | 343 |
Aaron | 317 |
Kate | 265 |
Find the fastest and the second fastest runner.
In particular, write a program as follows.Print the list of runners and times as above. Then print the name of the fastest runner and his/her time (in hours and minutes). Also, find the second fastest runner. Print the name and his/her time (in hours and minutes).
The program should have a method that takes as input an array of integers and returns the index corresponding to the person with the lowest time. The program should apply this method to the array of running times to find the fastest runner.
Also include a second method to find the second-best runner. The second method should use the first method to determine the best runner, and then returns the index corresponding to the person with the second lowest time.
Extra Credit (10 points): Print the list of runners and times nicely formatted in columns as displayed above. One option is to use the printf() method.
Here is some program code to get started:
class Marathon {
public static void main (String[] arguments){
final int numRunners = 16;
String[] names ={"Elena", "Thomas", "Hamilton", "Suzie", "Phil", "Matt",
"Alex", "Emma", "John", "James", "Jane", "Emily", "Daniel",
"Neda","Aaron", "Kate"};
int[] times ={341, 273, 278, 329, 445, 402, 388, 275, 243, 334, 412,
393, 299,343, 317, 265};
. . .
for (int i = 0; i < numRunners; i++) {
System.out.println(names[i]+ ": " + times[i]);
}
. . .
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started