Question: Update: these are the 3 classes: import java.util.Optional; import java.util.Arrays; import java.util.List; import java.util.Scanner; public class Main { public static void main(final String[] args) {
Update: these are the 3 classes:
import java.util.Optional; import java.util.Arrays; import java.util.List; import java.util.Scanner;
public class Main {
public static void main(final String[] args) { final Team t1 = new Team("USA", "Sarachan", 500); final Team t2 = new Team("Chile", "Rueda", 600); final Team t3 = new Team("Germany", "Lw", 700); final Team[] array = {t1, t2, t3}; final List
final Scanner keyboard = new Scanner(System.in);
// Get team name System.out.print("Enter name to search: "); final String key = keyboard.nextLine(); System.out.println("Looking for team " + key);
// Runs the linear search on the array final Optional
// Get funding level System.out.print("Enter min funding to search: "); final String fundingString = keyboard.nextLine(); final int funding = Integer.parseInt(fundingString); System.out.println("Looking for min funding " + funding); // Runs the linear search on the array final Optional
// Runs the binary search on the array final Optional
------------------------------------------------------------------------------------------------------------------------------.
import java.util.List; import java.util.Optional;
public class Search {
/** Looks for the position of the named team in an array. */ public static Optional
/** Looks for the position of the named team in a list. */ // Optional genraic meaning there is a value attached to it " Generic in the element type" // Why not bolean, bucause bolean doesnt allow us to find an interger // why not int, "we could get away with it if its >=0 && <0 is a failure"> findTeamPosition(final List
return Optional.empty(); } /** * Looks for the position of the poorest team that has at least * the specified funding level. * Uses binary search: Initially consider the entire index range, * then repeatedly eliminate the wrong half of the array until * zero or one items are left. * @pre arr is sorted * @post arr[result].funding >= minFunding && for all 0 <= i < result : arr[i].funding < minFunding */ public static Optional ----------------------------------------------------------------------------------------------- /** A sports team. */ public class Team { /** The team's name. */ private String name; /** The team's head coach. */ private String headcoach; /** The team's monetary funding level in thousands of US$. */ private int funding; /** Constructs a new team. */ public Team(final String name, final String headcoach, final int funding) { if (name == null) { throw new IllegalArgumentException("name is null"); } // TODO validity checking for headcoach // TODO validity checking for funding this.name = name; // TODO complete this constructor } /** Returns the team's name. */ public String getName() { return this.name; } /** Returns the team's head coach. */ public String getHeadcoach() { // TODO complete this method return null; } /** Returns the team's funding level. */ public int getFunding() { // TODO complete this method return -1; } } ---------------------------------------------------------------. package edu; import org.junit.Test; import static org.junit.Assert.*; public class TestSearch { Team[] makeArrayFixture(final int size) { final Team[] array = new Team[size]; for (int i = 0; i < size; i++) { final String s = Integer.toString(i); array[i] = new Team("Team " + s, "Coach " + s, i * 100 + 50); } return array; } // TODO makeListFixture @Test public void testFindPositionArray0() { final Team[] arr = makeArrayFixture(0); assertFalse(Search.findTeamPosition(arr, "Team 5").isPresent()); } @Test public void testFindPositionArray10s() { final Team[] arr = makeArrayFixture(10); assertTrue(Search.findTeamPosition(arr, "Team 5").isPresent()); } @Test public void testFindPositionArray10f() { final Team[] arr = makeArrayFixture(10); assertFalse(Search.findTeamPosition(arr, "Team 11").isPresent()); } // TODO: testFindPositionList0, 10s, 10f // TODO: testFindMinFundingArray for several sizes and scenarios // TODO: testFindMinFundingArrayFast for several sizes and scenarios } How DO I DO the //TODO CODE?
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
