why is z used in this java program? - java

package com.company;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class Main extends JFrame implements ActionListener { // main method with JFrame extension
JTextField field; // Creates new text field
double inp1; // initializing variables
double inp2;
double result;
double answer;
int x = 0;
int y = 0;
int z = 0;
char ch; // initialized variables
JButton num0, num1, num2, num3, // naming all buttons on the Calculator
num4, num5, num6, num7,
num8, num9, clear, square,
cube, add, sub, mul, div,
log, reciprocal, equal,
dot, root, sin, cos, tan;
Container container; // provides space for all future components
JPanel panel; // organizes the components in the space in the container
public Main() {
container = getContentPane(); // gets content pane in order to add an object to it
container.setLayout(new BorderLayout()); // allows to set layout of container
JPanel textpanel = new JPanel();
field = new JTextField(20);
field.setHorizontalAlignment(SwingConstants.LEFT); // This sets the alignment of the numbers when input
field.addKeyListener(new KeyAdapter() { // added so the numbers can also be input from keyboard
public void keyTyped(KeyEvent keyevent) {
char c = keyevent.getKeyChar();
if (c >= '0' && c <= '9') {
} else {
keyevent.consume();
}
}
});
textpanel.add(field); // adds field where the results will be displayed
panel = new JPanel();
panel.setLayout(new GridLayout(9, 3, 5, 5)); // hgap and vgap set the gap between buttons
num1 = new JButton("1"); // title of what the button will be called on the panel
panel.add(num1); // adding buttons on the panel
num1.addActionListener(this); // "this" is used as a reference to the current object
num2 = new JButton("2");
panel.add(num2);
num2.addActionListener(this);
num3 = new JButton("3");
panel.add(num3);
num3.addActionListener(this);
num4 = new JButton("4");
panel.add(num4);
num4.addActionListener(this);
num5 = new JButton("5");
panel.add(num5);
num5.addActionListener(this);
num6 = new JButton("6");
panel.add(num6);
num6.addActionListener(this);
num7 = new JButton("7");
panel.add(num7);
num7.addActionListener(this);
num8 = new JButton("8");
panel.add(num8);
num8.addActionListener(this);
num9 = new JButton("9");
panel.add(num9);
num9.addActionListener(this);
add = new JButton("+");
panel.add(add);
add.addActionListener(this);
num0 = new JButton("0");
panel.add(num0);
num0.addActionListener(this);
mul = new JButton("*");
panel.add(mul);
mul.addActionListener(this);
sub = new JButton("-");
panel.add(sub);
sub.addActionListener(this);
dot = new JButton(".");
panel.add(dot);
dot.addActionListener(this);
div = new JButton("/");
div.addActionListener(this);
panel.add(div);
equal = new JButton("=");
panel.add(equal);
equal.addActionListener(this);
log = new JButton("log");
panel.add(log);
log.addActionListener(this);
root = new JButton("√");
panel.add(root);
root.addActionListener(this);
sin = new JButton("SIN");
panel.add(sin);
sin.addActionListener(this);
cos = new JButton("COS");
panel.add(cos);
cos.addActionListener(this);
tan = new JButton("TAN");
panel.add(tan);
reciprocal = new JButton("1/x");
panel.add(reciprocal);
reciprocal.addActionListener(this);
tan.addActionListener(this);
square = new JButton("x^2");
panel.add(square);
square.addActionListener(this);
cube = new JButton("x^3");
panel.add(cube);
cube.addActionListener(this);
clear = new JButton("CLEAR");
panel.add(clear);
clear.addActionListener(this); // panel buttons till here
container.add(panel);
container.add("North", textpanel); // sets position of text panel to the top of the window
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // will close the program when clicked on x
}
public static void main(String args[]) {
try { // tests the code for errors while running
UIManager.setLookAndFeel("javax.swing.plaf.nimbus.NimbusLookAndFeel"); // sets the way the calculator window looks
}
catch(Exception e) { // executes the code in catch if error in try
}
Main window = new Main(); // Calculator object created
window.pack(); // this will size the window so that all contents are at their preferred size(or bigger)
window.setTitle("SCIENTIFIC CALCULATOR"); // sets the title of the window (seen on top of window)
window.setVisible(true); // window is made visible
}
public void actionPerformed(ActionEvent e) { // button clicks class
String inp = e.getActionCommand();
if (inp.equals("1")) {
if (z == 0) {
field.setText(field.getText() + "1"); // setText receives a string while getText returns it
} else {
field.setText("");
field.setText(field.getText() + "1");
z = 0;
}
}
if (inp.equals("2")) {
if (z == 0) {
field.setText(field.getText() + "2");
} else {
field.setText("");
field.setText(field.getText() + "2");
z = 0;
}
}
if (inp.equals("3")) {
if (z == 0) {
field.setText(field.getText() + "3");
} else {
field.setText("");
field.setText(field.getText() + "3");
z = 0;
}
}
if (inp.equals("4")) {
if (z == 0) {
field.setText(field.getText() + "4");
} else {
field.setText("");
field.setText(field.getText() + "4");
z = 0;
}
}
if (inp.equals("5")) {
if (z == 0) {
field.setText(field.getText() + "5");
} else {
field.setText("");
field.setText(field.getText() + "5");
z = 0;
}
}
if (inp.equals("6")) {
if (z == 0) {
field.setText(field.getText() + "6");
} else {
field.setText("");
field.setText(field.getText() + "6");
z = 0;
}
}
if (inp.equals("7")) {
if (z == 0) {
field.setText(field.getText() + "7");
} else {
field.setText("");
field.setText(field.getText() + "7");
z = 0;
}
}
if (inp.equals("8")) {
if (z == 0) {
field.setText(field.getText() + "8");
} else {
field.setText("");
field.setText(field.getText() + "8");
z = 0;
}
}
if (inp.equals("9")) {
if (z == 0) {
field.setText(field.getText() + "9");
} else {
field.setText("");
field.setText(field.getText() + "9");
z = 0;
}
}
if (inp.equals("0")) {
if (z == 0) {
field.setText(field.getText() + "0");
} else {
field.setText("");
field.setText(field.getText() + "0");
z = 0;
}
}
if (inp.equals("CLEAR")) {
field.setText("");
x = 0;
y = 0;
z = 0;
}
if (inp.equals("log")) {
if (field.getText().equals("")) {
field.setText("");
} else {
answer = Math.log(Double.parseDouble(field.getText()));
field.setText("");
field.setText(field.getText() + answer);
}
}
if (inp.equals("1/x")) {
if (field.getText().equals("")) {
field.setText("");
} else {
answer = 1 / Double.parseDouble(field.getText());
field.setText("");
field.setText(field.getText() + answer);
}
}
if (inp.equals("x^2")) {
if (field.getText().equals("")) {
field.setText("");
} else {
answer = Math.pow(Double.parseDouble(field.getText()), 2);
field.setText("");
field.setText(field.getText() + answer);
}
}
if (inp.equals("x^3")) {
if (field.getText().equals("")) {
field.setText("");
} else {
answer = Math.pow(Double.parseDouble(field.getText()), 3);
field.setText("");
field.setText(field.getText() + answer);
}
}
if (inp.equals(".")) {
if (y == 0) {
field.setText(field.getText() + ".");
y = 1;
} else {
field.setText(field.getText());
}
}
if (inp.equals("+")) {
if (field.getText().equals("")) {
field.setText("");
inp1 = 0;
ch = '+';
} else {
inp1 = Double.parseDouble(field.getText());
field.setText("");
ch = '+';
y = 0;
x = 0;
}
}
if (inp.equals("-")) {
if (field.getText().equals("")) {
field.setText("");
inp1 = 0;
ch = '-';
} else {
x = 0;
y = 0;
inp1 = Double.parseDouble(field.getText());
field.setText("");
ch = '-';
}
}
if (inp.equals("/")) {
if (field.getText().equals("")) {
field.setText("");
inp1 = 1;
ch = '/';
} else {
x = 0;
y = 0;
inp1 = Double.parseDouble(field.getText());
ch = '/';
field.setText("");
}
}
if (inp.equals("*")) {
if (field.getText().equals("")) {
field.setText("");
inp1 = 1;
ch = '*';
} else {
x = 0;
y = 0;
inp1 = Double.parseDouble(field.getText());
ch = '*';
field.setText("");
}
}
if (inp.equals("√")) {
if (field.getText().equals("")) {
field.setText("");
} else {
answer = Math.sqrt(Double.parseDouble(field.getText()));
field.setText("");
field.setText(field.getText() + answer);
}
}
if (inp.equals("SIN")) {
if (field.getText().equals("")) {
field.setText("");
} else {
answer = Math.sin(Double.parseDouble(field.getText()));
field.setText("");
field.setText(field.getText() + answer);
}
}
if (inp.equals("COS")) {
if (field.getText().equals("")) {
field.setText("");
} else {
answer = Math.cos(Double.parseDouble(field.getText()));
field.setText("");
field.setText(field.getText() + answer);
}
}
if (inp.equals("TAN")) {
if (field.getText().equals("")) {
field.setText("");
} else {
answer = Math.tan(Double.parseDouble(field.getText()));
field.setText("");
field.setText(field.getText() + answer);
}
}
if (inp.equals("=")) {
if (field.getText().equals("")) {
field.setText("");
} else {
inp2 = Double.parseDouble(field.getText());
if(ch == '+') { // if statement for all basic operations
result = inp1 + inp2;
} else if(ch == '-'){
result = inp1 - inp2;
} else if(ch == '/'){
result = inp1 / inp2;
} else{
result = inp1 * inp2;
}
field.setText("");
field.setText(field.getText() + result);
z = 1;
}
}
}
}
The code for this calculator works fine but I want to know what the purpose of the z variable is and what it is doing. I do understand the rest but I've just been wondering it's use for the past half hour so any help will be greatly appreciated
I saw that using the z variable in this fashion will make the code better and easier to understand so i wrote it, however am unsure what it's purpose is.

