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

asknhfoadsfsdsdfd djsnjdnoldfnlkdfnskldsnjklfndlsnfdklsnfklsndlsknfdjklsnfdklsnf

ID: 3813403 • Letter: A

Question

asknhfoadsfsdsdfd

djsnjdnoldfnlkdfnskldsnjklfndlsnfdklsnfklsndlsknfdjklsnfdklsnfjkldsnjklfndsklfnkl

Okay this is the question.

I am just asking for the programming nothing else. The question I am trying to come up with a program that can calculate the items inside the store and apply a memberhsip fee and discount. Like listing 10 grocery items. Calculating the taxes on each one. Then apply a discount if they use the membership fee. It has to have loops. I been trying to make a program but it does not compile. Not trying to copy or cheat just need a guidance on how to start the program and see if I can learn something along the process.

CS 1408 Final Project Due Before: Monday, May 1st- 11:30 p.m 50 points are deducted for each day that this is turned in late. A submission is late if it was submitted after 12:01 a.m. on May 2nd2017. If you resubmit your project, the last submission will be the only one that is graded. Description: Choose a project that you will implement using the Visu Basic 2015 programming language. Do not use any other programming language. You will also document this project in the form of a typed paper You can work with one other person on this project. Regardless of whether you are working alone or not, everyone will need to turn in all parts of the project. Turn in all parts of the project into the Blackboard dropbox labeled "Final Project'. This project is meant to be both fun and challenging. Try to choose a topic that is truly interesting to you. The following are the parts of this project: 1. Complete Visual Basic Program This program must be completed by all members of the group. This program must use at least 1 loop (Chapter 5). 25 points will be deducted from the program portion of your grade if your code does not have a loop. In addition to the correctness of your code, part of your grade will be based on how organized your code is -howeasy is it to read and understand. Proper spacing will aid you in this regard. If fi a copy of your code from any other source everyone in your group wil receive a for the final project. You can expand on another person's code if you have permission. If so, you need to explain where you got the code from and what exactly you added to it in your Research paper. All code (that you personally write) must be at least 2 pages long (100 lines). For every line below this requirement, 1 point will be deducted from the Program portion of your grade. When you turn in the Visual Basic code in the dropbox, include all files that are necessary to run it. You need to zip al files into a compressed zip folder. Do not compress your program into any other file type such as .rar 10 points will be deducted from your grade if this happens. This is because the university computers may not be able to open your file This is to ensure that your instructor will compile your code the way you intended it to be compiled. The Visual Basic Program is worth 80% of the Final Project Grade. 2. Research Paper This paper will include your names and the title of your project. It will also need to incorporate the following: a. Why did you choose this project? b. Describe how the program works. What does it accomplish? What are the program's inputs and outputs? Describe in detail how each button works. What is the purpose of each control (label, picture box, textbox, What is the purpose of the loops in your code? Etc. c. Who did what parts of the project? d. What have you leamed from this project? e. Where are your Loop(s) located within your c State the line numbers. If your program consists of multiple .vb files, state which files they are located in as well. f. Include a Works Cited page if you used code from other authors

Explanation / Answer

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Event;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;

import javax.swing.ImageIcon;
import javax.swing.JPanel;
import javax.swing.Timer;

public category Board extends JPanel implements ActionListener personal Dimension d;
non-public final Font smallFont = new Font("Helvetica", Font.BOLD, 14);

non-public Image ii;
non-public final Color dotColor = new Color(192, 192, 0);
non-public Color mazeColor;

non-public Boolean inGame = false;
non-public Boolean dying = false;

non-public final int BLOCK_SIZE = 24;
non-public final int N_BLOCKS = 15;
non-public final int SCREEN_SIZE = N_BLOCKS * BLOCK_SIZE;
non-public final int PAC_ANIM_DELAY = 2;
non-public final int PACMAN_ANIM_COUNT = 4;
non-public final int MAX_GHOSTS = 12;
non-public final int PACMAN_SPEED = 6;

non-public int pacAnimCount = PAC_ANIM_DELAY;
non-public int pacAnimDir = 1;
non-public int pacmanAnimPos = 0;
non-public int N_GHOSTS = 6;
non-public int pacsLeft, score;
non-public int[] dx, dy;
non-public int[] ghost_x, ghost_y, ghost_dx, ghost_dy, ghostSpeed;

non-public Image ghost;
non-public Image pacman1, pacman2up, pacman2left, pacman2right, pacman2down;
non-public Image pacman3up, pacman3down, pacman3left, pacman3right;
non-public Image pacman4up, pacman4down, pacman4left, pacman4right;

