Constructs And Initializes A Point With Same Location As Specified Point Object
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
ADVERTISEMENT
May 6, 2014
The goal is to desplays circles (max of 30) of fixed radius = 20, with the rightmost circle drawn in blue and left most circle in red and the rest are in white. The center is determined by the location of the point where the mouse is pressed. the number of circles is equivalent to number of mouse has been pressed_ the circles will be drawn only when you push the "draw" button.
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.JPanel;
public class CirclePanel extends JPanel {
private final int WIDTH = 500, HEIGHT = 300;
private final int RDIUS = 20;
private final int MAX = 30;
[code]...
View Replies
View Related
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
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
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
Sep 19, 2014
I am new Java Programming and I am struggling to pass my Java class. How to perform Java but I am trying. For this particular assignment I supposed to:
* Change all variables' data types to double.
* Change the two prompts to request double values
* Change change the two calls to the nextInt() method to nextDouble().
This is the original assignment:
import java.util.Scanner;
public class ArithmeticDemo
{
public static void main(String[] args)
{
Scanner input= new Scanner(System.in);
int firstNumber;
int secondNumber;
int sum;
int difference;
int average;
[code]....
View Replies
View Related
Mar 19, 2015
I'm trying to call the grade.processFile method from the main method but I'm getting this Error below. I'll post my code which includes the main method and the class underneath the error message:
Exception in thread "main" java.lang.NullPointerException
at java.io.FileInputStream.<init>(FileInputStream.jav a:130)
at java.util.Scanner.<init>(Scanner.java:611)
at MyGrades.processFile(MyGrades.java:49)
at myGradesMain.main(myGradesMain.java:19)
import java.util.Scanner;
import java.io.*;
[code]...
View Replies
View Related
Jan 28, 2015
I want to read a text file from the starting point to end of the file.
BufferedReader read=new BufferedReader(new FileReader("C:/eGurkha/agent/sample/UptimeRecord.txt"));
String line=read.readLine();
while (line != null)
{
System.out.println("lines are :"+line)
line=read.readLine();
}
By using the above code I can read all the line from the file, But I want to read from the some starting point.
For example : I have a file with 100 lines, from that file I want to read lines from 53 upto end of the file.
View Replies
View Related
Sep 21, 2014
Develop the class “Account” to be used by a bank. The Account class should have a single instance variable “balance”. Remember that balance must be a floating point number. The required methods for the Account class are shown below.
The Account class “debit” method should return a Boolean and should not allow an overdraft. If a withdraw greater than the current balance is attempted, the function should immediately return “false” and do nothing else.
Develop a test class to thoroughly test all aspects of the Account class. DO NOT change the class name or instance variable name given or the required method names as detailed below.
Account
1 constructor with no parameters (default balance to 0)
1 constructor with a balance parameter
setBalance method
getBalance method
credit method
debit method
I have the test class done, I won't need to put that in till later. My main problem is I'm not sure how I'm going to be able to get debit and setBalance to work together with each other.
public class Account
{
protected double balance;
// Constructor to initialize balance
public Account( double amount ) {
balance = amount;
[Code] ....
You can see I'm stressed out by not reading over my code. I already have the "Debit" in use, just have to change it. Which I did.
View Replies
View Related