You are using z as a flag. z==0 means you append input to the field. z==1 means you reset the field and start with new input.
After each calculation you want to reset field. So z has been set to 1.

The z variable is used as a toggle to work out if the next number pressed should be apeneded, or if the output needs to be reset. In the equals = key code below if (inp.equals("=")) { specifically z = 1;, we can see that this is the only place in code where the value of z is set to anything other than 0.
Then when a number key is pushed the code checks that z is not 0 then it adds the member to the output field.setText(field.getText() + "2");, however, it the equals key has been pushed first (where z became 1) then it clears the output field.setText(""); and field.setText(field.getText() + "2");

Related

Chess Interface with Piece IMG implementation

I am currently making a Chess program as a project for my data structures class. We pretty much have most of the code complete but for some reason, I cannot figure out how to place the pieces onto any help would be Greatly Appreciated.
we are using JAVA and Swing
MAIN GOAL:
get piece IMG to go onto the board:
public abstract class UserInterface {
//FIELDS
protected Board board;
//The board that the UI will be used to interact with
//CONSTRUCTORS
public UserInterface(Board board) {
//Constructor for UserInterface implementers
this.board = board;
}
public UserInterface() {
}
//OTHER
public abstract Move promptMove();
public abstract PieceType promptPromotion();
public abstract void updateBoard();
public abstract void playGame(Interactable whiteUser, Interactable blackUser);
}
class CommandInterface extends UserInterface {
private GraphicInterface gui = null;
//CONSTRUCTORS
public CommandInterface(Board board) {
//Main constructor for the CommandInterface
super(board);
gui = new GraphicInterface(board, null);
gui.initializeGui();
}
//OTHER
public void playGame(Interactable whiteUser, Interactable blackUser) {
//Starts a game using the UI and the board.
//[TEST CODE] Probably will clean this up later
board.setUsers(whiteUser, blackUser);
updateBoard();
Scanner input = new Scanner(System.in);
boolean gameOver = false;
while(!gameOver) {
boolean illegalMove;
do {
try {
// System.out.println("Press enter to move");
// String s = input.nextLine();
board.doMove(board.getCurrentUser().getMove());
illegalMove = false;
} catch(IllegalArgumentException e) {
System.out.println(e.getMessage());
illegalMove = true;
}
if(board.getState() == BoardState.CHECKMATE) {
System.out.println("\n" + board.getTurn().toString() + " is now checkmated. Game over!");
gameOver = true;
illegalMove = false;
} else if(board.getState() == BoardState.CHECK) {
System.out.println("\n" + board.getTurn().toString() + " has been put in check!");
illegalMove = false;
} else if(board.getState() == BoardState.STALEMATE) {
System.out.println("\n" + board.getTurn().toString() + " is now stalemated. Game over!");
gameOver = true;
illegalMove = false;
}
} while(illegalMove);
updateBoard();
}
}
public Move promptMove() {
//Takes user input for a move and returns the Move object
Scanner input = new Scanner(System.in);
String move;
boolean again;
do {
System.out.print("Enter your move (? for help): ");
move = input.nextLine();
if(move.equals("?")) {
//If the user asks for help
System.out.printf("%nHELP: To move, you must type a move in the following format:"
+ "%n<STARTING TILE> <ENDING TILE>"
+ "%nThe starting tile is the tile of the piece you wish to move."
+ "%nThe ending tile is the tile you wish to move your piece to."
+ "%nEach tile is notated with \"<COLUMN><RANK>\", example: \"e5\""
+ "%n%nFull example move: \"a5 g5\"%n");
again = true;
} else if(move.equalsIgnoreCase("CASTLE")) {
System.out.print("Enter the movement of the King: ");
move = input.nextLine();
return new Move(board, move, true);
} else again = false;
} while(again);
//Reprompt if the user asks for help
return new Move(board, move);
//Returns a Move object made from the SMN string
}
public PieceType promptPromotion() {
Scanner input = new Scanner(System.in);
System.out.print("Pawn has promotion available.\nWhich piece to promote to? ");
while(true) {
String type = input.nextLine();
PieceType promotion = PieceType.NONE;
if (type.equalsIgnoreCase("PAWN")) promotion = PieceType.PAWN;
else if (type.equalsIgnoreCase("ROOK")) promotion = PieceType.ROOK;
else if (type.equalsIgnoreCase("KNIGHT")) promotion = PieceType.KNIGHT;
else if (type.equalsIgnoreCase("BISHOP")) promotion = PieceType.BISHOP;
else if (type.equalsIgnoreCase("QUEEN")) promotion = PieceType.QUEEN;
else if (type.equalsIgnoreCase("KING")) promotion = PieceType.KING;
else if (type.equalsIgnoreCase("EARL")) promotion = PieceType.EARL;
else if (type.equalsIgnoreCase("MONK")) promotion = PieceType.MONK;
if(promotion == PieceType.NONE) {
System.out.print("\nInvalid type, please try again: ");
continue;
}
return promotion;
}
}
public void updateBoard() {
//Prints the board in basic ASCII format.
gui.updateBoard();
drawCaptured(Color.WHITE);
System.out.println();
//Adds a line before the board starts printing
int squaresPrinted = 0;
//Keeps track of the total number of squares that has been printed
for(int y = board.getZeroSize(); y >= 0; y--) {
//Loop through y-values from top to bottom
if(y != board.getZeroSize()) System.out.println();
//If not on the first iteration of y-loop, go down a line (avoids leading line break)
System.out.print((y + 1) + " ");
//Print the rank number
for(int x = 0; x <= board.getZeroSize(); x++) {
//Loop through x-values from left to right
if(board.pieceAt(x, y) != null) {
//If there is a piece on the tile
if(squaresPrinted % 2 == 0) System.out.print("[" + board.pieceAt(x, y).getString() + "]");
//If squaresPrinted is even, print "[<pString>]"
else System.out.print("(" + board.pieceAt(x, y).getString() + ")");
//If squaresPrinted is odd, print "(<pString>)"
} else {
//If there is no piece on the tile
if(squaresPrinted % 2 == 0) System.out.print("[ ]");
//If squaresPrinted is even, print "[ ]"
else System.out.print("( )");
//If squaresPrinted is odd, print "( )"
}
squaresPrinted++;
//Increment squaresPrinted for each iteration of the x-loop
}
squaresPrinted++;
//Increment squaresPrinted for each iteration of the y-loop
}
System.out.println();
System.out.print(" ");
//Print an extra line and the leading whitespace for the column identifiers
for(int i = 0; i <= board.getZeroSize(); i++) {
//Repeat <size> times
System.out.print(" " + (char) (i + 97));
//Print the column identifier chars by casting from int
}
drawCaptured(Color.BLACK);
//Prints all black pieces that have been captured
System.out.println();
}
private void drawCaptured(Color color) {
//Prints captured pieces of either color.
System.out.println();
//Prints a blank line
ArrayList<String> capturedPieces = board.getCaptured(color);
if(capturedPieces == null) return;
for(String p : capturedPieces) {
System.out.print(p + " ");
//TODO: Remove trailing whitespace
}
}
}
#SuppressWarnings("ALL")
class GraphicInterface extends UserInterface implements MouseListener {
private JButton[][] chessBoardSquares = null;
private JButton buttonsAndLabels = new JButton();
private JLabel message = null;
private String columnNames = null;
private Board board = null;
private JFrame frame;
public ImageIcon BK;
public ImageIcon WP;
public ImageIcon WR;
public ImageIcon WN;
public ImageIcon WB;
public ImageIcon WQ;
public ImageIcon WK;
public ImageIcon BP;
public ImageIcon BR;
public ImageIcon BN;
public ImageIcon BB;
public ImageIcon BQ;
public ImageIcon blank;
private Object ImageIcon;
public GraphicInterface(Board board, GraphicInterface frame) {
super(board);
// super(board);
this.board = board;
try {
//remove later
String path = "src/chuss/icons/";
new ImageIcon(javax.imageio.ImageIO.read(new File(path + "BK.gif")));
new ImageIcon(javax.imageio.ImageIO.read(new File(path + "WP.gif")));
new ImageIcon(javax.imageio.ImageIO.read(new File(path + "WR.gif")));
WN = new ImageIcon(javax.imageio.ImageIO.read(new File(path + "WN.gif")));
WB = new ImageIcon(javax.imageio.ImageIO.read(new File(path + "WB.gif")));
WQ = new ImageIcon(javax.imageio.ImageIO.read(new File(path + "WQ.gif")));
WK = new ImageIcon(javax.imageio.ImageIO.read(new File(path + "WK.gif")));
BP = new ImageIcon(javax.imageio.ImageIO.read(new File(path + "BP.gif")));
BR = new ImageIcon(javax.imageio.ImageIO.read(new File(path + "BR.gif")));
BN = new ImageIcon(javax.imageio.ImageIO.read(new File(path + "BN.gif")));
BB = new ImageIcon(javax.imageio.ImageIO.read(new File(path + "BB.gif")));
BQ = new ImageIcon(javax.imageio.ImageIO.read(new File(path + "BQ.gif")));
blank = new ImageIcon(javax.imageio.ImageIO.read(new File(path + "blank.png")));
buttonsAndLabels.addMouseListener((MouseListener) this);
buttonsAndLabels.add(buttonsAndLabels);
buttonsAndLabels.setSize(600, 600);
//buttonsAndLabels.getContentPane().setPreferredSize(new Dimension(800, 700));
} catch(IOException e) {
e.getCause();
e.printStackTrace();
}
buttonsAndLabels = new JButton((Action) new BorderLayout(3, 3));
chessBoardSquares = new JButton[8][8];
message = new JLabel("Chuss Champ is ready to play!");
columnNames = "ABCDEFGH";
initializeGui();
}
public GraphicInterface(JButton buttonsAndLabels) {
super();
}
public GraphicInterface(Board board) {
}
#Override
public Move promptMove() {
return null;
}
#Override
public PieceType promptPromotion() {
return null;
}
public final JButton initializeGui() {
// set up the main GUI
assert false;
buttonsAndLabels.setBorder(new EmptyBorder(5, 5, 5, 5));
JToolBar tools = new JToolBar();
tools.setFloatable(false);
buttonsAndLabels.add(tools, BorderLayout.PAGE_START);
tools.add(new JButton("New")); // TODO - add functionality!
tools.add(new JButton("Save")); // TODO - add functionality!
tools.add(new JButton("Restore")); // TODO - add functionality!
tools.addSeparator();
tools.add(new JButton("Resign")); // TODO - add functionality!
tools.addSeparator();
tools.add(message);
buttonsAndLabels.add(new JLabel("?"), BorderLayout.LINE_START);
// create the chess board squares
buttonsAndLabels = new JButton((Action) new GridLayout(0, 9));
buttonsAndLabels.setBorder(new LineBorder(java.awt.Color.BLACK));
buttonsAndLabels.add((Component) ImageIcon);
updateBoard();
Runnable r = () -> {
JFrame f = new JFrame("CHUSS");
f.add(getGui());
f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
f.setLocationByPlatform(true);
// ensures the frame is the minimum size it needs to be
// in order display the components within it
f.pack();
// ensures the minimum size is enforced.
f.setMinimumSize(f.getSize());
f.setVisible(true);
};
SwingUtilities.invokeLater(r);
assert false;
return null;
}
public void updateBoard() {
//Prints the board in graphical format.
buttonsAndLabels.removeAll();
Insets buttonMargin = new Insets(0,0,0,0);
for (int ii = 7; ii >= 0; ii--) {
for (int jj = 0; jj < chessBoardSquares.length; jj++) {
JButton b = new JButton();
b.setMargin(buttonMargin);
// our chess pieces are 64x64 px in size, so we'll
// 'fill this in' using a transparent icon..
Piece p = board.pieceAt(jj, ii);
ImageIcon icon = new ImageIcon();
if (p instanceof Pawn && p.getColor() == Color.WHITE) icon = WP;
else if (p instanceof Rook && p.getColor() == Color.WHITE) icon = WR;
else if (p instanceof Knight && p.getColor() == Color.WHITE) icon = WN;
else if (p instanceof Bishop && p.getColor() == Color.WHITE) icon = WB;
else if (p instanceof Queen && p.getColor() == Color.WHITE) icon = WQ;
else if (p instanceof King && p.getColor() == Color.WHITE) icon = WK;
else if (p instanceof Pawn && p.getColor() == Color.BLACK) icon = BP;
else if (p instanceof Rook && p.getColor() == Color.BLACK) icon = BR;
else if (p instanceof Knight && p.getColor() == Color.BLACK) icon = BN;
else if (p instanceof Bishop && p.getColor() == Color.BLACK) icon = BB;
else if (p instanceof Queen && p.getColor() == Color.BLACK) icon = BQ;
else if (p instanceof King && p.getColor() == Color.BLACK) icon = BK;
else if (p == null) icon = blank;
b.setIcon(icon);
if ((jj % 2 == 1 && ii % 2 == 1)
//) {
|| (jj % 2 == 0 && ii % 2 == 0)) {
b.setBackground(java.awt.Color.WHITE);
} else {
b.setBackground(java.awt.Color.GRAY);
}
chessBoardSquares[jj][ii] = b;
buttonsAndLabels.add(chessBoardSquares[jj][ii]);
}
}
initializeGui();
// fill the top row
for (int ii = 0; ii <= 7; ii++) {
buttonsAndLabels.add(
new JLabel(columnNames.substring(ii, ii + 1),
SwingConstants.CENTER));
}
// fill the black non-pawn piece row
for (int ii = 7; ii >= 0; ii--) {
for (int jj = 0; jj < 8; jj++) {
if (jj == 0) {
buttonsAndLabels.add(new JLabel("" + (ii + 1),
SwingConstants.CENTER));
}
buttonsAndLabels.add(chessBoardSquares[jj][ii]);
}
}
buttonsAndLabels.updateUI();
}
#Override
public void playGame(Interactable whiteUser, Interactable blackUser) {
GraphicInterface gui = new GraphicInterface(buttonsAndLabels);
gui.getChessBoard();
}
public JComponent getChessBoard() {
return buttonsAndLabels;
}
public JComponent getGui() {
return buttonsAndLabels;
}
#Override
public void mouseClicked(MouseEvent e) {
}
#Override
public void mousePressed(MouseEvent e) {
}
#Override
public void mouseReleased(MouseEvent e) {
}
#Override
public void mouseEntered(MouseEvent e) {
}
#Override
public void mouseExited(MouseEvent e) {
}

How can I check java console output

I am making SOS game with "stack".No other data structures such as normal array, string etc.
Gameboard size 3*6 and I am using random for determining letters.
But I don't know is the game over or not.
How can I control is there any horizontal or vertical sos at the console
Here is my code(I am beginner)
public static void main(String[] args) {
Random rnd = new Random();
Stack S1 = new Stack(6);
Stack S2 = new Stack(6);
Stack S3 = new Stack(6);
Stack ts1 = new Stack(6);
Stack ts2 = new Stack(6);
Stack ts3 = new Stack(6);
int Round = 0;
int satir;
boolean winner = false;
// for S1
int i = 0;
while (i != 6) { // 6time
i++;
// System.out.println(i);
if (rnd.nextBoolean()) {
S1.push("S");
} else {
S1.push("O");
}
}
// for S2
i = 0;
while (i != 6) {
i++;
if (rnd.nextBoolean()) {
S2.push("S");
} else {
S2.push("O");
}
}
// for S3
i = 0;
while (i != 6) {
i++;
if (rnd.nextBoolean()) {
S3.push("S");
} else {
S3.push("O");
}
}
int a = 0, b = 0, c = 0;
int tempa = a;
int tempb = b;
int tempc = c;
while (!winner) {
System.out.println("User" + ((Round % 2) + 1) + ":"); // User1:
// User2:
satir = rnd.nextInt(3) + 1;
if (satir == 1 && a != 6) {
a++;
}
if (satir == 2 && b != 6) {
b++;
}
if (satir == 3 && c != 6) {
c++;
}
tempa = a;
tempb = b;
tempc = c;
System.out.print("S1 ");
while (a > 0) { // S1 in icini yazdir bosalt ts1e kaydet
System.out.print(S1.peek() + " ");
ts1.push(S1.pop());
a--;
}
a = tempa;
while (!ts1.isEmpty()) { // S1i tekrar doldur
S1.push(ts1.pop());
}
System.out.println();
System.out.print("S2 ");
while (b > 0) { // S2 in icini yazdir bosalt ts1e kaydet
System.out.print(S2.peek() + " ");
ts2.push(S2.pop());
b--;
}
b = tempb;
while (!ts2.isEmpty()) { // S2i tekrar doldur
S2.push(ts2.pop());
}
System.out.println();
System.out.print("S3 ");
while (c > 0) { // S3 in icini yazdir bosalt ts1e kaydet
System.out.print(S3.peek() + " ");
ts3.push(S3.pop());
c--;
}
c = tempc;
while (!ts3.isEmpty()) { // S3i tekrar doldur
S3.push(ts3.pop());
}
System.out.println();
// check if there is sos winner=true;
if (a > 2) { //check S1 Horizontal
for (int yatay1 = 0; yatay1 < a; yatay1++) {
if (S1.peek().equals("S")) {
ts1.push(S1.pop());
if (S1.peek().equals("O")) {
ts1.push(S1.pop());
if (S1.peek().equals("S")) {
System.out.println("SOS-wow");
winner = true;
} else {
while (!ts1.isEmpty()) {
S1.push(ts1.pop());
}
}
} else {
S1.push(ts1.pop());
}
}
}
}
Round++;
} // end of loop
}

Messed up my code terribly with throwing/catching exceptions and try...catch blocks

Alright, I know I messed up bad with catching and throwing exceptions, but I can't figure them out for the life of me. I think I'm mixing several different ways to do them. Can anyone guide me in the right direction (not looking for complete answer, just what the code is supposed to resemble)? It gets stuck on the "throw new ();" lines, and the catch blocks. Everything else seems to not have any issues. It's supposed to be an improvement on a previous project, http://pastebin.com/sjR0BZBY. you can run this if you'd like to see what the program is supposed to do if that helps.
public class Project6 extends JFrame
{
// Declaring variables
private JLabel enterLabel, resultsLabel, errorLabel;
private JTextField queryField, errorField;
private JButton goB, clearB;
private JTextArea textArea;
private Container c;
private JPanel panel;
// main method
public static void main(String[] args)
{
Project6 p6 = new Project6();
p6.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
p6.setSize(new Dimension(455, 550));
p6.setVisible(true);
}
// creating JFrame
public Project6()
{
c = getContentPane();
c.setLayout(new FlowLayout());
setTitle("");
c.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));
ButtonHandler handler = new ButtonHandler();
enterLabel = new JLabel("Enter query here:");
c.add(enterLabel);
queryField = new JTextField(35);
c.add(queryField);
goB = new JButton("GO!");
c.add(goB);
goB.addActionListener(handler);
resultsLabel = new JLabel("Results:");
c.add(resultsLabel);
textArea = new JTextArea(20, 30);
c.add(textArea);
errorLabel = new JLabel("-------------Error messages:");
c.add(errorLabel);
errorField = new JTextField(35);
c.add(errorField);
clearB = new JButton("Clear");
c.add(clearB);
clearB.addActionListener(handler);
}
// ActionListener for buttons
private class ButtonHandler implements ActionListener{
public void actionPerformed(ActionEvent e){
// Go! button
if (e.getSource() == goB){
String str = queryField.getText();
StringTokenizer tokens = new StringTokenizer(str, ", ");
int numToks = tokens.countTokens();
String[] tokenArray = new String[numToks];
int i = 0;
// creating all tokenizing, validations, and the works. Try and bear with it, it works but it's a rough trip
while (tokens.hasMoreTokens()){
// while loop to create tokens
while (tokens.hasMoreTokens()){
str = tokens.nextToken();
tokenArray[i] = str;
System.out.println(tokenArray[i]);
i++; }
// start if verifications, everything else
String query = tokenArray[3];
String optok = tokenArray[4];
String index = tokenArray[5];
String qField = queryField.getText();
try {
if (qField.equals(""))
throw new MissingInputException();
else {
if (numToks != 6)
throw new IncorrectFormatException();
else {
if (tokenArray[0].equalsIgnoreCase("Report"))
{
if (tokenArray[1].equalsIgnoreCase("all"))
{
if (tokenArray[2].equals("where"))
{
if (tokenArray[3].equals("basePrice") || tokenArray[3].equals("quality") || tokenArray[3].equals("numInStock"))
{
if (tokenArray[4].equals("<") || tokenArray[4].equals(">") || tokenArray[4].equals(">=")||tokenArray[4].equals("<=")||tokenArray[4].equals("=="))
{
if (query.equals("basePrice"))
{ BasePriceM(query, index, optok); }
else if (query.equals("quality"))
{ QualityM(query, index, optok); }
else if (query.equals("numInStock"))
{ NumInStockM(query, index, optok); }
}
else
throw new InvalidOperatorException();
}
else
throw new InvalidLValueException();
}
else
throw new InvalidQualifierException();
}
else
throw new InvalidSelectorException();
}
else
throw new IllegalStartOfQueryException();
}
}
} // end try
catch(MissingInputException aa)
{
errorField.setText("Enter an expression");
queryField.setText("");
}
catch(IncorrectFormatException ab)
{
errorField.setText("Error, field too large or small");
queryField.setText("");
}
catch(IllegalStartOfQueryException ac)
{
errorField.setText("Error, report expected");
queryField.setText("");
}
catch(InvalidSelectorException ad)
{
errorField.setText("Error, all expected");
queryField.setText("");
}
catch(InvalidQualifierException ae)
{
errorField.setText("Error, where expected");
queryField.setText("");
}
catch(InvalidLValueException af)
{
errorField.setText("Error, basePrice, Quality, numInStock expected");
queryField.setText("");
}
catch(InvalidOperatorException ag)
{
errorField.setText("Error, < > >= <= == expected");
queryField.setText("");
}
catch(NumberFormatException af)
{
}
}// end of while loop
} // end go button
// clear all button
if (e.getSource() == clearB)
{
queryField.setText("");
textArea.setText("");
errorField.setText("");
}
}
} // end buttons
// methods for printing
public void BasePriceM(String query, String index, String optok)
{
int pos = 0;
int index1 = index.indexOf(".", pos);
if (index1 > -1)
{
double b = Double.parseDouble(index);
if (b > 0.05 && b < 5400.0)
{printBasePrice(query, optok, b);}
else{
errorField.setText("Invalid query, must be between 0.05 and 5400.0");
queryField.setText(""); }}
}
public void QualityM(String query, String index, String optok)
{
int pos2 = 0;
int index2 = index.indexOf(".", pos2);
if (index2 == -1)
{
int n = Integer.parseInt(index);
if (n > 0)
{
printBasePrice(query, optok, n);
}
else{
errorField.setText("Invalid query, must be greater than 0");
queryField.setText(""); }}
}
public void NumInStock(String query, String index, String optok)
{
int pos2 = 0;
int index2 = index.indexOf(".", pos2);
if (index2 == -1)
{
int n = Integer.parseInt(index);
if (n > 0)
{
printBasePrice(query, optok, n);
}
else{
errorField.setText("Invalid query, must be greater than 0");
queryField.setText("");} }
}
public void printQuality(String query, String optok, int p)
{
textArea.append("Search for " + query +" "+ optok +" "+ p + "\n");
}
public void printBasePrice(String query, String optok, double b)
{
textArea.append("Search for " + query +" "+ optok +" "+ b + "\n");
}
public void printNumInStock(String query, String optok, int n)
{
textArea.append("Search for " + query +" "+ optok +" "+ n + "\n");
}
} // end program`enter code here`

Reacting to a specific char - TCP and char[][] issue

I'm creating a TCP game of Battleship in Java, and as I've made some functions work, methods that used to work no longer work.
Here's what's happening when it's a users turn. A bomb being dropped on 2 diffrent char[][], where clientGrid is the actual grid where the client has his ships. It's on this grid where the dropBomb method is being printed, and tells us whether a bomb has hit or not. clientDamage is just an overview for the server to see where he has previously dropped bombs.
if (inFromServer.ready()) {
System.out.println("\nInput coordinate");
int x = scan.nextInt();
int y = scan.nextInt();
System.out.println(dropBomb(x, y, clientGrid));
dropBomb(x, y, clientDamage);
outToClient.writeChars("Enemy player has targeted " + x + ", " + y +'\n');
System.out.println(printBoard(clientDamage));
}
Here's the drop bomb method. It's proved to work before, however I have made some small changes to it. However I can't see why it wouldn't work. + indicates that there is a ship, x indicates that the target already has been bombed, and the else is ~, which is water. The method always returns "Nothing was hit on this coordinate...", and I can't seem to figure out why?
public static String dropBomb(int row, int col, char[][] board) {
if (row < gridSize && col < gridSize) {
if (board[row][col] == '+') {
board[row][col] = 'x';
return "Ship has been hit!";
} else if (board[row][col] == 'x') {
return "Already bombed.";
} else {
board[row][col] = 'x';
return "Nothing was hit on this coordinate...";
}
} else {
return "No such coordinate.";
}
}
Here is the full code... can someone please point out what I'm missing?
//server = player 1
//client = player 2
public class BattleshipGame {
public static ArrayList<Ship> fleet;
public static InetAddress clientAddress;
public static BattleshipGame battleship;
private final static int gridSize = 11;
public final static int numberOfShips = 3;
public static char[][] serverGrid;
public static char[][] clientGrid;
public static char[][] serverDamage;
public static char[][] clientDamage;
private int whosTurn;
private int whoStarts;
public static int count;
public static int bombCount;
public BattleshipGame() {
whoStarts = 0;
start();
showShipList();
}
public static String printBoard(char[][] board) {
String out = "";
for (int i = 1; i < board.length; i++) {
for (int j = 1; j < board.length; j++) {
out += board[j][i];
}
out += '\n';
}
return out;
}
public void start() {
Random rand = new Random();
if (rand.nextBoolean()) {
whoStarts = 1;
whosTurn = 1;
} else {
whoStarts = 2;
whosTurn = 2;
}
whoStarts = 1;
whosTurn = 1;
System.out.println("Player " + whoStarts + " starts\n");
}
public void initializeGrid(int playerNo) {
serverGrid = new char[gridSize][gridSize];
for (int i = 0; i < serverGrid.length; i++) {
for (int j = 0; j < serverGrid.length; j++) {
serverGrid[i][j] = '~';
}
}
serverDamage = new char[gridSize][gridSize];
for (int i = 0; i < serverDamage.length; i++) {
for (int j = 0; j < serverDamage.length; j++) {
serverDamage[i][j] = '~';
}
}
clientGrid = new char[gridSize][gridSize];
for (int i = 0; i < clientGrid.length; i++) {
for (int j = 0; j < clientGrid.length; j++) {
clientGrid[i][j] = '~';
}
}
clientDamage = new char[gridSize][gridSize];
for (int i = 0; i < clientDamage.length; i++) {
for (int j = 0; j < clientDamage.length; j++) {
clientDamage[i][j] = '~';
}
}
if (playerNo == 1) {
System.out.println("\nYour grid (player 1):\n"
+ printBoard(serverGrid));
} else if (playerNo == 2) {
System.out.println("\nYour grid (player 2):\n"
+ printBoard(clientGrid));
} else {
System.out.println("No such player.");
}
}
public static void deployShip(char[][] board, Ship ship, char direction,
int x, int y) {
if (direction == 'H') {
if (x < gridSize && y < gridSize) {
for (int i = 0; i < ship.getSize(); i++) {
board[x + i][y] = '+';
}
System.out
.println("Ship has been placed horizontally on coordinates "
+ x + ", " + y + ".");
} else {
System.out.println("Unable to place ship in this coordinate.");
}
} else if (direction == 'V') {
if (x < gridSize && y < gridSize) {
for (int i = 0; i < ship.getSize(); i++) {
board[x][y + i] = '+';
}
System.out
.println("Ship has been placed vertically on coordinates "
+ x + ", " + y + ".");
} else {
System.out.println("Unable to place ship in this coordinate.");
}
}
}
public static String dropBomb(int row, int col, char[][] board) {
if (row < gridSize && col < gridSize) {
if (board[row][col] == '+') {
System.out.println(board[row][col]);
board[row][col] = 'x';
bombCount++;
return "Ship has been hit!";
}
if (board[row][col] == 'x') {
System.out.println(board[row][col]);
bombCount++;
return "Already bombed.";
}
if (board[row][col] == '~') {
System.out.println(board[row][col]);
board[row][col] = 'x';
bombCount++;
return "Nothing was hit on this coordinate...";
}
} else {
return "No such coordinate.";
}
return "";
}
public void showShipList() {
System.out
.println("Choose ships to add to your fleet from the following list ("
+ numberOfShips + " ships allowed):");
ArrayList<Ship> overview = new ArrayList<Ship>();
Ship ac = new Ship("Aircraft carrier", 5, false);
Ship bs = new Ship("Battleship", 4, false);
Ship sm = new Ship("Submarine", 3, false);
Ship ds = new Ship("Destroyer", 3, false);
Ship sp = new Ship("Patrol Boat", 2, false);
overview.add(ac);
overview.add(bs);
overview.add(sm);
overview.add(ds);
overview.add(sp);
for (int i = 0; i < overview.size(); i++) {
System.out.println(i + 1 + ". " + overview.get(i));
}
}
public static ArrayList<Ship> createFleet(ArrayList<Ship> fleet, int choice) {
if (count < numberOfShips && choice > 0 && choice < 6) {
if (choice == 1) {
Ship ac = new Ship("Aircraft carrier", 5, false);
fleet.add(ac);
count++;
System.out.println("Aircraft carrier has been added to fleet.");
} else if (choice == 2) {
Ship bs = new Ship("Battleship", 4, false);
fleet.add(bs);
count++;
System.out.println("Battleship has been added to fleet.");
} else if (choice == 3) {
Ship sm = new Ship("Submarine", 3, false);
fleet.add(sm);
count++;
System.out.println("Submarine has been added to fleet.");
} else if (choice == 4) {
Ship ds = new Ship("Destroyer", 3, false);
fleet.add(ds);
count++;
System.out.println("Destroyer has been added to fleet.");
} else if (choice == 5) {
Ship sp = new Ship("Patrol Boat", 2, false);
fleet.add(sp);
count++;
System.out.println("Patrol boat has been added to fleet.");
}
} else {
System.out.println("Not an option.");
}
System.out.println("\nYour fleet now contains:");
for (Ship s : fleet) {
System.out.println(s);
}
return fleet;
}
}
public class TCPServer extends BattleshipGame {
private static final int playerNo = 1;
public static void main(String[] args) {
System.out.println("You are player: " + playerNo);
battleship = new BattleshipGame();
try {
InetAddress.getLocalHost().getHostAddress();
ServerSocket serverSocket = new ServerSocket(6780);
Socket socket = serverSocket.accept();
BufferedReader inFromServer = new BufferedReader(new InputStreamReader(System.in));
BufferedReader inFromClient = new BufferedReader(new InputStreamReader(socket.getInputStream()));
DataOutputStream outToClient = new DataOutputStream(socket.getOutputStream());
Scanner scan = new Scanner(System.in);
while (true) {
if (inFromServer.ready()) {
setup(scan, playerNo);
System.out.println("\nInput coordinate");
int x = scan.nextInt();
int y = scan.nextInt();
System.out.println(dropBomb(x, y, clientGrid));
System.out.println(printBoard(clientGrid));
dropBomb(x, y, clientDamage);
outToClient.writeChars("Enemy player has targeted " + x + ", " + y +'\n');
printBoard(clientDamage);
}
if (inFromClient.ready()) {
System.out.println(inFromClient.readLine());
System.out.println(printBoard(serverGrid));
}
}
// socket.close();
// serverSocet.close();
} catch (IOException e) {
e.printStackTrace();
}
}
private static void setup(Scanner inFromUser, int playerNo) {
fleet = new ArrayList<Ship>();
while (count < numberOfShips) {
createFleet(fleet, inFromUser.nextInt());
}
battleship.initializeGrid(playerNo);
for (int i = 0; i < fleet.size(); i++) {
System.out.println(fleet.get(i));
System.out.println("Define direction (V/H) plus coordinates");
deployShip(serverGrid, fleet.get(i), inFromUser.next().charAt(0), inFromUser.nextInt(), inFromUser.nextInt());
}
System.out.println("Placements:\n" + printBoard(serverGrid));
System.out.println("Fleet has been deployed. Press enter to continue.\n");
}
}
public class TCPClient extends BattleshipGame {
private static final int playerNo = 2;
public static void main(String[] args) {
System.out.println("You are player: " + playerNo);
battleship = new BattleshipGame();
try {
InetAddress.getLocalHost().getHostAddress();
Socket socket = new Socket(InetAddress.getLocalHost()
.getHostAddress(), 6780);
DataOutputStream dataOutputStream = new DataOutputStream(
socket.getOutputStream());
BufferedReader inFromServer = new BufferedReader(new InputStreamReader(socket.getInputStream()));
BufferedReader inFromClient = new BufferedReader(new InputStreamReader(System.in));
Scanner scan = new Scanner(System.in);
setup(scan, playerNo);
while (true) {
if (inFromClient.ready()) {
System.out.println("\nInput coordinate");
int x = scan.nextInt();
int y = scan.nextInt();
System.out.println(dropBomb(x, y, serverGrid));
dropBomb(x, y, serverDamage);
dataOutputStream.writeChars("Enemy player has targeted " + x + ", " + y +'\n');
System.out.println(printBoard(serverDamage));
}
if (inFromServer.ready()) { // modtag data fra server
System.out.println(inFromServer.readLine());
System.out.println(printBoard(clientGrid));
}
}
} catch (UnknownHostException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
private static void setup(Scanner inFromUser, int playerNo) {
fleet = new ArrayList<Ship>();
while (count < numberOfShips) {
createFleet(fleet, inFromUser.nextInt());
}
battleship.initializeGrid(playerNo);
for (int i = 0; i < fleet.size(); i++) {
System.out.println(fleet.get(i));
System.out.println("Define direction (V/H) plus coordinates");
deployShip(clientGrid, fleet.get(i), inFromUser.next().charAt(0), inFromUser.nextInt(), inFromUser.nextInt());
}
System.out.println("Placements:\n" + printBoard(clientGrid));
System.out.println("Fleet has been deployed. Press enter to continue.\n");
}
}
package Battleships;
public class Ship {
private String name;
private int size;
private boolean isDestroyed;
public Ship(String n, int s, boolean d) {
this.name = n;
this.size = s;
this.isDestroyed = d;
}
public String getName() {
String output = "";
output = "[" + name + "]";
return output;
}
public int getSize() {
return size;
}
public String toString() {
String output = "";
output = "[" + name + ", " + size + ", " + isDestroyed + "]";
return output;
}
}

Importing Ticket class problem (java)

My program will not find the ticket class i created . Cant seem to work out what i have done wrong? Thank you
package javacw;
/*
*
* #Author Christopher Kempster;
*
*/
import java.awt.event.*;
import java.awt.*;
import javax.swing.*;
public class Main extends JFrame implements ActionListener {
public JButton buyButton, viewSeatsButton, clearSeatsButton;
String[] showTimes = {"1pm", "3pm", "5pm", "7pm", "9pm"};
String[] ageCategories = {"Adult", "Child", "OAP"};
String[] seatingSections = {"Left", "Middle", "Right"};
public JComboBox times, categories, sections;
public JTextField numberOfTickets;
public Ticket ticket;
public int price;
public static void main(String args[]) {
Main dashboard = new Main();
dashboard.setVisible(true);
}
public void actionPerformed(ActionEvent e) {
Object item = times.getSelectedItem();
String stringTimes = (String)item;
Object item1 = categories.getSelectedItem();
String stringCategories = (String)item1;
Object item2 = sections.getSelectedItem();
String stringSections = (String)item2;
String text = numberOfTickets.getText();
int ii = Integer.parseInt(text);
if(e.getSource() == buyButton) {
buyTickets(stringTimes, stringSections, ii, stringCategories);
}
else if(e.getSource() == viewSeatsButton) {
showSeats(stringTimes, stringSections);
}
else if(e.getSource() == clearSeatsButton) {
clearSection(stringTimes, stringSections);
}
}
public Main() {
ticket = new Ticket();
JPanel panel = new JPanel();
FlowLayout flow = new FlowLayout();
panel.setLayout(flow);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(300, 500);
buyButton = new JButton("Buy tickets");
viewSeatsButton = new JButton("View seats");
clearSeatsButton = new JButton("Clear seats");
times = new JComboBox(showTimes);
categories = new JComboBox(ageCategories);
sections = new JComboBox(seatingSections);
JLabel label = new JLabel("Number of tickets:");
numberOfTickets = new JTextField(5);
buyButton.addActionListener(this);
viewSeatsButton.addActionListener(this);
clearSeatsButton.addActionListener(this);
panel.add(times);
panel.add(categories);
panel.add(sections);
panel.add(label);
panel.add(numberOfTickets);
panel.add(buyButton);
panel.add(viewSeatsButton);
panel.add(clearSeatsButton);
Container cp = getContentPane();
cp.add(panel, BorderLayout.CENTER);
cp.setBackground(Color.red);
}
public void showSeats(String a, String b) {
JOptionPane.showMessageDialog(this, "There are " + ticket.seatsLeft(a, b) + " seats left in the " + b + " at " + a + ".");
}
public void clearSection(String a, String b) {
ticket.clearSeats(a, b);
JOptionPane.showMessageDialog(this, "There are now " + ticket.seatsLeft(a, b) + " tickets left for this section.");
}
public void buyTickets(String a, String b, int i, String c) {
if(c.equals("Adult")) {
price = 5;
}
else if(c.equals("Child")) {
price = 2;
}
else if(c.equals("OAP")) {
price = 2;
}
price = price * i;
if(ticket.buyTix(a, b, i)) {
JOptionPane.showMessageDialog(this, "Tickets have been bought!\nThere are " + ticket.seatsLeft(a, b) + " seats left in this section.\nPrice of tickets bought: £" + price + ".");
}
else {
JOptionPane.showMessageDialog(this, "Sorry, there are just " + ticket.seatsLeft(a, b) + " tickets left for this section.");
}
}
}
Ticket.java
package javacw;
/*
*
* #Author Christopher Kempster;
*
*/
public class Ticket {
int c, seatsLeft;
public int[] seating = {12, 40, 12, 12, 40, 12, 12, 40, 12, 12, 40, 12, 12, 40, 12};
public int[] seating2 = {12, 40, 12, 12, 40, 12, 12, 40, 12, 12, 40, 12, 12, 40, 12};
public Ticket() {
}
public void clearSeats(String a, String b) {
seating[convertArrayPointer(a, b)] = seating2[convertArrayPointer(a, b)];
}
public boolean buyTix(String a, String b, int i) {
if(seatsLeft(a, b) >= i) {
seating[convertArrayPointer(a, b)] -= i;
return true;
}
else {
return false;
}
}
public int seatsLeft(String a, String b) {
seatsLeft = seating[convertArrayPointer(a, b)];
return seatsLeft;
}
public int convertArrayPointer(String a, String b) {
if(a.equals("1pm") && b.equals("Left")) {
c = 0;
}
else if(a.equals("1pm") && b.equals("Middle")) {
c = 1;
}
else if(a.equals("1pm") && b.equals("Right")) {
c = 2;
}
else if(a.equals("3pm") && b.equals("Left")) {
c = 3;
}
else if(a.equals("3pm") && b.equals("Middle")) {
c = 4;
}
else if(a.equals("3pm") && b.equals("Right")) {
c = 5;
}
else if(a.equals("5pm") && b.equals("Left")) {
c = 6;
}
else if(a.equals("5pm") && b.equals("Middle")) {
c = 7;
}
else if(a.equals("5pm") && b.equals("Right")) {
c = 8;
}
else if(a.equals("7pm") && b.equals("Left")) {
c = 9;
}
else if(a.equals("7pm") && b.equals("Middle")) {
c = 10;
}
else if(a.equals("7pm") && b.equals("Right")) {
c = 11;
}
else if(a.equals("9pm") && b.equals("Left")) {
c = 12;
}
else if(a.equals("9pm") && b.equals("Middle")) {
c = 13;
}
else if(a.equals("9pm") && b.equals("Right")) {
c = 14;
}
return c;
}
}
This compiles properly when I try under Eclipse.
The problem doesn't come from your code. I think it comes from your environment settings. Either the source path is not correct or your Ticket.java is not located in the proper directory (which should be [src path]/javacw here).

Categories

Resources