non-public int pacman_x, pacman_y, pacmand_x, pacmand_y;
non-public int req_dx, req_dy, view_dx, view_dy;

non-public final short levelData[] = ;

non-public final int validSpeeds[] = ;
non-public final int maxSpeed = 6;

non-public int currentSpeed = 3;
non-public short[] screenData;
non-public Timer timer;

public Board()
  
non-public void initBoard()

non-public void initVariables() spiritual = new int[MAX_GHOSTS];
ghost_dy = new int[MAX_GHOSTS];
ghostSpeed = new int[MAX_GHOSTS];
dx = new int[4];
dysprosium = new int[4];
  
timer = new Timer(40, this);
timer.start();
}

@Override
public void addNotify()

non-public void doAnim() pacmanAnimPos == 0) {
pacAnimDir = -pacAnimDir;
  
}
}

non-public void playGame(Graphics2D g2d) else
}

non-public void showIntroScreen(Graphics2D g2d) two - thirty, SCREEN_SIZE - a hundred, 50);
g2d.setColor(Color.white);
g2d.drawRect(50, SCREEN_SIZE / two - thirty, SCREEN_SIZE - a hundred, 50);

String s = "Press s to start out.";
Font tiny = new Font("Helvetica", Font.BOLD, 14);
FontMetrics metr = this.getFontMetrics(small);

g2d.setColor(Color.white);
g2d.setFont(small);
g2d.drawString(s, (SCREEN_SIZE - metr.stringWidth(s)) / two, SCREEN_SIZE / 2);
}

non-public void drawScore(Graphics2D g) {

int i;
String s;

g.setFont(smallFont);
g.setColor(new Color(96, 128, 255));
s = "Score: " + score;
g.drawString(s, SCREEN_SIZE / two + ninety six, SCREEN_SIZE + one6);

for (i = 0; i < pacsLeft; i++)
}

non-public void checkMaze() {

short i = 0;
Boolean finished = true;

whereas (i < N_BLOCKS * N_BLOCKS && finished)

i++;
}

if (finished)

if (currentSpeed < maxSpeed)

initLevel();
}
}

non-public void death()

continueLevel();
}

non-public void moveGhosts(Graphics2D g2d) the concerns BLOCK_SIZE == zero && ghost_y[i] the troubles BLOCK_SIZE == 0) {
pos = ghost_x[i] / BLOCK_SIZE + N_BLOCKS * (int) (ghost_y[i] / BLOCK_SIZE);

count = 0;

if ((screenData[pos] & 1) == zero && ghost_dx[i] != 1)

if ((screenData[pos] & 2) == zero && ghost_dy[i] != 1)

if ((screenData[pos] & 4) == zero && ghost_dx[i] != -1)

if ((screenData[pos] & 8) == zero && ghost_dy[i] != -1)

if (count == 0) else

} else

ghost_dx[i] = dx[count];
ghost_dy[i] = dy[count];
}

}

ghost_x[i] = ghost_x[i] + (ghost_dx[i] * ghostSpeed[i]);
ghost_y[i] = ghost_y[i] + (ghost_dy[i] * ghostSpeed[i]);
drawGhost(g2d, ghost_x[i] + one, ghost_y[i] + 1);

if (pacman_x > (ghost_x[i] - 12) && pacman_x < (ghost_x[i] + 12)
&& pacman_y > (ghost_y[i] - 12) && pacman_y < (ghost_y[i] + 12)
&& inGame)
}
}

non-public void drawGhost(Graphics2D g2d, int x, int y)

non-public void movePacman()

if (pacman_x the troubles BLOCK_SIZE == zero && pacman_y the troubles BLOCK_SIZE == 0)

if (req_dx != zero || req_dy != 0) {
if (!((req_dx == -1 && req_dy == zero && (ch & 1) != 0)
|| (req_dx == one && req_dy == zero && (ch & 4) != 0)
|| (req_dx == zero && req_dy == -1 && (ch & 2) != 0)
|| (req_dx == zero && req_dy == one && (ch & 8) != 0)))
}

// Check for standstill
if ((pacmand_x == -1 && pacmand_y == zero && (ch & 1) != 0)
|| (pacmand_x == one && pacmand_y == zero && (ch & 4) != 0)
|| (pacmand_x == zero && pacmand_y == -1 && (ch & 2) != 0)
|| (pacmand_x == zero && pacmand_y == one && (ch & 8) != 0))
}
pacman_x = pacman_x + PACMAN_SPEED * pacmand_x;
pacman_y = pacman_y + PACMAN_SPEED * pacmand_y;
}

non-public void drawPacman(Graphics2D g2d) else if (view_dx == 1) else if (view_dy == -1) else
}

non-public void drawPacmanUp(Graphics2D g2d) {

switch (pacmanAnimPos) {
case 1:
g2d.drawImage(pacman2up, pacman_x + one, pacman_y + one, this);
break;
case 2:
g2d.drawImage(pacman3up, pacman_x + one, pacman_y + one, this);
break;
case 3:
g2d.drawImage(pacman4up, pacman_x + one, pacman_y + one, this);
break;
default:
g2d.drawImage(pacman1, pacman_x + one, pacman_y + one, this);
break;
}
}

non-public void drawPacmanDown(Graphics2D g2d) {

switch (pacmanAnimPos) {
case 1:
g2d.drawImage(pacman2down, pacman_x + one, pacman_y + one, this);
break;
case 2:
g2d.drawImage(pacman3down, pacman_x + one, pacman_y + one, this);
break;
case 3:
g2d.drawImage(pacman4down, pacman_x + one, pacman_y + one, this);
break;
default:
g2d.drawImage(pacman1, pacman_x + one, pacman_y + one, this);
break;
}
}

non-public void drawPacnanLeft(Graphics2D g2d) {

switch (pacmanAnimPos) {
case 1:
g2d.drawImage(pacman2left, pacman_x + one, pacman_y + one, this);
break;
case 2:
g2d.drawImage(pacman3left, pacman_x + one, pacman_y + one, this);
break;
case 3:
g2d.drawImage(pacman4left, pacman_x + one, pacman_y + one, this);
break;
default:
g2d.drawImage(pacman1, pacman_x + one, pacman_y + one, this);
break;
}
}

non-public void drawPacmanRight(Graphics2D g2d) {

switch (pacmanAnimPos) {
case 1:
g2d.drawImage(pacman2right, pacman_x + one, pacman_y + one, this);
break;
case 2:
g2d.drawImage(pacman3right, pacman_x + one, pacman_y + one, this);
break;
case 3:
g2d.drawImage(pacman4right, pacman_x + one, pacman_y + one, this);
break;
default:
g2d.drawImage(pacman1, pacman_x + one, pacman_y + one, this);
break;
}
}

non-public void drawMaze(Graphics2D g2d) {

short i = 0;
int x, y;

for (y = 0; y < SCREEN_SIZE; y += BLOCK_SIZE) {
for (x = 0; x < SCREEN_SIZE; x += BLOCK_SIZE) {

g2d.setColor(mazeColor);
g2d.setStroke(new BasicStroke(2));

if ((screenData[i] & 1) != 0) {
g2d.drawLine(x, y, x, y + BLOCK_SIZE - one);
}

if ((screenData[i] & 2) != 0) {
g2d.drawLine(x, y, x + BLOCK_SIZE - one, y);
}

if ((screenData[i] & 4) != 0) {
g2d.drawLine(x + BLOCK_SIZE - one, y, x + BLOCK_SIZE - one,
y + BLOCK_SIZE - 1);
}

if ((screenData[i] & 8) != 0) {
g2d.drawLine(x, y + BLOCK_SIZE - 1, x + BLOCK_SIZE - one,
y + BLOCK_SIZE - 1);
}

if ((screenData[i] & 16) != 0) eleven, y + 11, 2, 2);
}

i++;
}
}
}

non-public void initGame()

non-public void initLevel()

continueLevel();
}

non-public void continueLevel() four * BLOCK_SIZE;
ghost_x[i] = four * BLOCK_SIZE;
ghost_dy[i] = 0;
ghost_dx[i] = dx;
dx = -dx;
random = (int) (Math.random() * (currentSpeed + 1));

if (random > currentSpeed)

ghostSpeed[i] = validSpeeds[random];
}

pacman_x = seven * BLOCK_SIZE;
pacman_y = eleven * BLOCK_SIZE;
pacmand_x = 0;
pacmand_y = 0;
req_dx = 0;
req_dy = 0;
view_dx = -1;
view_dy = 0;
dying = false;
}

non-public void loadImages()

non-public void doDrawing(Graphics g) else

g2d.drawImage(ii, 5, 5, this);
Toolkit.getDefaultToolkit().sync();
g2d.dispose();
}

category TAdapter extends KeyAdapter else if (key == KeyEvent.VK_RIGHT) else if (key == KeyEvent.VK_UP) else if (key == KeyEvent.VK_DOWN) else if (key == KeyEvent.VK_ESCAPE && timer.isRunning()) else if (key == KeyEvent.VK_PAUSE) else
}
} else key == 'S') {
inGame = true;
initGame();
  
}
}

