473,406 Members | 2,352 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

penny pitch anyone?

i am trying to make a penny pitch game. the sum is returned at the end of the game and the player has 2 options: toss and quit. the program does this when the toss option is clicked: generates two random numbers from teh row n column toss, add number at this position to the running total, and displays the board replacing the numbers with P's where pennies land.

here is what the board looks like

1 1 1 1 1 1 1
1 2 2 2 2 2 1
1 2 3 3 3 2 1
1 2 3 5 3 2 1
1 2 3 3 3 2 1
1 2 2 2 2 2 1
1 1 1 1 1 1 1

the boards position are indexed starting at [1,1] in the top left, not [0,0], thus the rows n columns go from 1 to 7.

i have succcessfully programed this in c++, but am unable to do so in java...arrays are just not my thing

if anyone can assist, that would be great, thanks.
Feb 21 '07 #1
20 7713
Ganon11
3,652 Expert 2GB
What exactly do you need help with?
Feb 21 '07 #2
What exactly do you need help with?
i basically need help getting started, like setting up the array/game board...i can pretty much take care of the rest
Feb 21 '07 #3
Ganon11
3,652 Expert 2GB
Well, that depends on what exactly needs to be in the game board. Will it be a 2D integer array? Will it be objects?

The basic syntax will be:

<Typename> board = new <Typename>[<xSize>][<ySize>];

and then you can fill it like you would in C++.
Feb 21 '07 #4
RedSon
5,000 Expert 4TB
This wouldn't perchance be a homework assignment would it? If it is, cool assignment, I never got to make a game in my classes.
Feb 21 '07 #5
Ganon11
3,652 Expert 2GB
In my classes, we weren't allowed to do 'games', as this would violate school policy. We worked on 'projects' with eerily familiar titles like Chess and Minesweeper.
Feb 21 '07 #6
DeMan
1,806 1GB
In my classes, we weren't allowed to do 'games', as this would violate school policy. We worked on 'projects' with eerily familiar titles like Chess and Minesweeper.
Ah.... Touche'
Feb 21 '07 #7
r035198x
13,262 8TB
I made it a point to make a game every two weeks.
Feb 22 '07 #8
hello my wife is currenty in a comp sci class at the local university and if i dont do tthis for her i will be in some serious trouble!!!!!! please help me do the penny pitch program ASAP.....in 5 minutes and email with the source code would be preferable............. <Removed:Against site rules>






i am trying to make a penny pitch game. the sum is returned at the end of the game and the player has 2 options: toss and quit. the program does this when the toss option is clicked: generates two random numbers from teh row n column toss, add number at this position to the running total, and displays the board replacing the numbers with P's where pennies land.

here is what the board looks like

1 1 1 1 1 1 1
1 2 2 2 2 2 1
1 2 3 3 3 2 1
1 2 3 5 3 2 1
1 2 3 3 3 2 1
1 2 2 2 2 2 1
1 1 1 1 1 1 1

the boards position are indexed starting at [1,1] in the top left, not [0,0], thus the rows n columns go from 1 to 7.

i have succcessfully programed this in c++, but am unable to do so in java...arrays are just not my thing

if anyone can assist, that would be great, thanks.
Mar 6 '07 #9
r035198x
13,262 8TB
hello my wife is currenty in a comp sci class at the local university and if i dont do tthis for her i will be in some serious trouble!!!!!! please help me do the penny pitch program ASAP.....in 5 minutes and email with the source code would be preferable............. <Removed:Against site rules>
We are not here to do students' assignments.
We only assist them to get it right.
Mar 6 '07 #10
I have the same problem. Our class needs to make a penny pitch game with a board like follows: 1 1 1 1 1
1 2 2 2 1
1 2 3 2 1
1 2 2 2 1
1 1 1 1 1

I was wondering if some one could help me with the program not do it.

Directions:
a player tosses several pennies on the board aiming for the number with the highest value. At the end of the game, the total of the tosses is returned. Develop a program that plays this game. The program should perform the following steps each time the user selects the TOSS button: Generate 2 random numbers for the row and column toss. Add the number at this position to a running total. Display the board, replacing the numbers with P's where the pennies land.

Should use a 2D array of square objects. Each square contains a number like those above (board) and a boolean flag that indicates a penny has landed on a square.
Apr 9 '07 #11
hey im doing this in my comp sci class i thought i had the code right but for some reason it wont work when i try to compile it. could someone please tell me whats wrong with my code? Id really appreciate it.

