Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

***Please I need help with this assignment*** Homework: Final Program Fundamenta

ID: 3840126 • Letter: #

Question

***Please I need help with this assignment***

    Homework: Final Program

    Fundamentals of Computing

Summary

Build an interactive software application, a simulation, or a game.

Work Items

Submit your program as a zip file of a directory that contains all your Java source code files and your features-to-be-graded list:

1) Please submit only a single zip file via Canvas. Do not email your instructor your work.

2) Name your directory LastFirst HW Final Prog. Name the zip file of that directory the same as that directory but with a .zip extension: LastFirst HW Final Prog.zip. In both filenames, put in your own last name and first name for “Last” and “First”. You must name your directory and file this way.

3) If you’re not sure how to create a zip file of a directory, please do a Google search to find out. The process to do so will be different depending on what operating system you’re using.

4) The name of your features-to-be-graded list (see Program Requirements below) should be named LastFirst HW Final Prog Features.txt.

Program Description

Write a program that demonstrates the skills we’ve learned throughout this quarter. This type of project offers only a few guidelines, allowing you to invest as much time and polish as you want, as long as you meet the program requirements described below. You can write a simple game (e.g., tic-tac-toe, Battleship), a simulation (e.g., a zero-dimensional energy balance model of the climate), or an application (e.g., a mortgage calculator). Your main requirement is that you demonstrate six of the following features in your software program and that you comment and document your code well:

1) Functional Decomposition: Use methods (a.k.a., functions) to break up a large program into meaningful chunks, using input to and output from those functions where appropriate.

2) Looping with Repetition Control Structures: Use two of the following structures: for, while, do/while, foreach.

3) Nested Loops: Use a loop within a loop in your program. Note that this is automatically accomplished when using Multi-Dimensional Arrays.

4) Branching with Selection Control Structures: Use multiple (i.e., more than one) if/else and/or switch statements in your code. (You don’t need to use both kinds of statements. if/else means any kind of if/else statement.)

5) File I/O: Read from or write to a file in your software. Examples of this include be reading in a preset pattern for the computer opponent’s answers in a game of rock/paper/scissors, or writing a file that logs each move the player makes, effectively recording a history of the game.

6) Using Multiple Classes: Build and use more than one class in your project. Note that a class that only has a main method and does not have any instance variables or methods does not count as a “class” in this feature. Thus, if you have a driver class that only has a main method and you want credit for this feature, you need at least two other classes in addition to the driver class.

7) One-dimensional arrays: Make use of a one-dimensional array in your software. If it is a partially-filled array, keep track of its current number of live elements with an int.

8) Class Design using Access Modifiers: Make all class-wide instance variables private in your class, and provide “getters” and “setters” to get and set the data accordingly.

9) Multi-Dimensional Arrays: Make use of an array with a dimensionality greater than one.

10) Recursion: Include a recursively designed function in your software, complete with (a) the recursive step and (b) the base step. (We did not cover this in the course, but if you know how to use it and want to, I’m willing to count it as a gradable feature for this assignment.)

11) Variable Tracing and Testing: Include a method(s) that can be used to provide output for trac-ing variables for the purpose of testing whether your code is working. The method(s) should be called test-something, e.g., testStatistics. Somewhere in your program, there should be a call to that method(s). In the code you submit, that call should be commented out, but I should be able to find it.

A few thoughts: Don’t be intimidated by the requirements above. Reuse, reuse, reuse! Think about how you can you accomplish multiple goals simultaneously. For example, doesn’t reading input from a file accomplish both File I/O and Looping with Repetition Control Structures? If you don’t know where to start, take an example that looks interesting to you and start by adding to it. NB: The requirement to comment and document your code well is in addition to the six features you’ve chosen. (Also, there are additional grading rubrics listed on the Canvas page for the assignment, but those form a relatively small part of the assignment grade.)

Finally, submit a file with your source code (put it in the same directory as your source code) where you list which six of the above features you want to be graded on. Make sure you number these features from one to six; the order doesn’t matter, but I’ll use the numbering as references while grading. Make this file a plain text file and with an extension .txt.

Explanation / Answer

package tictactoe;
import java.applet.Applet;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Container;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.io.PrintStream;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JOptionPane;