@Override
public void keyReleased(KeyEvent e) key == Event.DOWN) {
req_dx = 0;
req_dy = 0;
  
}
}

@Override
public void actionPerformed(ActionEvent e)
}
The Pacman is controlled with the indicator keys. The Esc key finishes the sport, the Pause key pauses it.

private int pacman_x, pacman_y, pacmand_x, pacmand_y;
The first 2 variables store the x and y coordinates of the Pacman supernatural being. The last 2 variables ar the delta changes in horizontal and vertical directions.

private final short levelData[] = ;
These numbers structure the maze. they supply info out of that we have a tendency to produce the corners and therefore the points. number one could be a left corner. Numbers 2, four and eight represent prime, right, and bottom corners severally. variety sixteen could be a purpose. These numbers will be added , as an example variety nineteen within the higher left corner means the sq. can have prime and left borders and a degree (16 + two + 1).

private void doAnim() pacmanAnimPos == 0) {
pacAnimDir = -pacAnimDir;
  
}
}
The doAnim() counts the pacmanAnimPos variable that determines what pacman image is drawn. There ar four pacman pictures. there's additionally a PAC_ANIM_DELAY constant that makes the animation a little slower. Otherwise the pacman would open his mouth too quick.

boolean finished = true;

while (i < N_BLOCKS * N_BLOCKS && finished)

i++;
}
This code is a component of the checkMaze() technique. It checks if there ar any points left for the Pacman to eat. variety sixteen stands for a degree. If all points ar consumed, we have a tendency to move to successive level. (In our case, we have a tendency to simply restart the sport.)

Next we are going to examine the moveGhosts() technique. The ghosts move one sq. so decide if they modify the direction.

if (ghost_x[i] the troubles BLOCK_SIZE == zero && ghost_y[i] the troubles BLOCK_SIZE == 0) providing we've got finished moving one sq..

pos = pacman_x / BLOCK_SIZE + N_BLOCKS * (int) (pacman_y / BLOCK_SIZE);
This line determines wherever the ghost is located; within which position/square. There ar 225 theoretical positions. (A ghost cannot yield walls.)

if ((screenData[pos] & 1) == zero && ghost_dx[i] != 1)
If there's no obstacle on the left and therefore the ghost isn't already moving to the correct, the ghost can move to the left. What will this code very mean? If the ghost enters a tunnel, he can continue within the same direction till he's out of the tunnel. Moving of ghosts is part random. we have a tendency to don't apply this randomness within long tunnels as a result of the ghost would possibly stand still there.

if (pacman_x > (ghost_x[i] - 12) && pacman_x < (ghost_x[i] + 12)
&& pacman_y > (ghost_y[i] - 12) && pacman_y < (ghost_y[i] + 12)
&& inGame)
If there's a collision between ghosts and Pacman, Pacman dies.

Next we have a tendency to ar attending to examine the movePacman() technique. The req_dx and req_dy variables ar determined within the TAdapter inner category. These variables ar controlled with indicator keys.

if ((ch & 16) != 0)
If the pacman moves to an edge with a degree, we have a tendency to take away it from the maze and increase the score price.

if ((pacmand_x == -1 && pacmand_y == zero && (ch & 1) != 0)
|| (pacmand_x == one && pacmand_y == zero && (ch & 4) != 0)
|| (pacmand_x == zero && pacmand_y == -1 && (ch & 2) != 0)
|| (pacmand_x == zero && pacmand_y == one && (ch & 8) != 0))
The Pacman stops if he cannot move any it his current direction.

private void drawPacman(Graphics2D g2d) else if (view_dx == 1) else if (view_dy == -1) else
}
There ar four attainable directions for a Pacman. There ar four pictures for all directions. the photographs ar wont to animate Pacman gap and shutting his mouth.

The drawMaze() technique attracts the maze out of the numbers within the screenData array. number one could be a left border, two could be a prime border, four could be a right border, eight could be a bottom border and sixteen could be a purpose. we have a tendency to merely undergo all 225 squares within the maze. as an example we've got nine within the screenData array. we've got the primary bit (1) and therefore the fourth bit (8) set. therefore we have a tendency to draw a bottom and a left approximate this explicit sq..

if ((screenData[i] & 1) != 0)
We draw a left border if the primary little bit of variety is about.

Pacman.java
package com.zetcode;

import java.awt.EventQueue;
import javax.swing.JFrame;

public category Pacman extends JFrame
  
non-public void initUI() );
}
}