This is what I have:


Expand|Select|Wrap|Line Numbers
  1. import javax.swing.*;
  2.      import java.awt.*;
  3.      import java.awt.event.*;
  4.      import java.util.*;
  5.      import java.io.*;
  6.      import java.util.Random;
  7.  
  8.       public class PennyPitchGame
  9.      {
  10.          public static void main(String[] args)
  11.         {
  12.  
  13.            Random gen = new Random();
  14.            int totalScore = 0;
  15.            int played = 0;
  16.  
  17.            while(true)
  18.            {
  19.               Square[][] PennyBoard=
  20.                    {{new Square(1), new Square(1), new Square(1), new Square(1), new Square(1)}, 
  21.                     {new Square(1), new Square(2), new Square(2), new Square(2), new Square(1)},
  22.                     {new Square(1), new Square(2), new Square(3), new Square(2), new Square(1)}, 
  23.                     {new Square(1), new Square(2), new Square(2), new Square(2), new Square(1)},
  24.                     {new Square(1), new Square(1), new Square(1), new Square(1), new Square(1)}};
  25.  
  26.               int round = 0;
  27.               int row = 0;
  28.               int col = 0;
  29.               int attempt = 0;
  30.               String str = "";
  31.               int score = 0;
  32.               boolean playAgain = true;
  33.               int boardTotal = 0;
  34.  
  35.               while(playAgain && round < 5)
  36.               {
  37.                  int random = gen.nextInt(25) + 1;
  38.                  attempt = gen.nextInt(25) + 1;
  39.                  row = (attempt - 1) / 5;
  40.                  col = (attempt - 1) % 5;
  41.                  str = "";
  42.  
  43.                  while(!PennyBoard[row][col].pennyLanded())
  44.                  {
  45.                     if(playAgain && round == 0)
  46.                     {
  47.                        for(int row2 = 0; row2 < PennyBoard.length; row2++)
  48.  
  49.                        {
  50.                           for(int col2 = 0; col2 < PennyBoard.length; col2++)   
  51.  
  52.                           {
  53.                              str += PennyBoard[row2][col2] + "   ";
  54.                           }
  55.                           str += "\n";
  56.                        }
  57.                        JOptionPane.showMessageDialog(null,"The Original Board: \n " + str);
  58.                        str = "";
  59.                     }
  60.  
  61.                     score += PennyBoard[row][col].getNumber();
  62.                     PennyBoard[row][col].setPennyLanded();
  63.                     round++;
  64.                     boardTotal++;
  65.  
  66.  
  67.                     for(int row2 = 0; row2 < PennyBoard.length; row2++)
  68.                     {
  69.                        for(int col2 = 0; col2 < PennyBoard.length; col2++)   
  70.                        {
  71.                           str += PennyBoard[row2][col2] + "   ";
  72.                        }
  73.                        str += "\n";
  74.                     }
  75.                     JOptionPane.showMessageDialog(null, "The Board: \t" + boardTotal + " out of 5 \n" + str);
  76.                  }
  77.               }
  78.  
  79.               totalScore += score;
  80.               played++;
  81.               JOptionPane.showMessageDialog(null,"Score for this round is " + score + " points");
  82.               JOptionPane.showMessageDialog(null,"Total is " + totalScore + " points");
  83.  
  84.               int option = JOptionPane.showConfirmDialog(null, "¿Quitar?", "Select Option", JOptionPane.YES_NO_OPTION);
  85.               if (option == 0)
  86.                  break;
  87.            }
  88.  
  89.            JOptionPane.showMessageDialog(null, "Total Status: " + totalScore + " points, in " + played + " rounds.");
  90.         }
  91.      }
  92.  
  93.  
  94.   //////////////////////////////////////////////////////////////////////////////////
  95.   //Square Class
  96.   //New Program
  97.   /////////////////////////////////////////////////////////////////////////////////
  98.    // Corresponds with Penny Pitch Game <PennyPitchGame.java>
  99.   // Represents a square
  100.  
  101.       public class Square extends Object
  102.      {
  103.         private int number;
  104.         private boolean pennyLanded;
  105.  
  106.          public Square(int n)
  107.         {
  108.            number = n;
  109.            pennyLanded = false;
  110.         }
  111.  
  112.          public boolean pennyLanded()
  113.         {
  114.            return pennyLanded;
  115.         }
  116.  
  117.          public void setPennyLanded()
  118.         {
  119.            pennyLanded = true;
  120.         }
  121.  
  122.          public int getNumber()
  123.         {
  124.            return number;
  125.         }
  126.  
  127.          public String toString()
  128.         {
  129.            if (pennyLanded)
  130.               return "P";
  131.            else
  132.               return "" + number;
  133.         }
  134.      }