public class GameApplet extends Applet
implements MouseListener, ActionListener, WindowListener
{
JFrame f;
int flag = 2;
int n;
int m;
int i = 0;
static int bug = 0;
char[] ch = new char[9];
JButton first;
JButton second;
String s1 = "";
  
public GameApplet()
{
this.f = new JFrame("Tic Tac Toe");
this.first = new JButton("CLEAR");
this.second = new JButton("EXIT");
this.f.add(this.first);
this.f.add(this.second);
this.f.addWindowListener(this);
this.f.getContentPane().setBackground(Color.BLUE);
this.f.setLayout(null);
this.f.setVisible(true);
this.f.setSize(800, 600);
this.first.setBounds(650, 50, 90, 60);
this.second.setBounds(650, 250, 90, 60);
  
this.f.addMouseListener(this);
for (this.i = 0; this.i < 9; this.i += 1)
this.ch[this.i] = 'B';
this.first.addActionListener(this);
this.second.addActionListener(this);
  
String message = "Please click on the frame !!!!! to start the game ";
  
JOptionPane pane = new JOptionPane(message);
JDialog dialog = pane.createDialog(new JFrame(), "Dilaog");
dialog.show();
Graphics g = this.f.getGraphics();
g.drawLine(200, 0, 200, 600);
g.drawLine(400, 0, 400, 600);
g.drawLine(0, 200, 600, 200);
g.drawLine(0, 400, 600, 400);
g.drawLine(600, 0, 600, 600);
}
  
public void keyPressed(KeyEvent k)
{
System.out.print("");
}
  
public void keyTyped(KeyEvent k) {
this.s1 += k.getKeyChar();
}
  
public void keyReleased(KeyEvent k) {
System.out.print("");
}
  
public void actionPerformed(ActionEvent ae)
{
if (ae.getSource() == this.first)
{
this.f.setVisible(false);
bug = 0;
new GameApplet();
}
if (ae.getSource() == this.second)
{
System.exit(0);
}
}
  
public void windowClosing(WindowEvent de)
{
System.exit(0); }
  
public void windowOpened(WindowEvent de) { }
  
public void windowClosed(WindowEvent de) { }
  
public void windowActivated(WindowEvent de) { }
  
public void windowDeactivated(WindowEvent de) { }
  
public void windowIconified(WindowEvent de) { }
  
public void windowDeiconified(WindowEvent de) { }
  
public void mouseClicked(MouseEvent e) { Graphics2D g2;
Graphics g = this.f.getGraphics();
g.drawLine(200, 0, 200, 600);
g.drawLine(400, 0, 400, 600);
g.drawLine(0, 200, 600, 200);
g.drawLine(0, 400, 600, 400);
g.drawLine(600, 0, 600, 600);
this.flag -= 1;
int x = e.getX();
int y = e.getY();
if (this.flag == 1)
{
if ((x < 200) && (y < 200)) { this.m = 0; this.n = 0; this.ch[0] = 'R'; }
if ((x > 200) && (x < 400) && (y < 200)) { this.m = 200; this.n = 0; this.ch[1] = 'R'; }
if ((x > 400) && (x < 600) && (y < 200)) { this.m = 400; this.n = 0; this.ch[2] = 'R'; }
if ((x < 200) && (y > 200) && (y < 400)) { this.m = 0; this.n = 200; this.ch[3] = 'R'; }
if ((x > 200) && (x < 400) && (y > 200) && (y < 400)) { this.m = 200; this.n = 200; this.ch[4] = 'R'; }
if ((x > 400) && (x < 600) && (y > 200) && (y < 400)) { this.m = 400; this.n = 200; this.ch[5] = 'R'; }
if ((x < 200) && (y > 400) && (y < 600)) { this.m = 0; this.n = 400; this.ch[6] = 'R'; }
if ((x > 200) && (x < 400) && (y > 400) && (y < 600)) { this.m = 200; this.n = 400; this.ch[7] = 'R'; }
if ((x > 400) && (x < 600) && (y > 400) && (y < 600)) { this.m = 400; this.n = 400; this.ch[8] = 'R'; }
g.setColor(new Color(77, 176, 230));
g2 = (Graphics2D)g;
g2.setStroke(new BasicStroke(10.0F));
g.drawOval(this.m + 10, this.n + 10, 159, 159);
}
  
if (this.flag == 0)
{
if ((x < 200) && (y < 200)) { this.m = 0; this.n = 20; this.ch[0] = 'P'; }
if ((x > 200) && (x < 400) && (y < 200)) { this.m = 200; this.n = 20; this.ch[1] = 'P'; }
if ((x > 400) && (x < 600) && (y < 200)) { this.m = 400; this.n = 20; this.ch[2] = 'P'; }
if ((x < 200) && (y > 200) && (y < 400)) { this.m = 0; this.n = 200; this.ch[3] = 'P'; }
if ((x > 200) && (x < 400) && (y > 200) && (y < 400)) { this.m = 200; this.n = 200; this.ch[4] = 'P'; }
if ((x > 400) && (x < 600) && (y > 200) && (y < 400)) { this.m = 400; this.n = 200; this.ch[5] = 'P'; }
if ((x < 200) && (y > 400) && (y < 600)) { this.m = 0; this.n = 400; this.ch[6] = 'P'; }
if ((x > 200) && (x < 400) && (y > 400) && (y < 600)) { this.m = 200; this.n = 400; this.ch[7] = 'P'; }
if ((x > 400) && (x < 600) && (y > 400) && (y < 600)) { this.m = 400; this.n = 400; this.ch[8] = 'P'; }
g2 = (Graphics2D)g;
g2.setStroke(new BasicStroke(10.0F));
g.setColor(new Color(77, 176, 230));
g.drawLine(this.m + 10, this.n + 13, this.m + 169, this.n + 164);
g.drawLine(this.m + 169, this.n + 10, this.m + 10, this.n + 169);
this.flag += 2;
}
  
for (this.i = 0; this.i < 3; this.i += 1)
{
if ((this.ch[this.i] != 'B') &&
(this.ch[(this.i + 3)] == this.ch[this.i]) && (this.ch[(this.i + 6)] == this.ch[this.i]))
{
new Board().win();
bug = 1;
}
}
  
for (this.i = 0; this.i < 7; this.i += 1)
{
if (this.ch[this.i] != 'B')
{
if ((this.ch[this.i] == this.ch[(this.i + 1)]) && (this.ch[this.i] == this.ch[(this.i + 2)]))
{
new Board().win();
bug = 1;
}
this.i += 2;
}
else {
this.i += 2;
}
}
if ((this.ch[4] != 'B') && ((
((this.ch[0] == this.ch[4]) && (this.ch[4] == this.ch[8])) || ((this.ch[2] == this.ch[4]) && (this.ch[4] == this.ch[6])))))
{
new Board().win();
bug = 1;
}
  
for (this.i = 0; (this.i < 9) &&
(this.ch[this.i] != 'B'); this.i += 1)
{
if (this.i == 8)
{
if (bug == 0)
new Board().draw();
bug = 0;
}
}
}
  
public void mouseReleased(MouseEvent e)
{
System.out.print("");
}
  
public void mouseEntered(MouseEvent e)
{
System.out.print("");
}
  
public void mouseExited(MouseEvent e) {
System.out.print("");
}
  
public void mousePressed(MouseEvent e) {
System.out.print("");
}
  
public static void main(String[] args)
{
new GameApplet();
}
}

package tictactoe;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JOptionPane;

class Board implements WindowListener
{
public void win()
{
String message = "Congratulations !!!!! You win ";
  
JOptionPane pane = new JOptionPane(message);
JDialog dialog = pane.createDialog(new JFrame(), "Dilaog");
dialog.show();
}
  
public void draw()
{
String message = "Players the result is !!!!! STALEMATE ";
  
JOptionPane pane = new JOptionPane(message);
JDialog dialog = pane.createDialog(new JFrame(), "Dilaog");
dialog.show();
}
  
public void windowClosing(WindowEvent we)
{
System.exit(0);
}
  
public void windowOpened(WindowEvent we)
{
}
  
public void windowClosed(WindowEvent we)
{
}
  
public void windowActivated(WindowEvent we)
{
}
  
public void windowDeactivated(WindowEvent we)
{
}
  
public void windowIconified(WindowEvent we)
{
}
  
public void windowDeiconified(WindowEvent we)
{
}
}