I am trying to make a movie database for some homework. Getting stuck adding deleting functionality. I get stuck trying when trying to re-add another movie because of my moivecount variable. If I delete movie3 if I have 4 movies then moviecount == 3 and when I try to add another movie it asks for movie4 again when I need to add movie3.
import java.util.*;
public class Interface {
private void run()
{
Scanner console = new Scanner(System.in);
Movie m1;
Movie m2;
Movie m3;
Movie m4;
String name, director;
int size, duration, option;
int moviecount = 0;
m1 = new Movie();
m2 = new Movie();
m3 = new Movie();
m4 = new Movie();
do {
System.out.println("Import new movie:(0), Delete movie from Database (2), View Movies: (3), Exit (9): ");
option = console.nextInt();
switch(option)
{
case 0:
if(moviecount == 0)
{
System.out.print("First Movie: ");
name = console.next();
m1.setName (name);
System.out.print("Director: ");
director = console.next();
m1.setDirector (director);
System.out.print("Size in MB: ");
size = console.nextInt();
m1.setSize(size);
System.out.print("Duration in minutes: ");
duration = console.nextInt();
m1.setDuration(duration);
moviecount++;
break;
}
else if(moviecount == 1)
{
System.out.print("Second Movie: ");
name = console.next();
m2.setName (name);
System.out.print("Director: ");
director = console.next();
m2.setDirector (director);
System.out.print("Size in MB: ");
size = console.nextInt();
m2.setSize(size);
System.out.print("Duration in minutes: ");
duration = console.nextInt();
m2.setDuration(duration);
moviecount++;
break;
}
else if(moviecount == 2)
{
System.out.print("Third Movie: ");
name = console.next();
m3.setName (name);
System.out.print("Director: ");
director = console.next();
m3.setDirector (director);
System.out.print("Size in MB: ");
size = console.nextInt();
m3.setSize(size);
System.out.print("Duration in minutes: ");
duration = console.nextInt();
m3.setDuration(duration);
moviecount++;
break;
}
else if(moviecount == 3)
{
System.out.print("Fourth Movie: ");
name = console.next();
m4.setName (name);
System.out.print("Director: ");
director = console.next();
m4.setDirector (director);
System.out.print("Size in MB: ");
size = console.nextInt();
m4.setSize(size);
System.out.print("Duration in minutes: ");
duration = console.nextInt();
m4.setDuration(duration);
moviecount++;
break;
}
else
{
System.out.print("Too many movies currently stored \n" );
break;
}
case 2: System.out.print("Which movie to delete? (1), (2), (3), (4) \n");
option = console.nextInt();
switch(option)
{
case 1: m1.setName(null);
m1.setDirector(null);
m1.setSize(0);
m1.setDuration(0);
System.out.print("Movie 1 deleted! ");
moviecount--;
break;
case 2: m2.setName(null);
m2.setDirector(null);
m2.setSize(0);
m2.setDuration(0);
moviecount--;
break;
case 3: m3.setName(null);
m3.setDirector(null);
m3.setSize(0);
m3.setDuration(0);
moviecount--;
break;
case 4: m4.setName(null);
m4.setDirector(null);
m4.setSize(0);
m4.setDuration(0);
moviecount--;
break;
}
case 3: System.out.print("Movies stored in database: \n");
System.out.print(m1.getName()+"\n");
System.out.print(m2.getName()+"\n");
System.out.print(m3.getName()+"\n");
System.out.print(m4.getName()+"\n");
}
}
while(option!=9);
}
public static void main(String[] args){
Interface intFace = new Interface();
intFace.run();
}
}
The problem lies in your design. You are running into this problem because you are not actually storing your movies anywhere. You are just creating 4 different movie objects and printing them out. If you changed the order of your print statements, they would be in a different order.
You are going to need to add in some sort of data structure - any array, a list, or some other sort of collection to store your movies in.
For example you might create a List to store your movie data.
//create new List called movieList
List movieList = new ArrayList();
//add movies to the list
movieList.add(m1);
movieList.add(m2);
movieList.add(m3);
movieList.add(m4);
//remove movies from the list by position
movieList.remove(0);
movieList.remove(1);
movieList.remove(2);
movieList.remove(3);
You can add your movies to the list using the Lists's add() method, and remove them using the remove() method. Keep in mind that remove removes the element at the index you provide, and the index starts at 0.
So, for example to remove the first movie, you would call movieList.remove(0).
The second movie would be at index 1, etc.
The answer to your specific implementation: you can't use that moviecount variable to determine in which slot you want to add a new move!
Instead: just walk over your movie objects. And push data into the first one that is empty.
Meaning: you could define a "isEmpty()" method on the Movie class that returns true if the name is null.
But just for the record: having and using these setter methods is a bad approach. Normally you would want to set all these values using the constructor of the movie class, as you don't want to allow to change that information later on.
And then you would simply do
movie1 = new...
when creating a new movie and
movie1 = null
to delete it later on. And then you can also easily check if a slot is taken:
if (movie1 == null) {...
Related
I wrote a short code that declares 6 reference variables from a class named 'ChosenCompanies' to practice classes and constructors in Java.
It is the following:
public static void main(String[] args) {
String[] FinalCompaniesName = new String[6];
ChosenCompanies com1 = new ChosenCompanies();
ChosenCompanies com2 = new ChosenCompanies();
ChosenCompanies com3 = new ChosenCompanies();
ChosenCompanies com4 = new ChosenCompanies();
ChosenCompanies com5 = new ChosenCompanies();
ChosenCompanies com6 = new ChosenCompanies();
Scanner scanner = new Scanner(System.in);
int choice;
int count = 1;
while(count <= 2) {
switch(count) {
case 1:
System.out.println("Choose one:");
System.out.println("1. " + com1.name);
System.out.println("2. " + com2.name);
System.out.println("3. " + com3.name);
choice = scanner.nextInt();
switch(choice) {
case 1:
FinalCompaniesName[0] = com1.name;
break;
case 2:
FinalCompaniesName[0] = com2.name;
break;
case 3:
FinalCompaniesName[0] = com3.name;
break;
}
break;
case 2:
System.out.println("Choose one:");
System.out.println("1. " + com4.name);
System.out.println("2. " + com5.name);
System.out.println("3. " + com6.name);
choice = scanner.nextInt();
switch(choice) {
case 1:
FinalCompaniesName[1] = com4.name;
break;
case 2:
FinalCompaniesName[1] = com5.name;
break;
case 3:
FinalCompaniesName[1] = com6.name;
break;
}
break;
}
count++;
}
System.out.println("You have chosen: "
+ FinalCompaniesName[0] + ", " + FinalCompaniesName[1]);
}
As you can see from the above code, these two parts are almost the same except for the names of reference variables(com1, com2, com3, com4...):
part 1:
switch(count) {
case 1:
System.out.println("Choose one:");
System.out.println("1. " + com1.name);
System.out.println("2. " + com2.name);
System.out.println("3. " + com3.name);
choice = scanner.nextInt();
switch(choice) {
case 1:
FinalCompaniesName[0] = com1.name;
break;
case 2:
FinalCompaniesName[0] = com2.name;
break;
case 3:
FinalCompaniesName[0] = com3.name;
break;
}
break;
part 2:
case 2:
System.out.println("Choose one:");
System.out.println("1. " + com4.name);
System.out.println("2. " + com5.name);
System.out.println("3. " + com6.name);
choice = scanner.nextInt();
switch(choice) {
case 1:
FinalCompaniesName[1] = com4.name;
break;
case 2:
FinalCompaniesName[1] = com5.name;
break;
case 3:
FinalCompaniesName[1] = com6.name;
break;
}
break;
}
I am wondering if I can minimize the amount of the code above by using a for or while loop, since the name of the reference variables are increased by 1, like integer 'i' in a common for statement.
In short, is it possible to declare reference variables by using loop?
Your example is confusing so I don't know what exactly are you trying to accomplish, but here is an example of how to prompt the user to select a new name for each company from a list of existing company names:
public class Company {
/**
* Array of available company names used to construct
* initial companies. These names are also used as possible
* choices when changing company names through {#link #changeCompanyNames()}
*/
private static final String[] COMPANY_NAMES = new String[]
{ "Alphabet", "Microsoft", "IBM", "Amazon", "Oracle", "Apple" };
/**
* <p>
* Array of Company objects initialized with a fixed number of
* new companies equal to the number of String entries in {#link #COMPANY_NAMES}.
* </p><p>
* Each company entry will inheriting a name from the mentioned array
* in the initialization process done in {#link #initializeCompanies()}
* </p>
*/
public static final Company[] COMPANIES = initializeCompanies();
private String name;
/**
* Internal constructor with private access to
* prevent class construction outside this class
*/
private Company(String name) {
this.name = name;
}
/**
* Should only be used internally on class loading to
* construct an array of companies from a list of company names.
*/
private static Company[] initializeCompanies() {
Company[] companies = new Company[COMPANY_NAMES.length];
for (int i = 0; i < COMPANY_NAMES.length; i++) {
companies[i] = new Company(COMPANY_NAMES[i]);
}
return companies;
}
/**
* Change any or all company names by prompting the user to choose
* a new name for each company from the list of available companies.
*/
public static void changeCompanyNames() {
java.util.Scanner scanner = new java.util.Scanner(System.in);
/*
* Create a new array of company names that is identical to the existing
* array of company names. We will change names here on user input and
* then update each new company name to values from this array.
*/
final String[] finalCompanyNames = COMPANY_NAMES.clone();
/*
* Iterate through an array of companies with a for-loop
* accessing and processing each company entry
*/
for (int i1 = 0; i1 < COMPANIES.length; i1++)
{
/* Prompt the user to choose a new company name for the
* company at index i1 from COMPANIES array.
*/
System.out.printf("Choose a new company name for %s company:%n", COMPANIES[i1].name);
/*
* Again iterate through all companies and print their names to
* console offering the user a list of possible names to choose from
*/
for (int i2 = 0; i2 < COMPANIES.length; i2++) {
System.out.printf("%d. %s%n", i2 + 1, COMPANIES[i2].name);
}
/*
* Get user input and validate it, then either update the array of
* final names with the new entry or print an error and move the index
* to the previous position if the input was an invalid number
*/
int input = scanner.nextInt();
if (input > 0 && input <= COMPANIES.length) {
finalCompanyNames[i1] = COMPANY_NAMES[input - 1];
System.out.println("You have choosen company name " + finalCompanyNames[i1]);
}
else {
System.out.printf("Error: input is not in range (1-%d)%n", COMPANIES.length);
/*
* It's imperative that we move the index to the previous
* position so we can iterate over this company entry again
*/
i1 -= 1;
}
}
// Print simple line separator
System.out.println("");
/* Print each choosen name that is different then the original
* company name and update the appropriate company name field value
*/
for (int i = 0; i < finalCompanyNames.length; i++)
{
if (!finalCompanyNames[i].equals(COMPANY_NAMES[i])) {
System.out.printf("Company %s has changed name to %s%n", COMPANY_NAMES[i], finalCompanyNames[i]);
COMPANIES[i].name = finalCompanyNames[i];
}
}
}
}
Example console output after the user is done choosing:
Company Alphabet has changed name to IBM
Company Microsoft has changed name to Amazon
Company IBM has changed name to Alphabet
Company Amazon has changed name to Oracle
Company Oracle has changed name to Microsoft
Company Apple has changed name to Amazon
Here we are able to set any number of companies and let the user choose any of the offered names for them. The code might look a tad bit daunting for a beginner but this is actually the simplest way of doing this without involving any of the more complex Java concepts into play.
Feel free to ask any questions regarding this implementation. I will be quite happy to help out.
EDIT: Updated the code to include detailed comments and a more comprehensive structure that is easier to understand and fixed an indexing issue.
It is not possible in Java to create dynamic variables (but with reflections, see here)
You can create an array and use the i as index like chosenCompanies[i].
Otherwise you can use lists or maps.
Edit:
That would e.g. look like this. Apart from the sence of the code, this example shows only how you would use an array:
String[] choosenCompanieNames = new String[2]; // you only store two values, not 6 values
//lets store the values to chose in arrays
String[] possibleCompanieNames = new String[6]; // 6 possible values to choose (com1 - com6)
possibleCompanieNames[0] = "com1";
possibleCompanieNames[1] = "com2";
possibleCompanieNames[2] = "com3";
possibleCompanieNames[3] = "com4";
possibleCompanieNames[4] = "com5";
possibleCompanieNames[5] = "com6";
//I deleted the while loop, as it only has two ways and every way has its own code.
Scanner scanner = new Scanner(System.in);
int choice;
System.out.println("Choose one:");
System.out.println("1. " + possibleCompanieNames[0]);
System.out.println("2. " + possibleCompanieNames[1]);
System.out.println("3. " + possibleCompanieNames[2]);
choice = scanner.nextInt();
choosenCompanieNames[0] = possibleCompanieNames[choice-1]; //you must subtract one, as the array index starts at 0 and ends on 5
System.out.println("Choose one:");
System.out.println("1. " + possibleCompanieNames[3]);
System.out.println("2. " + possibleCompanieNames[4]);
System.out.println("3. " + possibleCompanieNames[5]);
choice = scanner.nextInt();
choosenCompanieNames[1] = possibleCompanieNames[3+choice-1]; //here you want com4, com5 and com6, so you can e.g. add 3 to index and substract one like code above. Or better add only 2, as 3-1=2
System.out.println("You have chosen: "
+ choosenCompanieNames[0] + ", " + choosenCompanieNames[1]);
So I have this code here
CoinBag<Coin> bag = new CoinBag<>();
int choice = -1;
do {
System.out.println("[1] To add a new item to the bag");
System.out.println("[2] To print bag contents");
Scanner in = new Scanner(System.in);
choice = in.nextInt();
switch (choice) {
case 1:
System.out.println("Enter item:");
Coin item = in.nextInt();
if (bag.add(item)) {
System.out.println("Item " + item + " is added successfully to the bag");
}
break;
On the Coin item = in.next(); I am getting an error Incompatibile types: String cannot be converted to Int. What I am asking is what do I have to write so that it is converted that way the user can input an integer value so that it brings them to their selected option in the list.
You cannot take in an integer (nextInt()) and assign it to Coin. They are two different data types.
I suggest you read up on the Scanner.
I've been working on the following assignment:
This program should create an ArrayList called Book List. The program
should display a menu to allow the user to choose from the following options:
Enter 1 to add a book to the list:
Enter 2 to edit a book to the list:
Enter 3 to remove a book from the list:
Enter 4 to display the list of books:
Enter 5 to quit:
The program should use a case/switch statement and switch on the users choice. The program should continue until the user enters 5 to quit.
Case 1 should use BookList.add to add books to the ArrayList.
Case 2 should use BookList.set to edit books to the ArrayList.
Case 3 should use BookList.remove to remove a name from the list (Ask the user to enter the index number of the book to delete from ArrayList).
Case 4 should use a for loop to display all books in the ArrayList
along with their index number.
(Sample output) Your output should look similar to:
**********The Book List*********
Index: 0 Name: Stranger in a Strange Land
Index: 1 Name: PHP and MySQL
Index: 2 Name: HTML & CSS
Index: 3 Name: Love Story
Index: 4 Name: The Day the Earth Stood Still
I am having trouble with ArrayList.set. I can not figure out how to take user input (the index number and the corrected book title) to update the array list. That's not the end of my issues with this program, but any help on ArrayList.set would be greatly appreciated.
import java.util.ArrayList;
import java.util.Scanner;
public class BookList {
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
Scanner input = new Scanner(System.in);
//Create array
ArrayList<String> bookList = new ArrayList<String>();
//Add a few books to the array bookList
bookList.add("A Game of Thrones");
bookList.add("A Clash of Kings");
bookList.add("A Storm of Swords");
bookList.add("A Feast for Crows");
bookList.add("A Dance with Dragons");
//Display the items in bookList array and their indices.
System.out.println("******** The Book List ********");
for (int index = 0; index < bookList.size(); index++)
{System.out.println("Index: " + index + " Name: " + bookList.get(index));}
System.out.print("\n");
//declaring variables
int menuID = 0;
int changeIndex = 0;
int delIndex = 0;
String addTitle = "";
String corrTitle = "";
//Menu
System.out.println("Enter 1 to add a book to the list");
System.out.println("Enter 2 to edit a book in the list");
System.out.println("Enter 3 to remove a book from the list");
System.out.println("Enter 4 display the list of books");
System.out.println("Enter 5 to quit");
System.out.println("Enter a menu number (1-4 or 5 to Exit): ");
menuID = input.nextInt();
while (menuID != 0)
{
if (menuID >=1 && menuID <= 4)
{
switch (menuID)
{
case 1:
System.out.println("Enter the book to add: ");
addTitle = keyboard.nextLine();
bookList.add(addTitle);
System.out.print("\n");
System.out.println("******** The Book List ********");
for (int index = 0; index < bookList.size(); index++)
{System.out.println("Index: " + index + " Name: " + bookList.get(index));}
break;
case 2:
System.out.println("Enter index number of the book to change: ");
changeIndex = keyboard.nextInt();
System.out.println("Enter the corrected book name: ");
corrTitle = keyboard.nextLine();
bookList.set(changeIndex, corrTitle);
System.out.println("******** The Book List ********");
for (int index = 0; index < bookList.size(); index++)
{System.out.println("Index: " + index + " Name: " + bookList.get(index));}
break;
case 3:
System.out.println("Enter index number of the book to remove: ");
delIndex = keyboard.nextInt();
bookList.remove(delIndex);
System.out.println("******** The Book List ********");
for (int index = 0; index < bookList.size(); index++)
{System.out.println("Index: " + index + " Name: " + bookList.get(index));}
break;
case 4:
System.out.println("******** The Book List ********");
for (int index = 0; index < bookList.size(); index++)
{System.out.println("Index: " + index + " Name: " + bookList.get(index));}
break;
case 5:
System.out.println("Goodbye!");
break;
}}
else if (menuID >=1 && menuID <= 4)
System.out.println("You must enter a number 1-5:");
System.out.println("Enter a menu number (1-4 or 5 to Exit): ");
menuID = input.nextInt();
}
}
}
You should be using only one Scanner object with the same source, unless you had a really complicated way to traverse the input, which probably isn't the case here. So your code should look something like this:
// Scanner keyboard = new Scanner(System.in);
Scanner input = new Scanner(System.in);
// ...
menuID = input.nextInt();
while (menuID != 0)
{
if (menuID >=1 && menuID <= 4)
{
switch (menuID)
{
case 1:
// ...
addTitle = input.nextLine();
// ...
Now, there's another issue because you're calling Scanner.nextInt, which gets you the next integer, but won't consume the rest of the line after taking the integer, so when you call Scanner.nextLine it will get you the rest of that previous line instead of the new line you're expecting. To fix that, you could call a dummy Scanner.nextLine after each Scanner.nextInt, like this:
menuID = input.nextInt();
input.nextLine(); // Consumes the rest of the line
Or you could get the whole line every time and parse the integer it contains, using Integer.parseInt, like this:
menuID = Integer.parseInt(input.nextLine());
Here's the working code using the second option (which I find better for this case)
As a side note, you're asking the user to exit with 5, but your while depends continues as long as the menuID is not 0
My program uses an array: collection[] to hold information on cars. user input is used to add a car to the array using the console. So the user would enter the car's name, year of make, etc. However when it gets added to the array it goes straight into collection[0]. So if there is anything already in collection[0] it will replace it.
I want the user input to be but into the the next null cell in the array to avoid this problem. I have tried to write code that goes through each cell of the array and once it finds a cell which is null it then adds the information into it. However it is not working.
public void addCarInput1()
{
for (int i = 0; i < 1; i++)
if (this.collection[i] = null)
{
this.collection[i].addCarInput();
}
}
Here is a shortened version of addCarInput:
Scanner sin = new Scanner(System.in);
System.out.print("Enter car make: ");
Cmake = sin.nextLine();
System.out.print("Enter car model : ");
Mname = sin.nextLine();
You can try something like this if you want more cars
String shouldContinue = null;
while(true) {
if (shouldContinue.equals("no")) break;
Scanner sc = new Scanner(System.in);
System.out.print("Enter car make: ");
String make = sc.nextLine();
System.out.print("Enter car model : ");
String model = sc.nextLine();
//add car info
addCarInput(make, model);
System.out.print("Enter info for another car? : ");
shouldContinue = sc.nextLine()
}
Why don't you use a LinkedList or an ArrayList object instead of an array?
the add() method will add the elements at the end of the list & not replace the old values
http://docs.oracle.com/javase/7/docs/api/java/util/ArrayList.html
https://docs.oracle.com/javase/7/docs/api/java/util/LinkedList.html
http://examples.javacodegeeks.com/core-java/util/arraylist/arraylist-in-java-example-how-to-use-arraylist/
I am trying to build a program which allows a user to input an actors name and details (age+address) and also 2 films they've starred in. These films must be read into a main array in the main method, but each individual actors films must be copied into a designated array in my actor class to store the actors films individually.
I am currently trying to read the values into my array inside a loop in my main method:
import java.util.Scanner;
public class main {
public static void main(String[] args) {
Scanner kbd = new Scanner (System.in);
String code="";
System.out.println("How many actors would you like to enter?");
int amt = kbd.nextInt();
int noOfFilms = (amt*2);
Actor [] arrayOfActors = new Actor[amt];
//Array of ALL films, each actors films must be copied to seperate array in the actor class.
String [] allFilms = new String[noOfFilms];
kbd.nextLine();
int count = 1;
int i = 0;
do {
count++;
System.out.println("Enter the Details for actor "+(count-1)+"\n");
System.out.println("Enter actor name:"+"\n");
String name = kbd.nextLine();
System.out.println("Enter actor age:"+"\n");
int age = kbd.nextInt();
kbd.nextLine();
System.out.println("Enter actor address:"+"\n");
String address = kbd.nextLine();
//Read in the actors films
System.out.println("Enter film 1 for "+name+"\n");
String film1 = kbd.nextLine();
allFilms[i] = film1;
System.out.println("Enter film 2 for "+name+"\n");
String film2 = kbd.nextLine();
allFilms[i+1] = film2;
//Create an actor as array is full of references only.
arrayOfActors[i] = new Actor(name, address, age);
i++;
arrayOfActors[i-1].print();
} while (count <= amt);
System.out.println("This was in the films array: "+allFilms[1]);
}
}
Obviously the way I have it structured currently will not work as every time the loop starts the values will just be over-written and the only details stored will be the last actors films to be entered.
I am stuck trying to work around this and read in all the films, which will then need to be deep copied into another array. (in Actor class)
This is a college assignment and must be done this way. Any suggestions would be of great help.
You can include an array field inside your Actor class. Then you will modify your Actor class constructor in order to include this array argument for initialization purposes.
So I would handle this part inside the loop like this:
String[] actorFilms = new String[2];
//Read in the actors films
System.out.println("Enter film 1 for "+name+"\n");
String film1 = kbd.nextLine();
allFilms[i] = film1; //not OK; read below
actorFilms[0] = film1;
System.out.println("Enter film 2 for "+name+"\n");
String film2 = kbd.nextLine();
allFilms[i+1] = film2; //not OK; read below
actorFilms[1] = film2;
//Create an actor as array is full of references only.
arrayOfActors[i] = new Actor(name, address, age, actorFilms);
I'm not sure if you still need to keep the allFilms array, but if you need, you will have to determine the indexes you need to populate depending on the count value. By simply using i and i+1 you always overwrite the same locations in the array.
Some other remarks:
-- I think you're not using count properly; you're initializing it with 0, but you immediately increment it (first statement in the loop);
-- notation conventions in Java state that class names should be capitalized.
I would suggest use a collection of actor objects in a collection.
Collection actorDetails= new ArrayList<>();
do
{
....
...
....
actorDetails.add(actioObj)
}while(....)
finally use actorDetails to retriev information
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner kbd = new Scanner (System.in);
String code = "";
System.out.println("How many actors would you like to enter?");
int amt = kbd.nextInt();
int noOfFilms = (amt * 2);
Actor[] arrayOfActors = new Actor[amt];
String[] allFilms = new String[noOfFilms];
kbd.nextLine();
for (int count = 0; count < amt; count++) {
System.out.println("Enter the details for actor " + (count + 1));
System.out.prinln("Enter actor name:");
String name = kbd.nextLine();
System.out.println("Enter actor age:");
int age = kbd.nextInt();
kbd.nextLine();
System.out.println("Enter actor address:");
String address = kbd.nextLine();
System.out.println("Enter film 1 for " + name);
String film1 = kbd.nextLine();
allFilms[count * 2] = film1;
System.out.println("Enter film 2 for " + name );
String film2 = kbd.nextLine();
allFilms[(count * 2) + 1] = film2;
arrayOfActors[count] = new Actor(name, address, age);
arrayOfActors[count].print();
}
System.out.println("This was in the films array: " + allFilms[1]);
}
}
Perhaps something like this? I got rid of the i variable and used only the count variable to keep track of the array indexes. I am assuming you have not began working with Collections, otherwise you could do that.