JOptionPane - Display Total Number Of Goals Scored By All Players

May 22, 2014

JOptionPane.showMessageDialog(null,myRoster.totalGoalsScored + " is the total number of goals scored by all the players on the roster");

HOW CAN I CALL THE METHOD totalGoalsScored and display it using JOptionPane

ERROR: CAN NOT FIND SYMBOL

View Replies


ADVERTISEMENT

Store A Number Of Different Value Cards For A Number Of Players?

Feb 18, 2014

i am trying to store a number of different value cards for a number of players. E.g there can be 2 , 4 or more players and each player can have any number of cards.

I have decided to use an arraylist for cards and tried using an array for players. But after coding and reading some information online, i realised that it is not possible to have an array of arraylist.

View Replies View Related

How To Display Players Score In Panel

Jun 19, 2014

So I'm working on this game for a school project and I have 2 problems

1.I do not know how to display the players score in the panel
2.Every single time the console reads the second button I click on as a 0 instead of the number underlining it

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
import javax.swing.border.*;
public class Matchgame extends JPanel implements ActionListener { 
private final JPanel Brd = new JPanel(new BorderLayout(3, 3));

[Code]...

View Replies View Related

Calculate Total Price And Display Total In Order Class

Oct 11, 2014

I'm struggling with inheritance in my assignment. The assignment states that I should use the calculatePrice() to calculate the total price and use another method to display the total. The I must overload the calculatePrice() and add a fee in the SpeedOrder() class.

My main class

package useorder;
import javax.swing.*;
public class UseOrder {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Order.display();

[Code] .....

The problem is mainly displaying the TotalPrice field and. I can't display TotalPrice if it's not static but if it's static I can't inherit it to the SpeedOrder class to assign the total in the overloaded calculateprice method. How can I display the total in my order class and use it in my SpeedOrder class?

View Replies View Related

Creating Leaderboard For Game - Display Top 5 Players

Feb 26, 2014

I'm in the process of building an algorithm for a leaderboard for my game, but now I'm stuck.

- It is a two-player game.
- The leaderboard is supposed to display the top 5 players.
- Scores will be saved to an external .txt file as a reference.

Also, may I add that I still cannot decide if I should only consider the winner's score for the leaderboard, or also the loser's.

For example:

Player 1 is Juliet.
Player 2 is Romeo.

At the end of the match, Juliet's score is greater than Romeo's.

Should I only evaluate Juliet's score for the leaderboard, or both of their scores? As of now my algorithm considers only the winner's score.

As of the moment I'm also only thinking of using JLabel to display the scores, but I'm not sure if this is the most efficient way to do it. I'm considering JTable.

So here's my current algorithm:

1) When the user starts a new match/returns to menu/exits game: (I provided 4 options: new game (scores remain but the board is reset), new match (everything is reset), menu, and exit.)

public class Game
{
//This class also holds the code for the operation of the game
if (event.getSource() == newmatch)//or menu or exit {
if (p1score != 0 || p2score != 0) {
Leaderboard x;

[Code] .....

3) The next step which is I'm highly unsure of is to create an ArrayList for the scores (I'm missing the part about the player's name because well I'm not sure as well how I will approach it) and then sort it, but the problem after that would be how to make the score agree with the player's name, if you get what I mean.

Like for example the scores are:

Anna = 1
Pamela = 5
Gabby = 3
Sorted: 5, 3, 1

Pamela has the highest score, but how will I be able to display her name together with her score?

4) I have a checker which determines if the ArrayList of scores is empty, and if it is, it will automatically display the player's name and score (this is for the first pair of players).

It's something like this:

if (board.isEmpty()){
label1.setText(winnername);
scorelabel1.setText(winnerscore);
} else {
//
}

There's a whole lot of buzz going on and now I don't know how I should proceed.

View Replies View Related

How To Get Total Number Of Pennies In Dollar Amount For The Output Of Total Pay

Mar 28, 2014

I cannot get the right output for my program. I need to get the total number of pennies in dollar amount for the output of Total Pay. This is my program. The directions are:

Write a program that calculates the amount a person would earn over a period of time if his or her salary is one penny the first day, two pennies the second day, and continues to double each day. The program should then show the total pay at the end of the period. The output should be displayed in a dollar amount, not the number of pennies. Do not accept a number less than 1 for the number of days worked.

