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


ADVERTISEMENT

Multi-sided Dice - Keep Track Of Total Sum Of All Dice In Array

May 7, 2014

I'm finishing up this assignment, and I'm stuck. These are the last 2 instructions:

. Roll each of the Dice by invoking the roll method on each Dice in the array.
. Keep track of the totals sum of all the dice in the array. Be sure to roll the dice array at least 10000 times.

How to finish it up?

Here's my code so far:

package homework3;

import java.util.Random;
public class Dice {
private int numberShowing;
private final int numberOfSides;
private static final Random randomNumber = new Random();
public Dice() {
numberOfSides = 6;

[Code] ....

View Replies View Related

Not Counting Total Of Dice Rolls

Jan 25, 2015

I am currently trying to roll 5 dice 100,000 times and output the number of times each possible total (of dots/pips) occurs. It seems to output the incorrect thing and isnt counting the occurrences properly.

public class lab_DiceRollTest {
public static void main(String[] args) {
int total;
int total2;
String valid;
String isDifferent;
int rolls = 100000;
int d = 0;

[code]...

View Replies View Related

Roll Two Dice / Add Them Together And Print The Result

Oct 23, 2014

Write a program that rolls two dice, adds the numbers and prints out the results. I have managed to do this but we have to make it a horizontal table instead of a vertical one. like the attached file "CORRECT", right now i only get the "NOTCORRECT". i have tried for hours to fix this but i can't.

import java.util.Random;

public class Statistikk {
public static void skrivStatistikk() {
Random rand = new Random();
int[] antall = new int[13]; {

[Code] .....

(Antall is basically frequency|side is the same as a face of a die)

Here is my code, does my code need improvement? Or is it my printf that is the issue? i've tried deleting the 's and adding the printf to the same line, but nothing worked.

Attached image(s)

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

Keep Track Of Output - How Many Times Each Total Occurs

Jan 23, 2015

I am currently truing to make this class instantiate 100,000 dice rolls of 2 dice. And I also need to keep track of how many times each possible total occurs and I am having trouble outputting the result. Right now when I run my code it is just showing the results of each of the 100,000 roles.

public class ltefera_DiceRollTest {
public static void main(String[] args) {
ltefera_DiceRoll diceRoll = new ltefera_DiceRoll(10);
System.out.println("Total # of pips" + "
");
diceRoll.printArray();
System.out.println(diceRoll.countDice(2));
System.out.println(diceRoll.isArrayDataValid());
System.out.println(diceRoll.getTotal());
System.out.println(diceRoll.allDifferent());

[code]....

"how many time each possible total occurs"

View Replies View Related

Randomly Throw Two Dice And Display Their Values

Mar 25, 2014

Dice are used in many games. One die can be thrown to randomly show a value from 1 through 6.

Design a Die class that can hold an integer data field for a value (from1 to 6).

Include a constructor that randomly assigns a value to a die object. Appendix D contains information on generating randomnumbers. To fully understand the process, you must learn more about Java classes and methods. However, for now, you can copy the following statement to generate a random number between 1 and 6 and assign it to a variable. Using this statement assumes you have assigned appropriate values to the static constants.

randomValue = ((int)(Math.random() * 100) % HIGHEST_DIE_VALUE +
LOWEST_DIE_VALUE);

Also include a method in the class to return a die's value. Save the class as

Die.java.

Write an application that randomly "throws" two dice and displays their values. After you read the chapter Making Decisions, you will be able to have the game determine the higher die. For now, just observe how the values change as you execute the program multiple times. Save the application as TwoDice.java.

View Replies View Related

Swing/AWT/SWT :: Using SetText To Display GUI Results

Feb 15, 2015

I have the code here to populate a GUI. I have the math and then print out and return a single number. I have tried to use setText in the class CalculateButtonHandler.

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class RectangleProgram extends JFrame {
private JLabel lengthL, widthL, areaL, perimeterL, averageL;

[Code] ....

View Replies View Related

Trying To Display Array Results In GUI Window JAVA

Sep 16, 2014

I am having the hardest time trying to figure out how to display an array in a 1-window GUI.

I can display 1 book separately, by basically ignoring the array and creating a new object for each book, but I need all 5 books to display in one window, and that's where I'm lost. I'd really like to use the arrayI built to generate the books in the GUI. The information of each book appearing horizontally, and the different books appearing vertically.

// Bookstore.java
// This program displays information on multiple books

/* Currency Formating Import */
import java.text.NumberFormat;
import java.util.Locale;
import java.util.Arrays;

[Code] ....

View Replies View Related

GUI To Display Search Results Based On User Input Server Name

Jul 18, 2014

I am using a GUI to display search results based on user's input server name. I am using MS Access as DB and I have the DSN set up correctly.But the search results are displayed for the first typed value in text filed. I am getting same result set every time though i input different server names .

import java.sql.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.table.DefaultTableModel;
public class SearchResult implements ActionListener{

[Code]...

View Replies View Related

Count Number Of Characters Contained In Both Strings And Display Results

May 2, 2014

I have been working on this for hours and cannot get it to work properly. The program is to count the number of characters contained in both strings and display the results. It is also to display the final statement, but only once. This version has a complete statement for each matching character.

import java.util.Scanner;
public class CountMatches {
public static void main(String[] args) {
String firstStr = ("");
String s1 = firstStr;

[Code] ....

View Replies View Related

String Characters Display First Three Multiple Times

Sep 26, 2014

I am trying below challenge to display first three characters three times if the size of the string is greater than 3.

Say if i send hello i should get helhelhel

if i send xyz i should get xyzxyzxyz

I wrote as below

public String front3(String str) {
if(str.length()==3){
return str+str+str;
}
if(str.length()>3){
String str2=new String(new char[]{str.charAt(0),str.charAt(1),str.charAt(2)});
return str2;
}
}

I am getting error as below

Error:public String front3(String str) {
^^^^^^^^^^^^^^^^^^
This method must return a result of type String

Possible problem: the if-statement structure may theoretically allow a run to reach the end of the method without calling return. Consider adding a last line in the method return some_value; so a value is always returned.

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

JSP :: Result Displayed With Display Tag Library

Apr 21, 2014

I have html code that use form and the result displayed with display tag library the form forward to servlet page but when I use a javascript to change value of hidden after returning to html page the value of hidden input deos not change

<form name="form" method="get" action="Text" >
<input type="checkbox" dir="rtl" ID="CheckBox2" value="check" onclick="All(this,'all','_chk');">
</td>         
<td> <input type="submit" name="delete" value="حذف"></td>
</tr><p>
<div align="center">

[code]....

View Replies View Related

Feet To Meters And Display Result

Dec 3, 2014

I have to do feet to meters code. here is the question. Write a Java program that reads a number in feet, converts the number to meters and displays the result. One foot is 0.305 meters.

here is my code :

import java.io.*;
class FeetToMeters
{
public static void main (String[] args) throws IOException
{
InputStreamReader inStream = new InputStreamReader (System.in);
BufferedReader stdin = new BufferedReader (inStream);

[Code] ....

I have seen alot of people use the scanner tool for the start of it but we never learned it as it is an online course but we may end up learning it farther on in our java programming. we have just started with the input and output stuff.

View Replies View Related

JSP :: Using ForEach Tag - Display Result Set From Database

Apr 26, 2015

I am trying display the result set from the database.I am getting the following exception :

Caused by: javax.servlet.jsp.JspTagException: Don't know how to iterate over supplied "items" in <forEach>
at org.apache.taglibs.standard.tag.common.core.ForEachSupport.toForEachIterator(ForEachSupport.java:286)

My Jsp code :

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">

[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

Java Program Using Nested Loop To Compute / Display Average Of Test Results For Each Experiment

Apr 2, 2015

Four experiments are performed, each consisting of six tests. The number of test results for each experiment is entered by the user. Write a Java program using a nested loop to compute and display the average of the test results for each experiment.

You can run the program by entering the following test results:

Experiment 1 results:23.231.516.927.525.428.6
Experiment 2 results:34.845.227.936.833.439.4
Experiment 3 results:19.416.810.220.818.913.4
Experiment 4 results:36.939.549.245.142.750.6

View Replies View Related

Swing/AWT/SWT :: Display Console Result In JTextarea

Mar 29, 2014

I have a problem with my code,in fact I can't output the stream from console to my jTextarea,this is my code:

public class AudioFrame extends javax.swing.JFrame {
static double[] audioFile;
static String audioToDecode;
static String audioKey;
static String outputName;
static String outAudio;
static String name;
static int command;
static String textToEncode;

[Code]...

View Replies View Related

Servlets :: Unable To Display Result In Web Browser

Mar 14, 2014

When I am invoking a servlet class file from my HTML file instead of displaying output in my browser it is downloading my output as a file..Why it is?..

View Replies View Related

Translate Morse Code And Then Display Result

Jul 24, 2014

I'm currently working on a program that is supposed to translate morse code and then display the result and I'm stuck, my program has tons of errors when I try to compile.

public class Assignment10
{
public static void main ( String [] args )
{
String str = Input.getString("Please type in a word");
char [] letters = {'a','b','c','d','e','f','g',

[Code] .....

View Replies View Related

Count And Display Number Of Times Specified Character Appears In String

Mar 7, 2014

Write a program using a while-loop (and a for-loop) that asks the user to enter a string, and then asks the user to enter a character. The program should count and display the number of times that the specified character appears in the string. (So, you will have two separate program codes, one using a while-loop and the other one using a for-loop.)

Example:
Enter a string: "Hello, JAVA is my favorite programming language."
Enter a character: e
The number of times the specified character appears in the string: 3

I don't even know where to begin I've only got this

import java.util.Scanner;
 public class letterCounter {
 public static void main(String [] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter a string");
String myString = sc.nextLine();
System.out.println("Enter a letter");
String letter = sc.nextLine();
}
}

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

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 View Related

Roll Four Sided Die Between 100 And 1000 Times Depending On Input And Display Answer

Oct 29, 2014

I'm trying to get the program to roll a four sided die between 100 and 1000 times, depending on your input, and then displaying the answer.

public class Lab08
{
public static void main(String[] args)
{
int v1 =0, v2 = 0, v3 = 0, v4 = 0;
int n;
char response;
System.out.print("Enter number of rolls (100-1000): ");
 
[Code] ....

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







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