Hello All! I am working on the following assignment: An attempt to moveOn or backUp or to evaluate seesCD when it is illegal causes an abrupt System.exit(0) without explanation. The user would appreciate a tracing output in such cases. Revise these three methods to call a private method that explains the problem (with showMessageDialog) and then terminates.
I wrote the following code:
import java.util.*;
import java.awt.*;
import javax.swing.*;
public class Vic extends Object
{
private static final String NONE = "0";
/////////////////////////////////
private String itsSequence = "";
private int itsPos = 1;
private final int itsID; // assigned by the constructor
private void trace (String action)
{
System.out.println ("Vic# " + itsID + ": " + action
+ itsPos + "; sequence= " + itsSequence);
} //======================
public void backUp()
{
if (itsPos == 1)
error("Could not backUp");
itsPos--;
trace ("backUp to slot ");
} //======================
public void moveOn()
{
if ( ! seesSlot())
error("Could not moveOn");
itsPos++;
trace ("moveOn to slot ");
} //======================
public boolean seesSlot()
{
return itsPos < itsSequence.length();
} //======================
public boolean seesCD()
{
if ( ! seesSlot())
error("Can't see CD, there is no slot");
String s = itsSequence.substring (itsPos, itsPos + 1);
return ! s.equals (NONE);
} //======================
private void error(String message)
{
JOptionPane.showMessageDialog(null, "ERROR: " + message);
System.exit(0);
}
}
When I compile I receive the following error message:
"variable itsID might not have been initialized".
and this line is highlighted."public class Vic extends Object"
Any help would be greatly appreciated! Thank you!