import java.util.Scanner;
import java.text.DecimalFormat;
public class PenniesForPay {
public static void main(String[] args) {
int numDays;

[Code] ....

totalSalary should be total number of pennies / 100....However its not picking up only day 30 of pennies which is 536,870,912 pennies and then dividing it?

View Replies View Related

Calculate Total Sales After Each Football Game - JOptionPane (input / Output)

Mar 5, 2014

This specific assignment requires me to write a program that calculates the total sales after each football game. There are 4 types of tickets: box, sideline, premium, and general admission. After each game, data is stored in a file... then output the number of tickets sold and total sale amount. Format your output with 2 decimal places.

Okay I know there is a I/O section and wasnt sure where to post this. I need some insight on how to use file input and output as well ... Here is my program:

import javax.swing.JOptionPane;
import java.text.DecimalFormat;
public class ticketsSold
{
public static void main(String[] args)
{
String BoxSeat;
String SideLine;

[Code] ....

View Replies View Related

Calculate Total Length Of N Number Of Bamboo Trees In M Number Of Seasons

Feb 20, 2014

In a forest, there are some bamboo trees .The length of each tree get doubled during winter and increases by one unit in summer , write a Java program to calculate the total length of n number of bamboo trees in M number of seasons. The season always starts with winter.

import java.util.Scanner;
public class Tree {
public static void main(String args[]) {
int length;
int season;

[Code] ....

View Replies View Related

Compute Recursively Total Number Of Blocks In Triangle With Given Number Of Rows

Jul 8, 2014

We have triangle made of blocks. The topmost row has 1 block, the next row down has 2 blocks, the next row has 3 blocks, and so on. Compute recursively (no loops or multiplication) the total number of blocks in such a triangle with the given number of rows.

triangle(0) → 0

triangle(1) → 1

triangle(2) → 3

View Replies View Related

JOptionPane New Lines And New Display Windows?

Jul 1, 2014

Using JOptionPane, I want to display in one window:

1: ***
2: *****
etc

where 1 is the element of the array, and the * are a percentage calculated in a loop. My variables are all being input fine, but the output is 100+ windows:

1:

*
*
*

2:
*

The CLI way would be with print() and println(), but I'm having a tough getting it to be visual.

View Replies View Related

JOptionPane And StringBuilder - Display And Receive Information To / From The User

Mar 6, 2014

I'm using the JOptionPane to display and receive information to/from the user. In addition to this, I am using StringBuilder to receive inputs from the user and then manipulate (append) that input to display the desired output.

//Example

(JOptionPane): "Enter text"
(user input): Java is cool!
(program): *stringBuilder.append(" I love it!")
JOptionPane.showMessageDialog( );
.....

Psuedo-like code. The problem is that showMessageDialog(null, string) and not showMessageDialog(string, string). I want to display the enter text: " Java is cool! I love it! " in the JOptionPane. How do I accomplish this, since showMessageDialog only accepts (null, string).

View Replies View Related

JOptionPane / Entering Valid ID Number

Oct 5, 2014

I am working on allowing a user to enter an ID # using JOptionPane. If the ID is valid, then it will display the ID#, student name, and GPA. If it is not valid, then the window should pop up again to allow the user to enter a valid ID. I have managed to get that far.

I am struggling with once a valid ID # is entered, how do I get the loop to stop? I have tried several different ways, but the code below is the most recent one, and it is still not working!

import javax.swing.*;
public class StudentIDArray
{
public static void main(String[] args)
{
String enteredID;
int idNumber;
int x = 0;

[Code] .....

View Replies View Related

Calculate And Display Normal / Overtime And Total Pay

Sep 12, 2014

The pay rate is php 35.00 per hour. any hours worked after 40 hours is paid at rate of 2 times the normal hourly rate. Calculate and display the Normal Pay, The overtime pay, and the total pay.

OUTPUT MUST BE:

Sample 1 :

Enter Hours Worked: 40 (Sample)
Normal Pay: 1400 (Sample)
Overtime Pay: 0 (Sample)
Total Pay: 1400 (Sample)

Sample 2 :

Enter Hours Worked: 41 (Sample)
Normal Pay: 1400 (Sample)
Overtime Pay: 70 (Sample)
Total Pay: 1470 (Sample)

Here is my code or something, but i cant finish it.

import java.util.Scanner;
public class Workpay {
public static void main(String[]args) {
Scanner in = new Scanner (System.in);
int hours;
int normalpay = 35;

[Code] .....

View Replies View Related

Cumulative Sum - Display Total Price From All Loops Added Together

Feb 27, 2014

In the code below, under calculations, I have x=totalPrice+xXxXxX. Obviously the x's were just place holders, but I wanted to know if there was any way to add something there so the program would tally the totalPrice, store it in the x variable outside the loop, so when the loop ended it would display the total price from all the loops added together where I have System.out.println("TOTAL OF ALL ORDERS: $"+ round.format(x)); at the very end.

Java Code:

import java.util.Scanner;
import java.text.DecimalFormat;
public class ModifyOrderV2TEST
{
public static void main(String [] args)
{
//Rounding
DecimalFormat round = new DecimalFormat("0.00");

[Code] ....

View Replies View Related

Calculate Total Amount Paid And Display It - NULL Error

Dec 10, 2014

Exception in thread "main" java.lang.NullPointerException
at ShoeStore.calculateTotal(ShoeStore.java:103)
at ShoeStore.main(ShoeStore.java:88)

This is the error when program is ran. The program is supposed to calculate the total amount paid for all shoes and display it.

import java.util.Scanner;
 public class ShoeStore
{
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
String shoe_Name, nameStore, type;
int size, shoeAmount;
double sellingCost;
 
 [Code] .....

View Replies View Related

Display Result Of Two Dice Thrown Five Times And Total Of Those Results

Sep 12, 2014

I need to create a simply application that would display the results of two dice thrown five times and the total of those results. This is shown below in the attached file.

The problem is, I have a do-while loop that loops 6 times. Inside the loop, I have 2 random.nextInt(5) that generate random numbers. But how can I output the total? How can I make a variable equal to the sum of the two random numbers if the two random numbers are located inside a do-while loop?

Attached below is also the code I have thus far.

(Attached below is both files: what it needs to look like, and what it currently looks like)

View Replies View Related

JSP :: How To Get Total Number Of Pages In JavaScript

Apr 22, 2014

How to find the total number of pages in java script .how to achieve it.

View Replies View Related

Java GUI - Calculate And Display Total Cost For Certain Automotive Maintenance Services

May 12, 2014

I'm trying to create a GUI application that calculates and displays the total cost for certain automotive maintenance services. The application should contain hree classes: 1) the main class that creates and displays the window; 2) a panel for the routine services and 3) a panel for the non-routine services. 2 and 3 are instantiated in 1. I'm pretty positive the error lies in the NonRoutinePanel class because when I comment it out of the main class the program runs fine. But I can't quite figure out which lines of code or methods are causing the problem.

When I try running the program I get these error messages:

Exception in thread "main" java.lang.NullPointerException
at java.awt.Container.addImpl(Container.java:1040)
at java.awt.Container.add(Container.java:958)
at javax.swing.JFrame.addImpl(JFrame.java:540)
at java.awt.Container.add(Container.java:926)
at JoesAutomotiveGUI.<init>(JoesAutomotiveGUI.java:38)
at JoesAutomotiveGUI.main(JoesAutomotiveGUI.java:111)

Here's my code for the three classes:

import javax.swing.*; // Needed for Swing class
import java.awt.*; // Needed for BorderLayout class
public class RoutineMaintenancePanel extends JPanel
{
public final double oilChange = 26.00;// cost of oil change
public final double lubeJob = 18.00;// cost of lube job

[Code] .....

View Replies View Related

Total Number Of Each Alphabetical Letter From A File

Nov 28, 2014

So far I've got it where the program is reading the file and returning

a:0
b:0
c:0
d:0
e:0
f:0
g:0
h:0
i:0
j:0
k:0
l:0
m:0
n:0
o:0
p:0
q:0
r:0
s:0
t:0
u:0
v:0
w:0
x:0
y:0
z:0

But I need it to print the letters and then the total amount of each character that is found in the file.

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;

[code]....

View Replies View Related

Receive Information (Number) From User And Calculates Its Total

Apr 19, 2014

I wanted to write a simple code that receives information from the user (double-digit number and above) and calculates it's numbers.

For instance- The user wrote a number- 234, the software will return the number 9 (2+3+4 = 9).

Tried to use a loop for that, but I got stuck since I didn't know what to write.

This is what I've wrote so far

Java Code:

import java.util.Scanner;
public class Calculate {
public static void main(String[] args) {
System.out.println("Please type a number larger than 9");
Scanner type = new Scanner(System.in);
String number1 = type.nextLine();

for( int i = 0; i < number1.length(); i++ ){
int calculate = number1.charAt(i);
}
}
} mh_sh_highlight_all('java');

View Replies View Related

Basic GUI Calculator - Display Amount Of Commission And Total Annual Salary In Dollar Format

Apr 28, 2014

So, I am supposed to write a program that calculates the total annual compensation for a salesman using user input for the salary, sales, and commission rate (list of 3 predefined commission rates. have to display in dollar format the amount of commission and total annual salary.

CommCalc class

public class CommCalc
{
//attributes of class, stored data
private double sales;
private double salary;
private double rate;
//and a total field? beware stale data.
//store sales argument from sales field
public void setSales(double sal)

[Code] ....

I know that i have to fix some of the semantics . I have this code that I made earlier, is there an easy way to make it into a GUI interface? Or will I have to go throughthe code lines to add the JOptionPane? And I am a little confused on how to make a list (array) for the commission rate.

View Replies View Related

Adding Number Of X Consecutive Values In Array And Get Minimal Total Value

Nov 9, 2014

Here is my problem: if I want to add a number of X consecutive values in an array and get the minimal total value along with the indexes that caused this result, how can I do that?

For example:

X = 2
array[4] = (5,2,8,6,7)

start adding every 2 consecutive values as following:

array[0]+array[1] = 5+2 = 7 //minimal value
array[1]+array[2] = 2+8=10
array[2]+array[3] = 8+6= 14
array[3]+array[4] = 6+7=13

output:

minimal value = 7
indexes of minimal values are: 0 and 1

View Replies View Related

Counting Total Number Of Searches - Calling Price Method

Apr 23, 2015

How would I program a counter that will return the total number of search, failed searches and correct searches. The second thing is how can a return the price of the search methods with out calling for it specifically. Here is my current code.

package stu.paston.program7;
import java.util.Scanner;
public class MainClass
{
public static void main(String[] args)
{
InventoryClass productData= new InventoryClass();

[Code] ....

View Replies View Related

Program Is To Accept Number And Display New Number After Removing All Zeros

Dec 29, 2014

ex
Sample input:2340980
Sample Output:23498

this is the program i have tried but is dosent work

import java.util.*;
class zero
{
public static void main(String args[])
{

[Code]....

View Replies View Related

Board Of Colors And Players

Sep 14, 2014

My assignment is for a game where there is a board of colors and each player draws a color and moves to that position on the board. It will then output how many cards total in the game it took whichever player to win. If no winner it outputs the number of cards that none won by going through. I attached the file that corresponds with my code.

This is the desired output:

Player 1 won after 7 cards.
Player 2 won after 8 cards.
No player won after 8 cards.
Player 2 won after 4 cards.
No player won after 6 cards.
Player 2 won after 8 cards.
Player 1 won after 4 cards.
Player 2 won after 8 cards.
Player 1 won after 1 cards.
No player won after 200 cards.
Player 4 won after 100 cards.

import java.io.*;
import java.util.Scanner;
public class ProgrammingAssignment1 {
/**
* @param args the command line arguments
*/
public static int players;
public static int cards;
public static int boardlength;
public static String board;

[Code] .....

The output that I get is:

Player 1 won after 3 cards.
Player 2 won after 8 cards.
No player won after 8 cards.
Player 1 won after 3 cards.
No player won after 6 cards.
Player 2 won after 8 cards.
Player 1 won after 3 cards.
Player 2 won after 8 cards.
Player 1 won after 1 cards.
No player won after 200 cards.
Player 4 won after 100 cards.I guess I'm supposed to set the playerPos[] to -1, but I'm unsure how.

Attached File(s) : colors.in.txt (1.5K)

View Replies View Related

Football Manager - Find Out Optimal First Eleven Amongst 25 Or 30 Players

Nov 26, 2014

I am looking into making a program, that will find out the optimal first eleven (in football or soccer for americans) amongst 25 or 30 players. This is going to apply for a computer game: "Football manager 2015"

I was thinking one class would be the player class that is going to have the variables:

player_number (unique) integer
name string
position (there are eleven positions)
position_rating for each position capable of playing

constructor would be add_player(int number, string name)

and a method would be add_position(position, position_rating)

one player can have more than one positions

another class would be the position

position name (unique) string

that's all I can think of now.

the main class would do a loop

starting with a random or defined position it would do all combinations of every single player into each position.

For example it could start with center forward position. There are 5 available players for that position. Lets say the program picks the first player that is also capable of playing in wide position. If the player is picked for center forward he is not avaialable for wide position.

Then the program would move to the wide position and lets say there are 4 players available. It would pick one.

Once 11 players are selected it would add the 11 ratings.

and start over for a different player in center forward position.

at the end of all loops it would print out the 11 players into their respective positions that got the best score.

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved