I am trying to compare a string to a string value. Seems rather simple, however, the comparison is returning null. All I want is to output the matched value and ignore the null return. But the output is showing the null value as well. I have tried this in various ways, but it keeps showing the null value.
class ActionMovie extends cdinventoryprogram {
private String Atitle;
private double Avalue;
private double Rstock;
private String Ctitle;
public ActionMovie(String title, int itemNumber, int numberofUnits, double unitPrice ){
Atitle = title;
Avalue = numberofUnits * unitPrice;
Rstock = unitPrice * .05;}
public String getActionTitle(){
if (Atitle.equals("Matrix")){
Ctitle = Atitle;
}else if (!Atitle.equals("Matrix")){
}
return Ctitle;
}
}
public class cdinventoryprogram {
public static void main(String[] args) {
ActionMovie myAction[] = new ActionMovie[DEFAULT_LENGTH];
myAction[0] = new ActionMovie ("The Illusionist", 1, 5, 15.99);
myAction[1] = new ActionMovie ("Matrix", 2, 3, 14.99);
myAction[2] = new ActionMovie ("Old School", 3, 6, 12.99);
for ( ActionMovie currentActionMovie : myAction ){
CAction = currentActionMovie.getActionTitle();
JOptionPane.showMessageDialog( null, "Your action movie is: " + CAction);
}} }
Ctitlenot initialized. Plus Java variables start with lowercase letter.