Last active
January 13, 2017 17:44
-
-
Save mattcunningham/6bb11758a4ab1dce9db625d166e4d08e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.ArrayList; | |
public class BaseballPlayer { | |
public ArrayList<Integer> playerStats; | |
public BaseballPlayer(int numHits, int numRuns, int numRBIs) { | |
playerStats = new ArrayList<Integer>(); | |
playerStats.add(numHits); | |
playerStats.add(numRuns); | |
playerStats.add(numRBIs); | |
} | |
public int fixPlayerList(ArrayList<String> baseballPlayers) { | |
ArrayList<String> uniques = new ArrayList<String>(); | |
int start = baseballPlayers.size(); | |
for (int i = 0; i < baseballPlayers.size(); i++) { | |
if (!uniques.contains(baseballPlayers.get(i))) { | |
uniques.add(baseballPlayers.get(i)); | |
} else { | |
baseballPlayers.remove(i); | |
i--; | |
} | |
} | |
return start - baseballPlayers.size(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.ArrayList; | |
public class FlightSchedule { | |
public ArrayList<String> scheduleList; | |
public FlightSchedule(ArrayList<String> flightScheduleList) { | |
scheduleList = flightScheduleList; | |
} | |
public void delayedFlight(int delayedIndex) { | |
this.scheduleList.add(scheduleList.remove(delayedIndex) + " (DELAYED)"); | |
System.out.println(scheduleList); | |
} | |
public void earlyFlight(int earlyIndex, int newPos) { | |
this.scheduleList.add(newPos, scheduleList.remove(earlyIndex) + " (EARLY)"); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.ArrayList; | |
import java.util.Map; | |
import java.util.HashMap; | |
public class FriendsList { | |
ArrayList<String> friendsArray = new ArrayList<String>(); | |
Map<String, Integer> map = new HashMap<String, Integer>(); | |
public FriendsList(ArrayList<String> facebookFriends) { | |
this.friendsArray = facebookFriends; | |
} | |
public String occursMost() { | |
String maxName = null; | |
int max = 0; | |
for (int i = 0; i < friendsArray.size(); i++) { | |
if (map.containsKey(friendsArray.get(i))) { | |
map.put(friendsArray.get(i), map.get(friendsArray.get(i)) + 1); | |
} else { | |
map.put(friendsArray.get(i), 1); | |
} | |
int val = map.get(friendsArray.get(i)); | |
if (val > max) { | |
max = val; | |
maxName = friendsArray.get(i); | |
} | |
} | |
return maxName; | |
} | |
public ArrayList<String> removeDoubles() { | |
ArrayList<String> uniques = new ArrayList<String>(); | |
for (int i = 0; i < friendsArray.size(); i++) { | |
if (!uniques.contains(friendsArray.get(i))) { | |
uniques.add(friendsArray.get(i)); | |
} | |
} | |
friendsArray = uniques; | |
return friendsArray; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.ArrayList; | |
public class TheOffice { | |
public double getRealPrice(double taxPercent, double salePrice) { | |
return salePrice + ((0.01 * taxPercent) * salePrice); | |
} | |
public int findRundownIndex(ArrayList<String> rundown, String name) { | |
for (int i = 0; i < rundown.size(); i++) { | |
if (rundown.get(i).equals(name)) { | |
return i; | |
} | |
} | |
return -1; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.ArrayList; | |
public class TrappedHelper { | |
public void removeEvens(ArrayList<Integer> arr) { | |
for (int i = 0; i < arr.size(); i++) { | |
if (arr.get(i) % 2 == 0) { | |
arr.remove(i--); | |
} | |
} | |
} | |
public void removeThreeMults(ArrayList<Integer> arr) { | |
for (int i = 0; i < arr.size(); i++) { | |
if (arr.get(i) % 3 == 0) { | |
arr.remove(i--); | |
} | |
} | |
} | |
public void thirdThing(ArrayList<Integer> arr) { | |
for (int i = 0; i < arr.size(); i++) { | |
if (arr.get(i) % 2 == 0 && ((arr.size() - 1 != i) ? (arr.get(i+1) % 2 == 1) : false)) { | |
arr.remove(i+1); | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.ArrayList; | |
public class PhoneContacts { | |
ArrayList<Integer> phoneNumbers = new ArrayList<Integer>(); | |
ArrayList<String> phoneNames = new ArrayList<String>(); | |
public void addContact(String name, int number) { | |
phoneNames.add(name); | |
phoneNumbers.add(number); | |
System.out.print(name + " was saved."); | |
} | |
public void findNumber(String name) { | |
for (int i = 0; i < phoneNumbers.size(); i++) { | |
if (phoneNames.contains(name)) { | |
System.out.print(phoneNumbers.get(i)); | |
return; | |
} | |
} | |
System.out.println("Contact doesn't exist."); | |
return; | |
} | |
public void deleteContact(String name) { | |
for (int i = 0; i < phoneNumbers.size(); i++) { | |
if (phoneNames.contains(name)) { | |
phoneNumbers.remove(i); | |
phoneNames.remove(i); | |
System.out.print(name + " was deleted."); | |
return; | |
} | |
} | |
System.out.print("Contact doesn't exist."); | |
return; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment