I am trying to write a small program that will calculate the gain and/or loss of the sale of stock. The program will ask the user for the number of shares, the purchase price and the selling price. I am pretty sure that the errors is coming from my calculations in the program.
import java.util.Scanner; public class investmentCalculator { public static void main (String[] args) { Scanner input = new Scanner(System.in); //User input for number of shares System.out.print("Enter the number of shares: "); double shares = input.nextDouble();
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.
Write a program OutCircle.java that declares and initializes three floating-point variables (r, x, y): the first variable represents the radius r of a circle centered at (0,0) and the second and third variables are the coordinates (x, y) of a point in the plane.Your program should print true if the point is outside the circle and false otherwise. Hint: A point is outside the circle when its distance to the center is greater than the radius.
I need to convert a .txt file to html text, where the first line is changed to have < h1 > < /h1 > around it and the rest is wrapped in < p > < /p > so for example I read a .txt file that says:
chapter 1
this is a sentence
it would output:
<h1>chapter 1</h1>
<p>this is a sentence</p>
here is what I have so far and I cannot get anything to output.
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!");
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.
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,
jTotal.setText(Double.toString(dTotal)); DecimalFormat myFormatter = new DecimalFormat("#####.#"); String output = myFormatter.format(dTotal); a visual aspect of it.
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');
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
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)
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)
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);
//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()
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...
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.
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");
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:
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
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)
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;
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.*;