How To Restart A Loop At A Certain Point
Jun 8, 2014
I made a blackjack code in java and I need to find a way to replace the place where I added a system.exit with a way to ask the user if they'd like to play again and restart the loop, keep in mind that I don't need the program to restart as I'd like to keep the value of their chips considering if they've won or lost.
Secondly, because it is a blackjack code, when it deals the cards, I would like for it to also print out K, Q or J but still consider it the number 11. Can I make an Ace count as 1 and 11?
One last question, is there anyway to add the suits of the cards such as (clubs, spades etc.) but the actual signs and if the signs aren't possible at all then the letter ('C', 'S', 'H', 'J') will have to do I guess.
import java.util.Scanner;
class Blackjack {
public static void main(String[] args) {
Scanner scan = new Scanner (System.in);
Scanner num = new Scanner (System.in);
System.out.println("Welcome to Blackjack!");
[code]....
View Replies
ADVERTISEMENT
Jun 5, 2014
I was reading the oracle java tutorial under: URL....Here's the code for the Point class:
public class Point {
public int x = 0;
public int y = 0;
//constructor
public Point(int a, int b) {
x = a;
y = b;
}
}
and in the Rectangle class you have the following constructor:
public Rectangle(Point p, int w, int h) {
origin = p;
width = w;
height = h;
If we create a new Point object like this:
Point originOne = new Point(23, 94);
and then a new Rectangle object like this:
Rectangle rectOne = new Rectangle(originOne, 100, 200);
Will that set originOne to point to the object Point at (23, 94). just want to make that this is the meaning of this statement: Point(Point p)Constructs and initializes a point with the same location as the specified Point object.
View Replies
View Related
Oct 29, 2014
I am creating a body mass index calculator and i was wondering how i could make its so that the program resets itself once the BMI has been found....
My code is below...
package bmiCalculatorSource;
import java.util.Scanner;
public class BMICalculator {
public static void main(String[] args) {
final double KilogramsPerPound = 0.453;
final double MetersPerInch = 0.026;
[Code] ....
View Replies
View Related
Mar 19, 2014
how to make this restart button work. This is what I have so far. I have put the restart button code in red and bold...
package Game;
public class Buttons extends javax.swing.JPanel {
private GameWorld world;
private int restart;
[code]....
View Replies
View Related
May 22, 2014
how I would achieve the concept of saving the contents of a JTable, so even after program restarts, the table would retain the data. I am developing a utility that will be a password storage book. The user enters passwords and they are stored in a JTable. Currently, the table resets whenever the program is restarted, however I would like it to keep it's data. URL....
View Replies
View Related
Feb 15, 2014
I'm working in a GUI program, but I'm not going to put the code because there is a lot of code and files. Instead, I will try to put it an example.
Let say:
I'm working in a GUI program that ask form the user to enter two number's. When the user press at the calculate button. It will show up the output. However, the program won't exit unless the user press at red (X).
int x = user_Input1;
int y = user_Input2;
int total = x + y; //
JOptionPane.showMessageDialog(null, total);
I know that there will be a (total) now, so my question is here how can I reset all the calculation and have a new total that will show up when the user enter two number's again.
View Replies
View Related
Jan 31, 2014
how the data is stored in float. It seems like the range would be greater because it stores scientific notation rather than plain value, whilst integer arithmetic performance is better. float should be used to store bigger values and integer should be used for speed when values are smaller. As an example, I want to have cubic volumes ranging from about a handful to cargo ship. So float would be necessary for that.
View Replies
View Related
Apr 26, 2014
designing a program which allows you to buy stuff from the jframe with 10x items each with different pricing, so once you click the image button the cost of that is displayed in the textfield, ive been trying to set the jtextfield to a decimal point but have not been able to so far,
if (source == jBSofa) {
System.out.println("Sofa");
{
dTotal = dTotal + 599.99;
jTotal.setText(Double.toString(dTotal));
DecimalFormat myFormatter = new DecimalFormat("#####.#");
String output = myFormatter.format(dTotal);
a visual aspect of it.
View Replies
View Related
May 8, 2014
What are the x- and y-coordinates of the Points referred to as p1, p2, and p3 after the following code executes? Give your answer as an x-y pair such as (0, 0). Recall that Points and other objects use reference semantics.
PHP Code:
Point p1 = new Point();
p1.x = 17;
p1.y = 9;
Point p2 = new Point();
p2.x = 4;
p2.y = -1;
Point p3 = p2;
p1.translate(3, 1);
p2.x = 50;
p3.translate(-4, 5); mh_sh_highlight_all('php');
P1:
P2:
P3:
My guesses were: P1:(20,10) //Correct
P2:(50,-1) //Incorrect
P3:(0,4) //Incorrect
View Replies
View Related
Jan 7, 2015
the output of this:
int x = (int) 24.6;
View Replies
View Related
Apr 18, 2015
Right now it displays a number like this "$25.0" and I want it to display it like this "$25.00" and don't know how to do it.
View Replies
View Related
Sep 29, 2014
I need to fill up 1/10th of the board with mines but i am only able to successfully put 1! also my goal is not showing up on the game even though i put it as an up arrow.
package Homework4;
import java.util.Random;
import java.util.Scanner;
public class HW4 {
//Creates a new type to be used to create the board
[Code] ......
View Replies
View Related
Aug 13, 2014
I wanna write a program that take an Hexadecimal and convert it to floating-point . what should I do ?
View Replies
View Related
Apr 12, 2014
From a two-dimensional grid 5x5 that looks like this:
(0,0)(0,1)(0,2)(0,3)(0,4)
(1,0)(1,1)(1,2)(1,3)(1,4)
(2,0)(2,1)(2,2)(2,3)(2,4)
(3,0)(3,1)(3,2)(3,3)(3,4)
(4,0)(4,1)(4,2)(4,3)(4,4)
We have Starting point that is (3,0) and an ending point is (1,3). We can only move up and right to get to the ending point by using recursion. We have to list all possible paths from (3,0) to (1,3)
Example: paths:(3,0)(2,0)(1,0)(1,1)(1,2)(1,3)
(3,0)(2,0)(2,1)(1,1)(1,2)(1,3)
etc...
I was able to get from (3,0) to (1,3) but how to list the other paths. This is my code so far
public class Program7 {
public static void main(String[] args){
int size = 5;
int x1 = 3;
int y1 = 0;
int x2 = 1;
int y2 = 3;
System.out.println(x1+" "+y1);
System.out.println(x2+" "+y2);
int [][] path = new int[size][size];
grid(path,x1,y1,x2,y2);
[code].....
View Replies
View Related
Apr 12, 2014
From a two-dimensional grid 5x5 that looks like this:
(0,0)(0,1)(0,2)(0,3)(0,4)
(1,0)(1,1)(1,2)(1,3)(1,4)
(2,0)(2,1)(2,2)(2,3)(2,4)
(3,0)(3,1)(3,2)(3,3)(3,4)
(4,0)(4,1)(4,2)(4,3)(4,4)
We have Starting point that is (3,0) and an ending point is (1,3). We can only move up and right to get to the ending point by using recursion. We have to list all possible paths from (3,0) to (1,3)
Example: paths:(3,0)(2,0)(1,0)(1,1)(1,2)(1,3)
(3,0)(2,0)(2,1)(1,1)(1,2)(1,3)
etc...
I was able to get from (3,0) to (1,3) but how to list the other paths. This is my code so far
public class Program7 {
public static void main(String[] args){
int size = 5;
int x1 = 3;
int y1 = 0;
int x2 = 1;
int y2 = 3;
System.out.println(x1+" "+y1);
System.out.println(x2+" "+y2);
[Code] ....
View Replies
View Related
Jul 27, 2014
Our professor asked us to make a Point Of Sale Program that will allow the user to choose from a menu(like a fast-food chain) and how to do this.
The program must have the following:
-A menu consisting of 25 recipes (including their prices)
-The user must also be able to choose how many orders they want
-The user must be able to remove or add more to their current order
-The user must input their money and get their change
View Replies
View Related
Apr 26, 2014
//Design/write a class named MyPoint to represent a point with x and y coordinates. The class should contain:
//->Two variables, x and y, that represent the coordinates
//->A no-arg constructor that creates a point (0,0)
//->A constructor that constructs a point with specified coordinates
//->Two getter (accessor) methods for the variables x and y
//-> A method named distance that returns the distance from a point to another point of the MyPoint type
//-> A method named distance that returns the distance from a point to another point with specified x and y coordinates.
//Draw the UML Diagram for the class. Implement the class. Write a test program that creates two points (0,0) and (10, 30.5) and displays the distance between them.
I have written the program but not I have to do it with user input ....
class MyPoint {
private double x;
private double y;
public double getx()
{
return x;
}
public double gety()
[Code] ....
View Replies
View Related
May 26, 2014
So I'm making buttons for a game I'm making. The graphics work, at least to the extent that I don't have to fix them yet. However, click detection is a bit iffy. For example pressing where the black line is in the first picture below, triggers a response. Now obviously that point is not on the button. I have tested the buttons bounding box by drawing a rectangle around it, using it's getBounds() method (which is also used for click detection) and it draws a perfect rectangle around it. So then I tested the mouse click points and it turns out that even though the button is placed at y = 100, at the black line, the mouse point is also equal to 100... Now, why that is happening, especially because, if I place the button in the top left corner, the mouse detection correctly detects the top pixels and there is no offset...
View Replies
View Related
May 25, 2015
I have a problem in with colissions in JavaFX.
First, I detect a collision between a line and a circle using the follow code:
if(line.getBoundsInParent().intersects(circle.getBoundsInParent())){
System.out.println("Collision!");
}
After this, i need catch the coordinate of collision, like the below figure:
How to catch this coordinate?
[]'s
View Replies
View Related
Mar 2, 2015
I have a shape, Polygon (javafx.scene.shape.Polygon) and want to test whether a point (javafx.geometry.point2D) is contained within the shape. (contains doesn't work)
I can change the polygon to any type, but I need to be able to create it using the 4 corners points and add it as a child to the Pane.
View Replies
View Related
Jan 27, 2015
I am trying to print a loop inside an array of a greater size than the loop itself. Like for example I have an array of size 7 but it has only 3 elements.
int[] array=new int[7]
array[0]=2;
array[1]=3;
array[2]=4;
now what I want to do is print these three numbers in a loop so that my array[3]=2;array[4]=3;array[5]=4 ...... till the last one. Also the array could be any size and not just 7.
View Replies
View Related
Jul 21, 2014
Given a Numbers instance, whose fields are arrays of all the built-in Java numeric types (int, long, float, double, big-decimal, etc), write a method to sort all the numbers into a master list, and then print out the numbers where the number of digits past the decimal point is equal to the index of the number in the master list.
Is there a function in Java that will give me just the numbers after the decimal? I tried Decimalformat but couldn't get it to work. Here is what I have so far; however, I think I might be on the wrong track.
public class Numbers
{
public static void main(String[] args) {
Byte bNum = new Byte((byte) -50);
Integer iNum = new Integer(168);
Long lNum = new Long(100000L);
Short sNum = new Short((short) 10000);
Float fNum = new Float(12.19f);
Double dNum = new Double(23.123);
BigDecimal bd = new BigDecimal("3.14159265358979323846");
[code]....
View Replies
View Related
Apr 26, 2015
I created this program to display a square root table. Problem is all of my output is too long. I would like to round the number to 4 spaces past the decimal. Here is my code:
public class MySqrt5_2 {
public static void main(String[] args) {
System.out.println("Number SquareRoot");
int[] table;
table = new int[21];
for (int counter = 0; counter < table.length; counter += 2) {
System.out.println(counter + " " + Math.sqrt(counter));
}
}
}
View Replies
View Related
Sep 19, 2014
Pretty much what im trying to accomplish, i need to write a program that figures out the distance between one point to another, using miles and feet..
Heres how it has to look: "The distance from my uncles house is ___ miles, or ____ feet."
I can get it to run if i add only whole miles..but when i try to add 8.5 miles, and compile, the program flips out..I know i need to use a double somewhere, but cant figure it out, here is my code..
import java.util.Scanner; //required for input
public class feetToMiles {
public static void main (String[] args){
//Create new scanner object called input
Scanner input = new Scanner (System.in); //allows for input
[Code] ....
View Replies
View Related
Mar 13, 2015
I need to modify the drawShape method to calculate the distance from the starting point (the diameter) of any shape regardless of how many sides I give it, but I have absolutely no clue where to begin with this. The ultimate goal of the program is to calculate the value of pi using the shape that is drawn.
Here is the code:
public class PiTurtle extends Turtle
{
private double mySize;
private int mySides;
private double diameter = 0;
final static double startX = 590.0;
final double startY;
public PiTurtle(int nSides)
[Code] .....
View Replies
View Related
Jan 23, 2014
If I have 0123.45 string and trying to get 12345 as result. I am trying regex like below.
String s="0123.45";
s = s.replaceAll("^0*([0-9]+).*", "$1");
It gave result 123 as leading zeros removed that is one of the things that I want. How do I achieve 12345?
View Replies
View Related