Jun 3 '09 #12
JosAH
11,448 Expert 8TB
@jazzed4jasper
By "compile it" and "won't work" I assume the compiler complained about your code, i.e. it is syntactically incorrect. Compilers usually emit a readable error diagnostic message; one per error. Did you read them and understand them? If not why not copy/paste those messages here instead of making us guess.

kind regards,

Jos
Jun 4 '09 #13
the error says:


class PennyPitchGame is public, should be declared in a file named PennyPitchGame.java
Jun 4 '09 #14
JosAH
11,448 Expert 8TB
@jazzed4jasper
And what is the name of the file?

kind regards,

Jos
Jun 4 '09 #15
Uh..where do i find that? I'm very confused.
Jun 5 '09 #16
r035198x
13,262 8TB
@jazzed4jasper
You are not paying attention to the error message.
You do have some .java files that you are trying to compile, right?
In those .java files are declarations of classes. Now read the error messages again.
Jun 5 '09 #17
Markus
6,050 Expert 4TB
The class name must be the same as the file it is in.

You have what appears to be two classes defined in one file, and I'm not sure you can do that in Java. I would say it (my previous statement) with conviction, i.e you cannot declare multiple classes in one file, but I know little about Java, and I'm sure to be corrected by either Jos or r0.
Jun 5 '09 #18
JosAH
11,448 Expert 8TB
@Markus
You can define one public class or interface in a file but you can add many non-public classes and interfaces to it. The name of the file has to be equal to the name of the public class or interface in it.

kind regards,

Jos
Jun 5 '09 #19
ok...i'll try fixing it. Thanks for the help.
Jun 8 '09 #20
RedSon
5,000 Expert 4TB
@jazzed4jasper
Where do you find the name of the file? Are you sure you should be taking a computer science class? Usually one would need to be somewhat advanced before taking on such a course.
Jun 8 '09 #21

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Justin Shaw | last post by:
I am using the tkSnack library to estimate the frequency from a sound file. The pitch seems to drop down an octave at 400 Hertz. For example A~440 Hertz comes out at 220 Hertz. When I use the...
77
by: nospam | last post by:
Reasons for a 3-tier achitecture for the WEB? (NOTE: I said, WEB, NOT WINDOWS. DON'T shoot your mouth off if you don't understand the difference.) I hear only one reason and that's to switch a...
1
by: Peter Mueller | last post by:
Hi, is it possible to reduce the line pitch with simple html? I am not able to use CSS oder JavaScript here. I tried to reduce the size in the font-tag with no avail. Tanks in advance. Peter
1
by: talsharf | last post by:
Hi everyone, I have this small problem and I wonder if someone could put me in some direction. I am trying to build a simple sound generator, mainly for playing the sound of a car's engine. I...
7
by: aagarcia | last post by:
My sum from my a report footer total at the end of a report is off by a penny! The data totals coming from query are correct. Only the calculations (=Sum()doesn't add the penny. I've tried...
1
by: Vinay Kodam | last post by:
Is there any OCX component or function or source code that I can use to convert sound into db or pitch? In another word, if I talk through Microphone, it should tell me what my db or pitch is? ...
0
by: gjunge | last post by:
Hi, I want to show a Pitch graph/curve of a wave file. I saw that good results can be made by using AutoCorrelation. I have the autocorrelation function and I also have the FFT function, but I...
1
by: Dan | last post by:
Hello, I have been working on a problem for a day now and am spinning my wheels. What is the easiest way to add two sets of roll/pitch/yaw angles? For example, an airplane is at 25deg pitch, 0...
0
by: djpaul | last post by:
Hello, Does anybody knows a good api or dll to use within c#? I am creating a jingle program and also for music where i need a good pitch control on it. I tried the directShiow but when i pull...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.