If you're new to ArrayLists, you may want to run ArrayListDemo.java .
Design a class called PrimesFactory. This class will
calculate the prime factorization of any number,
print a list of all prime numbers as well as state whether or
not a given number is a prime number.
Source Code
- public boolean isPrime(int num)
- This method returns true if
num is a prime number.
- public ArrayList<Integer> getPrimeFactors(int num)
- This method returns an ArrayList full of the prime factors of num
- public String listPrimesUpTo(int num)
- This mehtod returns a comma separated String of all prime numbers less than num
Project 2: Class Roster: This class will implement the functionality of all roster for school. Here is
a grading rubric.
- Instance Variables
- a
final int MAX_NUM representing the maximum number of students allowed on the roster
- an ArrayList storing names as Strings
- an Arraylist stores student id's as Integers
- 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 roster
String retrieveById(int id) //@ returns Student name associated with id
int 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, mke sure that the total number of students does not exceed
MAX_NUM. Hint: Make user of the containsStudent() method
- 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 3: PlayList Project: This class stores lists of songs and will require 2 ArrayLists.
One is an
ArrayList of Strings that represent the individual track titles of all songs in a PlayList ; the other is a parallel ArrayList called 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 variable final int MAX_NUMBER_SONGS, which is pretty self descriptive (When you add the final modifer 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.
- swap the position of any two items in the list.
- add a song to the PlayList-- Do not allow more than
MAX_NUMBER_SONGS to be added to the list.
- remove a song from the PlayList
- rename the PlayList
- get the total number of songs currently in the PlayList
- clear all songs from the PlayList (You shoudl decide how to do this).
- print all songs as well as their stars.
- print all songs that have a given rating.