Project 1: PrimesFactory.java
If you're new to ArrayLists, you may want to run ArrayListDemo.java .
- public boolean isPrime(int num)
- This method returns true if
numis a prime number.
- This method returns true if
- public ArrayList<Integer> getPrimeFactors(int num)
- This method returns an ArrayList full of the prime factors of num
- public String listPrimesUpTo(int num)
- This method returns a comma separated String of all prime numbers less than num
- This method returns a comma separated String of all prime numbers less than num
Project 2: Bank This class will implement some of the basic functionality of a bank.
- Instance Variables
- An ArrayList to store names as Striings
- An Arraylist storing bank accounts (ints)
- An ArrayList storing balances (doubles
- Constructors
- default constructor
- A constructor with 1 paramater. This parameter is a list of names.
- Methods
- Accessors
- boolean hasAcount(String name) //@returns true if name has a bank account
- double getBalance(String name)//@returns the balance for name's account.
- double getBalance(int accountNumber)//@returns the balance as so cited with that accountNumber
- String getName(int accountNumber)//@ returns the name associated with that accountNumber
- Accessors
- Mutators
- void addAccount(String name, int number, double balance) adds an account
- void setBalance(int accountNumber, double balance) sets the accountNumber's balance equal to balance.
- void changeName(int accountNumber) changes the name associated with accountNumber
Project 3: Class Roster: This class will implement the functionality of all roster for school. Here is a grading rubric.
- Instance Variables
- a
final int MAX_NUMrepresenting the maximum number of students allowed on the roster - an ArrayList storing names as Strings
- an Arraylist stores student id's as Integers
- a
- Constructors
- a default constructor should initialize the list to empty strings
- a single parameter constructor that takes an ArrayList<String>
- Both constructors should initialize the instance variables
- Methods
-
Accessors
boolean containsStudent(String studentName)//@returns true if studentName is in rosterString retrieveById(int id)//@ returns Student name associated with idint retrieveId(String Student)//@returns id associated with String Student
-
Mutators:
boolean addStudent(String studentName, int studentId);//adds student name and id to end of roster- This method should not allow a student to be added if the name or the studentId is already in the roster. Also, make sure that the total number of students does not exceed
MAX_NUM. Hint: Make user of thecontainsStudent()method
- This method should not allow a student to be added if the name or the studentId is already in the roster. Also, make sure that the total number of students does not exceed
- boolean removeStudent(int id) // removes student from roster based on id. Make sure that you maintain the integrity of the parallel ArrayLists.
- boolean removeStudent(String name) //removes student based on name. Make sure that you maintain the integrity of the parallel ArrayLists.
- Project 4: PlayList Project: This class stores lists of songs and will require e ArrayLists.
One is an
ArrayListofStringsthat represent the individual track titles of all songs in aPlayList; the other is a parallelArrayListcalled Stars which represents how many 'stars' you give each song(between 0 and 5 stars). It should also have an instance variable that represents the name of the PlayList and an instance variablefinal int MAX_NUMBER_SONGS, which is pretty self descriptive (When you add thefinalmodifier to a variable it become a constant that cannot be changed by your program). You should create accessor and mutator methods that implement the following functionality. - Instance Variables
- private String listName : This is the 'name' of your playList
- private ArrayList<String> songs
- private ArrayList<Integer> stars //how many stars each song has
- private ArrayList<String> artists
- Constructor
- no default constructor
public PlayList(String name): There should be only 1 constructor that takes a parameter representing the name of the playList
- Mutator Methods
public void swap(String song1, String artist1, String song2, String artist2)// switches positions of these twopublic void renameList(String to)//changeslistNametotopublic void clearList()//removes all items from all the lists and sets the value oflistNametonullpublic boolean add(String song, String artist, int stars)//adds data if number of song is less thanMAX_NUMBER_SONGSpublic void removeSong(String song, String artist )//removessongassociated withartist- Note: Be careful here. You are allowed to add the same song and artist. Duplicates are allowed. Make sure your code works with duplicate
song, artistin the list
- Note: Be careful here. You are allowed to add the same song and artist. Duplicates are allowed. Make sure your code works with duplicate
public void removeArtist(String artist )//removes all elements associated withartistpublic void removeLowStars(int cutOff)//removes all elements associated with a star rating less thancutOffpublic PlayList(String name): There should be only 1 constructor that takes a parameter represents the name of the playList** public void sortByRating()//this rearranges the playlist so that the 5 starred elements are the first group in the list, 4 stars second ...1 stars, last- ** PlayList shuffle()//this returns a new PlayList in which all of the songs have been reordered randomly
- Accessor Methods
public String getName()//returnslistNamepublic ArrayList<String> getArtist(String song)// returns an ArrayList of all musicians associated with a given song name (This could be multiple musicians)public ArrayList<String> getSongs(String artist)// returns an ArrayList of all Songs associated withartist.public int getStars(String artist, String song)// returns how many stars givensonghaspublic int spacesLeft()//returns has many spaces are left for songs. In other words, if the list is empty it returnsMAX_NUMBER_SONGSpublic double averageRating()// returns the mean star rating for the listpublic int numSongsByArtist(String musician)//returns a count of how many songs are associated with givenmusicianpublic double averageRating(String artist)// returns the mean star rating associated withartistpublic String getMusician(String artist)// returns a comma separated list of all songs and their respective ratings associated withartistpublic void printRating(int starRating)// prints a list of all songs and musicians whose stars havestarRating.public String toString()//returns an appropriate String representation of the list