Created
December 4, 2015 16:05
-
-
Save connlark/a449d36825a72f10a50c 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; | |
import java.util.Scanner; | |
public class MyPlaces | |
{ | |
/** | |
* Instance variable: a collection which is | |
* always in alphabetic order | |
*/ | |
private ArrayList<String> places; | |
/** | |
* Constructor for objects of class Places | |
*/ | |
public MyPlaces() { | |
places = new ArrayList<String>(); | |
} | |
/** postcondition: the names are in alphabetical order **/ | |
public void add(String place) | |
{ | |
for (int i = 0; i < places.size() ; i++) { | |
if (place.compareToIgnoreCase(places.get(i)) < 0){ | |
places.add(i,place); | |
return; | |
} | |
} | |
places.add(place); | |
} | |
// print list of all places you've been | |
public void print() | |
{ | |
System.out.println(places); | |
} | |
/** | |
* Rename – Searches through the list for the originalName. If the originalName is | |
* in the list, changes it to newName and return true. If originalName is not in the | |
* list, return false. | |
*/ | |
public boolean rename(String originalName, String newName) { | |
for (int i = 0; i < places.size(); i++) { | |
if (places.get(i).equals(originalName)){ | |
places.remove(i); | |
add(newName); | |
return true; | |
} | |
} | |
return false; | |
} | |
/** | |
* return: the average length of the names of all places you've been | |
* rounded to the nearest 10th. | |
public double aveLength() | |
{ | |
} | |
/** | |
* postcondition: The first letter of each place name is capitalized | |
public void capitalize() | |
{ | |
} | |
*/ | |
public static void main(String[] args) { | |
Scanner key = new Scanner(System.in); | |
MyPlaces foo = new MyPlaces(); | |
foo.add("add"); | |
foo.add("b"); | |
foo.add("c"); | |
foo.add("d"); | |
foo.print(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment