The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | Jul 2017 |
| Last Sign in: | 337 Weeks Ago, 1 Day Ago |
| Questions Answered: | 15833 |
| Tutorials Posted: | 15827 |
MBA,PHD, Juris Doctor
Strayer,Devery,Harvard University
Mar-1995 - Mar-2002
Manager Planning
WalMart
Mar-2001 - Feb-2009
Hello,
I have attached one of my assignments(mission 13) to this file. I am having a hard time solving the errors and getting it to work properly. I have attached the Game driver class and also my method class. Can you please take a look at it and give me some insight and show me what I need to do to get my program to work correctly and follow the directions outlined in mission 13.
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
public class MemoryGame
{
//set up main variables
public JFrame main;
public JLabel lblInstructions;
public JTextField txtInput;
public int num = 1;
public String[] colors = {"red","green", "blue", "brown", "yellow", "black", "white"};
public String[] solution = new String[5];
public MemoryGame ();
//get random color
Random r = new Random();
{
//set up my dialog box
main = new JFrame ();
main.setSize (400,300);
main.setTitle("Memory Game");
main.setDefaultCloseOperation(main.EXIT_ON_CLOSE);
main.setLayout(new FlowLayout());
createContents();
main.setVisible(true);
}
public void createContents ()
{
JLabel lblInstructions = new JLabel();
txtInput = new JTextField(null,15);
//starting number of dialog box
lblInstructions.setText ("#" + num);
//Add action to text box
txtInput.addActionListener(new GameListener());
main.add(lblInstructions);
main.add(txtInput);
}
//call out the action being performed
public class GameListener implements ActionListener
{
public void actionPerformed (ActionEvent e)
{
String guess = "";
guess = txtInput.getText();
//call out what number matches a color
for (int i = 0; i < solution.lenght; i++)
{
if (solution[i] == colors[r.nextInt(7)])
{
main++;
lblInstructions.setText("Congratulations-your memory is perfect!");
}
else
{
lblInstructions.setText("Sorry-wrong color, Eat more antioxidants.");
}
}
}public class GameDriver2
{
public static void main (String[] args)
{
MemoryGame game = new MemoryGame ();
}
}
}
}
----------- ----------- H-----------ell-----------o S-----------ir/-----------Mad-----------am ----------- Th-----------ank----------- yo-----------u f-----------or -----------you-----------r i-----------nte-----------res-----------t a-----------nd -----------buy-----------ing----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n. -----------Ple-----------ase----------- pi-----------ng -----------me -----------on -----------cha-----------t I----------- am----------- on-----------lin-----------e o-----------r i-----------nbo-----------x m-----------e a----------- me-----------ssa-----------ge -----------I w-----------ill----------- be----------- qu-----------ick-----------ly