Java, Searching String in array?

Rnard

New member
i need help for searching a string in array and will return error message if there is no string in that array

here is the array private
String DVDnames [] = { "Dvd1" , "Dvd2" , "Dvd3" , "Dvd4" , "Dvd5", "Dvd6" , "Dvd7" , "Dvd8" , "Dvd9" , "Dvd10" };

public void borrowDVDs()
{
System.out.println("\n--- BORROW A DVD ---\n");
Scanner scanner = new Scanner(System.in);
System.out.println("What DVD would you like to borrow?");
String nameDVD = scanner.next();
for( int i = 0; i < DVDnames.length;i++)
{
if ( nameDVD==DVDnames)
{
System.out.println("The DVD is available");
System.out.println("The price is : $ "+DVDprice);
System.out.println("Please insert the money.");
double payment = scanner.nextDouble();
if (payment < DVDprice)
{
System.out.println("Payment amount is not sufficient");
}
else
{
double change = calcChange(DVDprice, payment);
System.out.println("Change due: $" + change);
updateNumberDVDs(-1, false);
updateAccountBalance(DVDprice, true);
}
}
else
{
System.out.println("---ERROR---");
}


that is the method i want to make. so if i insert say Dvd1 it will go to another method

but for now all the method goes to error
 
Back
Top