Creates Two Die Objects And Roll Them Display The Values
May 4, 2014
I've written a die program, and i want the user to type any key in order to continue, how do i achieve this ?
I have already created a Die class, i just want to implement the main method now.
PHP Code:
package test;
/* This program demonstrates the use of a user-defined class
public class RollingDice {
// Creates two Die objects and rolls them display the values.
public static void main (String[] args) {
Die die1 = new Die();
System.out.println("Roll the die ")
}
} mh_sh_highlight_all('php');
What should i add after System.out.println, So that the user types (any key, or types "Enter" for example, for the die to roll). i dont want the die to roll by itself i Want the user to interact with the program in order for it to roll.
View Replies
ADVERTISEMENT
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
Feb 11, 2015
So I want to write a constructor that creates a new object with the data from the array values. I don't know where to start. It's the last method in the code:
public class Measurements {
private double[] values;
private double[] newArray;
private int n; //numberofvalues
private double[] ms;
public Measurements(int max) { //constructor
[code]....
View Replies
View Related
Oct 28, 2014
Whether I pass primitives or objects the original value does not change. Is this expected result?
Java Code:
public class Class {
public static void main(String args[]) {
int x=3;
doItPrim(x);
System.out.println(x);//3
Integer i=new Integer(3);
[Code] ......
View Replies
View Related
Nov 3, 2014
Everything is written up and looks good and i get no compile errors but every student object other than the default constructor has null and zero values when printed.
import java.text.DecimalFormat;
import java.lang.Math;
public class Student
{
//instantiate variables
[Code] .....
View Replies
View Related
Apr 3, 2014
The main method should creates a Student object with name as "Bill" and marks as {88,92,76,81,83} and print it.
Java Code:
class TestStudent {
public static void main(String args[]) {
Student1 st = new Student1();
st.name = "bill";
Student st1[] = new Student[6];
//This gives error
st1[].marks = {1, 5, 8, 9, 7, 6}; mh_sh_highlight_all('java');
View Replies
View Related
May 6, 2014
Create an application that allows a user to enter values for an array of seven Salesperson objects. Offer the user the choice of displaying the objects in order by either ID number or sales value.
import java.util.*;
public class SalesPersonSort
{
public static void main(String args[]) {
int[] id = new int[7];
int[] salesValue = new int[7];
final int END = 999;
[Code] ....
View Replies
View Related
Jan 13, 2014
I have a code to resize a single rectangle. I would like to display and resize multiple rectangles independently and according to my research on the net, the best way is to use an arraylist. So I modified the code in this sense, except ...when I run the code, the rectangles appear good but impossible to resize. I think the problem comes from mousePressed, Released, Dragged and Moved methods. When I use the mouse to resize the rectangle, nothing happens. The code does not interact with the arraylist, and therefore with rectangles it "contains". Resizing is my main class, the MouseAdapter is in the Resizer class (below).
Resizing component; boolean dragging = false; // Give user some leeway for selections.
final int PROX_DIST = 3; Path2D.Double selectedPath; public Resizer(Resizing rz) {
component = rz; component.addMouseListener(this);
component.addMouseMotionListener(this);
[Code] .....
View Replies
View Related
Dec 10, 2014
This program is basically complete. It compiles and runs. It is a college course assignment that I pretty much completed but for the last part in which I'm suppose to change the values of all fields and display the modified values using a toString method. Modifying the values of the fields is where I am stuck. I don't think I need to create a new text data file to do this. The instructor only asked that all the values of fields be changed and this was the last part of the assignment so I don't think it involves creating additional ObjectOutputStream and ObjectInputStream objects. I'm getting a NullPointerException error on line 161.Here is the code. I'm also including the input data file.
//create program so that objects of class can be serialized, implements interface Serialiable
//create constructor with 4 parameters with accompanying get and set methods, Override toString method
//create text file with 5 records, create Scanner object,ObjectOutputStream, and ObjectInputStream
//create new ItemRecord object, change values of all fields in ItemRecord object using object's set methods
//modify ItemRecord object using toString method
[hightlight =Java]import java.io.Serializable;
public class ItemRecord implements Serializable
[Code] .....
This is the error message:
----jGRASP exec: java ItemRecordReport
Item Cost Quantity Description
Number
A100 $ 99.99 10 Canon PowerShot-135
A200 $149.99 50 Panasonic-Lumix T55
A300 $349.99 20 Nikon- D3200 DSRL
A400 $280.99 30 Sony- DSC-W800
A500 $ 97.99 20 Samsung- WB35F
Exception in thread "main" java.lang.NullPointerException
at ItemRecordReport.main(ItemRecordReport.java:161)
----jGRASP wedge2: exit code for process is 1.
----jGRASP: operation complete.
Here is the data file:
A100 99.99 10 Canon PowerShot-135
A200 149.99 50 Panasonic-Lumix T55
A300 349.99 20 Nikon- D3200 DSRL
A400 280.99 30 Sony- DSC-W800
A500 97.99 20 Samsung- WB35F
Here is the data file for the modified field values.
B100 98.00 10 ABC1010
B200 97.00 15 DEF1020
B300 96.00 10 GHI1030
B400 95.00 05 JKL1040
B500 94.00 01 MNO1050
View Replies
View Related
Mar 7, 2014
My intention is to see the real reference values (memory locations) of 2 StringBuilder objects as below:
StringBuilder sb2 = new StringBuilder("123");
StringBuilder sb3 = sb2;
System.out.println(sb2);
System.out.println(sb3);
I was expecting a printout like
@S234853
@S984724
But all I got was 123 printed twice. How can i print out the reference values instead of what is inside the StringBuilder object ?
View Replies
View Related
Apr 15, 2014
I am attempting a programming exercise to display the values in the Fibonacci sequence from F0 to F15. I understand the concept, but, for some reason my equation is simply creating a resulting string of numbers that simply increase by 2's. As, I know it is supposed to be the sum of the previous F and the F that precedes that one to total the new F number. It seems so simple yet I seem to be far off. As usual, I have worked my code for your review.
/*
* This program calculates the "Fibonacci sequence."
* A "sentinel" is used to limit the extent the calculation.
*/
import acm.program.*;
public class bookFibonacciTest2a extends ConsoleProgram {
/* Specifies the limit value of the calculations */
private static final int SENTINEL = 16;
public void run() {
println ("This program display Fibonacci sequence numbers 0 - 15.");
[Code] .....
View Replies
View Related
Sep 13, 2014
I am writing a program that accepts input from the user, I want default values displayed before the input values.
Java Code:
public surfboards() {
surfboardType = "Type not assigned";
shaperName = "Shaper not assigned";
constructionType = "Construction Type not assigned";
surboardSize = 0D;
} mh_sh_highlight_all('java');
I can get the output to display as shown below
(THIS IS WHERE I WANT DEFAULT CONSTRUCTOR DISPLAYED. Currently not displayed)
Type not assigned
Shaper not assigned
Construction Type not assigned
0 Feet
(THIS IS WHERE I WANT DEFAULT CONSTRUCTOR DISPLAYED. Currently not displayed)
input:
Java Code:
Enter Surboard Type:
test
Enter Shaper Name:
test
Enter Surfboard Construction Medium:
test
Enter Surfboard Size:
6.5 mh_sh_highlight_all('java');
Output:
test
test
test
6.5 feet
View Replies
View Related
Feb 16, 2014
I am just displaying my values in different ways and I can't seem to get my values to display one at time on new lines. I dont know why that isn't compiling. The part i am having trouble with has the "Not Working" tag in the code.
[highlight=Java]
//Trying to figure out how to use /n
public class Test
{
public static void main(String[] args)
{
int gold= 5;
int silver= 3;
int bronze= 1;
[Code] ......
View Replies
View Related
Dec 4, 2014
The program contains username and password which on submission checks with the database if the details entered are right or wrong....on right details it Displays Welcome (name) and (lastname) parameters from database.
View Replies
View Related
Mar 21, 2011
I am new to jsp .i created a wepage in jsp. That's i need to create dynamic textboxes in jsp and want to display the values of the textbox in next page.
View Replies
View Related
Apr 8, 2014
I've been trying to learn how to read in file input and have a question about this piece of code:
Java Code:
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Scanner;
public class readFile {
public static void main(String args[]) throws FileNotFoundException{
File file = new File("file.txt");
int sum[]=new int[5];
int i=0;
[Code] .....
"file.txt" holds the following information:
1
2
88
42
56
89
But my output looks like:
2
42
89
if I take out sum[i]=input.nextInt(); it will display all values in the file.
View Replies
View Related
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
Apr 2, 2015
I need assigning the selected hashmap values into a list and to display the values in a jsf page. The user will select certificates and will be stored in the below list:
private List<String> selectedCertificates = new ArrayList<String>();
The selectedCertificates will have the values ("AA","BB"). Now I will be passing the list into a hashmap in order to get the names and to display them on the jsf page.
My code is below:
Map<String, String> CertificatesNames =
new HashMap<String,String>(selectedCertificates.size());
CertificatesNames.put("AA", "Certificate A");
CertificatesNames.put("BB", "Certificate B");
CertificatesNames.put("CC", "Certificate C");
for(String key1: selectedCertificates) {
System.out.println(CertificatesNames.get(key1));
}
I want to display in my jsf page :
Certificate A
Certificate B
Now my issue is that is how to display all the values of the CertificatesNames.get(key1) in the jsf page as I tried to do the below and it printed all the values when I used the #{mybean.beans} using the :
List beans =
new ArrayList(CertificatesNames.values());
So how to do this?
View Replies
View Related
Jan 27, 2014
I have a program in which I am prompting users for integer values to display in a JFrame. I call the method below to load an array with their input:
Java Code:
public String inputAssembly(){
if (!jtfInput.getText().matches("d")){
JOptionPane.showMessageDialog(null, "Input must be of integer value.");
} if (jrbFar.isSelected()){
return jtfInput.getText() + jrbFar.getText();
[Code] ....
Regardless of the input, both messages display (invalid input / got it). I've tried debugging so I know that the values are getting entered and read correct, at least to my knowledge. It is a very simple regular expression, only checking to be sure an integer was entered.
View Replies
View Related
Feb 13, 2014
I have the following simple "selectManyCheckbox" specified in my jsf page:-
<h:selectManyCheckbox id="animalsmc" layout="pageDirection" value="#{animalSelectionBean.selectedAnimals}">
<f:selectItem itemValue="1" itemLabel="Lion"/>
<f:selectItem itemValue="2" itemLabel="Tiger"/>
<f:selectItem itemValue="3" itemLabel="Elephant"/>
<f:selectItem itemValue="4" itemLabel="Eagle"/>
<f:selectItem itemValue="5" itemLabel="kangaroo"/>
</h:selectManyCheckbox>
I have the following specified in my bean class:-
private int [] selectedAnimals;
...
public int[] getSelectedAnimals() {
return selectedAnimals;
}
public void setSelectedAnimals(int[] selectedAnimals) {
this.selectedAnimals = selectedAnimals;
}
I would like to know how to display the values of selected checkboxes on the JSF page after submitting the form? I tried outputtext, however it displays the object and not the values. I cannot even frame the outputformat for the same.
View Replies
View Related
Oct 21, 2014
Write a program that reads a sequence of input values and displays a bar chart of the values, using asterisks, like this:
********************** **************************************** **************************** ************************** **************
You may assume that all values are positive. First figure out the maximum value. That value's bar should be drawn with 40 asterisks. Shorter bars should use proportionally fewer asterisks.
import java.util.Scanner;
import java.util.ArrayList;
import java.util.Arrays;
public class Array717
{
public static void main( String[] args )
[Code] ....
The problem is that all this code does is print 1 line of *'s and what seems to be thousands of them
View Replies
View Related
Feb 17, 2014
I am making a Dice Roll GUI and I have most of it down and I only need this constructor to work for the program to work (I think). I don't know where to place the constructor, I tried placing it around the RollButton class but it still didn't work and gave me java error constructor in class cannot be applied to given types
Here's my constructor:
private JPanel panel;
public RollButton(JPanel panel){
this.panel = panel;
}
Here's my code:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;
import java.util.Random;
import javax.imageio.ImageIO;
[code]....
View Replies
View Related
Nov 26, 2014
Here is what I have so far:
/**
* This class encapsulates a simple dice game. The number of dice and number of sides on those dice are given by instance variables. The outcomes ArrayList holds a list of all possible outcomes of throwing that number of dice with that number of sides.
*
* If there were 2 dice, each with 6 sides, then possible outcomes would include 1 1, 1 2, 1 3, 1 4, 1 5, 1 6, 2 1, 2 2, 2 3, and so on.
*
* Your task is to complete the methods that calculate the possible outcomes. One method calculates outcomes allowing for repeated numbers. One method calculates the outcomes of a fictional dice game where repeated numbers cannot occur.
*
* You must use recursion. This is a variation on the permutations problem from the book.
*/
public class Dice
{
private static int numberOfSides;
private static int numberOfDice;
public ArrayList<String> outcomes;
[code]...
I manage to calculate the numberOfOutcomes correctly, but then get a nullPointerException. Also, is there a way that I can use getNumberOf Outcomes without making it static? The testing code that the teacher provided is using it in another class and if I make it static, then it doesn't work in that file.
View Replies
View Related
Mar 8, 2014
The code I have below asks the user how many times you want to roll the dice. It rolls dice 1 and dice 2 randomly and gives the total. Now, I'm trying to keep track of the result of each roll using an array that is indexed by the sum of the roll of the two dice. Then I want to output my result in a table that shows each value (from 2 - 12)) and the number of times that value was rolled. I would like to do this preferably with the JTextArea class, but it doesn't have to be. I keep getting errors.The code below works for the dice rolling in the 1st paragraph. I took out all the bad code I was trying to use for the 2nd paragraph.
package Part2pack;
import java.util.Random;
import javax.swing.JOptionPane;
class Dice{
public static void main (String args[])
{
String input = " ";
int count = 0,dice1,dice2;
[code]....
View Replies
View Related
May 8, 2014
what code I should add to my program in order to get these dice to roll. The program, according to my teacher, is CORRECT so far, so I'm not going to change anything. I just need to know how to roll the 2 dice I added in. I just want to get it done. No math.Random. The direction is: Roll each of the Dice by invoking the roll method on each Dice in the array.
My code:
//Dice.java
package homework3;
import java.util.Random;
public class Dice {
private int numberShowing;
private int numberOfSides;
private static final Random randomNumber = new Random();
[code]....
View Replies
View Related
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