Write A Small Program That Will Calculate Gain / Loss Of Sale Of Stock

Jan 24, 2014

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();
 
[code]....

View Replies


ADVERTISEMENT

Stock Program - Stop User From Entering In Textfield And Display Message When Stock Is Low

Jun 29, 2014

I'm trying to make a stock program that stops the user from entering in textfield and displays a message when stock is low. There's just 2 problem the entered value by the user is only decremented twice then the total stock resets for example with SofaTotal and the if statement doesn't work:

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
import java.text.DecimalFormat;
import java.util.Arrays;

[Code] .....

View Replies View Related

How To Calculate And Display Win / Loss For Two Different Teams Using Boolean Function And Arrays

Jan 28, 2015

I am still new to Java and have an assignment that I am stuck on. I believe I got the boolean function correct, however I cannot figure out what to write in the main function. I have exhausted searching, and trying different loops, arrays, etc.

View Replies View Related

Point Of Sale Program Using HTML

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

Calculate Person Calories Burned Per Minute - Possible Loss Of Precision Error

Feb 2, 2015

I was asked to write code to calculate a person's calories burned/min. This is what I got. The problem is I keep getting an error.

--------------------Configuration: <Default>--------------------
C:Program FilesJavajdk1.7.0_72CaloriesBurned.java:22: error: possible loss of precision
caloriesBurnedPerMinute = 0.0175 * METS * weightInKg;
^
required: int
found: double
1 error

Loss of precision? What does that mean? Do I have to change weightInKg into some other number type?

import java.util.Scanner;
public class CaloriesBurned
{
public static void main(String[] args)
{
Scanner keyboard = new Scanner(System.in);
int runningHours, basketballHours, sleepingHours, METS, caloriesBurnedPerMinute;

[Code] ....

View Replies View Related

Write A Program Using Loop And Break To Calculate Value Of Pi

Oct 5, 2014

having some trouble doing this. Here are the requirements:

1)Write a program using loop and break to calculate the value of PI.
2)You can use the following equation to calculate PI. PI=4/1-4/3+4/5-4/7+4/9-4/11+4/13 etc.. The program shouldn't loop until the criteria is satisfied.
3)The criteria is the value of PI you get is very close to the “real” value (3.1415926), meaning that their difference
should be smaller than a very small numeric number, e.g., 0.0001).
4)The control structures you may need for this program are loop, if-else, and unlabeled break.
5)The output should have the format: for each iteration, it has iteration number and the corresponding value of PI until that
iteration. The last line would be the final value of PI.

Here is my code so far:

package ids;
public class IDS {
public static void main(String[] args) {
double pi = 0;
for(int i=1; i<=100000; i++){
if ((i%2)==0){
pi+=(4/(2*i-1));

[code]...

View Replies View Related

Write A Program That Will Call A Method To Calculate Function

Dec 3, 2014

I have understood my programming class up to this point and now I have been given a lab that I can't figure out for the life of me. Here what I have to do: Write a program that will call a method (called f) to calculate the following function" f(x)=(x^2)-16...this is what the output should be:

x f(x)
1 -15
2 -12
3 -7
4 0
5 9
6 20
7 33
8 48
9 65
10 84

I guess it also has to print this output in a table even though my professor never mentioned it. Usually

public class Lab12 {
public static int f(int x)
{
return x*x-16;

[code]....

View Replies View Related

Write A Program To Calculate Telephone Charges For Four Customers

Apr 13, 2014

Write a program to calculate the telephone charges for four customers. The data for each customer consists of NAME, PREVIOUS METER READING, PRESENT METER READING. The difference between the two readings gives the number of units used by the customer for the period under consideration.

The amount due for each customer is calculated by: UNITS USED * RATE PER UNIT + RENTAL CHARGE The rate per unit and rental charge is assumed to be the same for all customers and must be input once only.

Your program must:

a. Input the rate and rental charge
b. Read the data for each customer and calculate the amount due
c. Print the information under suitable headings
d. Calculate and print the total amount due to the telephone company

************************************
java.jpg
************************************

I just need the totalX in my for loop to print the total but the total i want to print it is in the while loop

View Replies View Related

2D Boolean Array - Gain A Value When All Elements Have Been Turned True

Feb 2, 2014

I'm creating a 4x4 2D array. I need to be notified, or gain a value when all elements have been turned true. Is this as simple as

"If the2DArray[] = true { blah blah }" ?

View Replies View Related

Swing/AWT/SWT :: Set A Column In A JTable To Make It Unable To Gain Focus?

Jun 29, 2007

How would you set a column in a JTable to make it unable to gain focus i.e. select the next column on the same row or ignore the command completely when selecting a column that should not be able to be gained focus on?

View Replies View Related

Error - Possible Loss Of Precision

Feb 10, 2015

I'm stuck trying to figure out why this isn't compiling.

Bumper.java:87: error: possible loss of precision
myX = (Math.random()* (rightEdge-myXWidth) + myXWidth / 2);
^
required: int
found: double
Bumper.java:88: error: possible loss of precision
myY = (Math.random()* (bottomEdge-myYWidth) + myYWidth / 2);
^
required: int
found: double

View Replies View Related

Small Chat Lobby

Feb 4, 2014

Me and my brother are working on a small java project to learn network programming and get some experience working with networking code. We decided to make a relatively simple client/server program where clients get into a simple chat lobby and can invite others to play small games(like pong). The basic server code has been written, and we have made a special client that is used for debugging.

We use a self-defined protocol of Strings where a message looks like "4-|user,pass". The number before the delimiter "-|" is the operation code, that tells the server what kind of message this client sends. Based on that number, the server dispatches the message to the appropriate handler method. 4 is authentication for example, and the handler looks the user and pass up in a file and if found, returns true, otherwise, false. Then the server responds to the clinet with 2-|"any message" where the client will recognize opcode 2 as a "authentication accepted" and proceed with the next part of client code. In a similar way, we plan to write all message types(both in the game, in the lobby and in a game setup room).

While testing we ran into a problem where the BufferedReader .readLine() does not seem to be a blocking call like it should be, so the client keeps spamming 'null' in the output field that we made to see the server response to the message we send. When we try to debug the server code and set breakpoints at the suspicious locations, it strangely skips both while(true) loops without activating either breakpoint and executes the finally{} code, even though the client did not close the connection and the second while loop was never entered. The first while loop IS entered though, because the test client gets a "0" on its output, which is the server message indicating "please authenticate yourself".

Also, if we approach things in a dumb way that can be done way more efficiently or easier to read/manage, please do tell. Keep in mind we are beginners though! We decided to use messages in a string format and decode it at both sides as it seemed easier than transmitting java objects and making sure they are of the same type, also for reducing overhead as much of possible. URL....

The server code:

package Chatroom;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.HashSet;

/**
* This is the main server class. It is the core of the server functionality, and the listener for incoming clients that will spawn threads to deal with clients, track their information, change their states and ultimately, clean up after all clients by keeping the data structures up to date.

[code]...

View Replies View Related

Small Text Editor

Jun 23, 2014

I'm having a problem with a small text editor I'm trying to create. I have implemented a panel of labels, containing line numbers, on the left of a scrollable text area. The panel is designed to size such that it fits the larger numbers whenever they appear. It does that very well, actually, until either one of the scrollbars appear. As soon as one does appear, it immediately shrinks in width. The horizontal scrollbar even blocks the view a little, making it impossible to see what you are writing on the very last line.

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Main implements KeyListener {
public static JPanel tab = new JPanel(false);
public static JTextArea text = new JTextArea();
public static JScrollPane scroll, reflex;
public static JPanel lines;

[code]...

Explanation of the code: There is a main panel which embodies a text area and another container filled with labels of line numbers.Both the text area and line number panel have scroll panels attached. They are synchronized, in order to scroll at the same time.

The main class contains a static function "position" which generates a GridBagConstraints, created for the convenience of single-line creation of constraints.It also implements the KeyListener interface, and waits for change in the amount of lines inside the text area. Afterwards, it changes the panel of labels accordingly.

View Replies View Related

Array Index - Possible Loss Of Precision

Feb 5, 2015

public class Access
{
public static void main(String args[])
{
long a=2;
int j[]=new int[a];
}
}

Code shows error as "possible loss of precision" as am working with long type.but need to have my array size as 10^10 or some other logic?

View Replies View Related

Building A Small Text Based RPG

Dec 18, 2014

i'm totally new to Java.I'm making a small text based RPG and this is what i've come up for now.

Java Code:

import java.util.Scanner;
class Main {
public static void main(String args[]){
Scanner input = new Scanner(System.in);
Player playerObject = new Player();

[code]....

My thing is that i want the user to enter 'Caucasian' or another race in the console below and i want it to be saved in a variable or something else in the Player Class that i can later use it in texts or something else. My question is how can i do it?

I tried like 'int Mongoloid = 1; int Caucasian = 2;'

And the same with the others, and after that i tried to use them with the Switch Statement but it did not work.

View Replies View Related

Stock System In Java

Jan 6, 2015

I'm making a stock system for the heck of it,so everything was going great until I hit the loop I am trying to use a for loop to add stock to the stock system,any way the question is maily about loops.How come I cannot declare a variable outside a loop and assign a value to it,for example I can declare as follows and I will not get an error,

for(int i=0;i<10;i++){
System.out.println("example");

}

but in my code(and yes its the only error I get I tested it) I get an error and can only declare and assign a value inside the loop,the reason for this is because I wanted to get the value from another class and use it in the loop ok so heres the code from both classes.

public class mainn{

public static void main(String [] args){
stock first = new stock();
int internal;
internal = first.wanted;

[code]....

View Replies View Related

Map That Shows The Stock Of Some Company

Dec 16, 2014

Is there anyway i could clean this up. ??

package map;
import java.io.*;
import java.util.*;
public class Map {
public static void main(String[]args)throws Exception{

[Code] .....

View Replies View Related

Java MultiThreading Stock

Feb 13, 2014

I am doing a multi threading program . I am unable to get the output i want. I have no compilation error . But I cant get the result I , Null exception. This is my Test program

import java.util.*;
public class Test
{
public static void main (String[]args){
int totalShares = 0 ;
double totalCost = 0.0;
String name = "FCS";
double profit = 0.0;

[code]....

View Replies View Related

Servlets :: Intermittent Loss Of Some Session Attributes

May 21, 2014

Session attributes after logging into web-app:

Session Attributes
thisUsersAllowedRoles=45
username=hw
authenticatedUser=org.hw.client.payroll.model.User@2c8a09da
supervisorCode=
authenticated=true

[Code] ....

Every now and then while debugging I lose session attributes:

Session Attributes
thisUsersAllowedRoles=45
username=hw
supervisorCode=
authenticated=true

[Code] ....

The authenticatedUser and menu attributes are gone. I never know when it's going to happen so I can't trace it. Any guesses why those type session objects would die?

I attached an image of what menu object looks like.

View Replies View Related

Loss Of Data In ArrayList When Paint Is Called

May 23, 2014

Java Code:

public void draw(ArrayList<int[]> good,ArrayList<int[]> bad){
drawing = true;
goodToDraw=good;
badToDraw=bad;
System.out.println("Canvase/draw: Calling paint with a size of "+goodToDraw.size());
middleMan();

[code]....

What this does is two ArrayList are sent to the draw function.one called good and the other bad. Right now I am only working on good. What is suppose to happen is paint takes all the good coordinates and paints them but I seem to loose the arrayList size when repaint is called. You can see in the picture below of my console that it starts of with 20. Then because I was wondering if the scope was to short i called middleman to make sure that it held its size outside of the first function. Then finally it calls paint and tells me the array is empty. To simplefy..Why does my arraylist size go to zero when I call repaint?

View Replies View Related

How Does Program Know To Calculate For Only One Year

Mar 26, 2015

how does the program know to calculate for only one year?

public class Interest2 {
public static void main(String[] args) {
double principal; // The value of the investment.
double rate; // The annual interest rate.
double interest; // The interest earned during the year.

[code]....

View Replies View Related

Stock Database Query Class

Dec 14, 2014

I have a Stock Database query class, it compiles and runs well. Thing is when i enter a user, it shows a user stock information but it repeats showing the same user in the command prompt. the repetition is so fast, you can't see the information. All i wanted was the application to show a user's info, then asks you to enter another user again and so forth. Here is the code

import java.io.*;
import java.sql.*;
import java.util.*;
public class StockDatabaseQuery {
public static void main(String[] args)throws Exception {
String userID;
String firstName;

[Code] ....

View Replies View Related

Stuck On Porting Small Segment Of JavaScript To Java

Mar 3, 2014

I'm fairly good at Java, but somewhat at a loss when the some of the JavaScript below is mentioned. I've attempted to port the below code, but I'm finding it somewhat difficult.

Parts of JavaScript I'm stuck at porting:

1. I'm stuck on the return statement on the 3rd line.

2. Similarly the lines utilizing "charCodeAt", as I keep getting error "Cannot invoke charCodeAt(int) on the primitive type char"

3. Also on the second to last line, I keep getting the error "Cannot invoke padLZ(int) on the primitive type int".

Link to original javascript

Convert between Latitude/Longitude & OS National Grid Reference points

Original JavaScript

Java Code:

OsGridRef.prototype.toString = function(digits) {
digits = (typeof digits == 'undefined') ? 10 : digits;
e = this.easting, n = this.northing;
if (e==NaN || n==NaN) return '??';
// get the 100km-grid indices
var e100k = Math.floor(e/100000), n100k = Math.floor(n/100000);

[Code] ....

View Replies View Related

Create A Program That Will Calculate Different Tax Brackets

Oct 3, 2014

I have spent the past 12 hours on it and have gotten no where. I need to create a program that will calculate different tax brackets. I have tried all combinations I can think of and can't get it to work!!! I am literally about to go insane! I need the program to calculate tax will be 1% for anything up to $50000. If the tax is over $50000, you keep that 1% of $50000 and then add the remaining. So for an income in the second range, it would be 1% of $50000, and then 2% of (income - $50000). This then continues for each range.

The problem I'm having is getting it to display the correct interest rates. I am not asking for you to write it for me. I want to learn. But at this point I have exhausted all resources available to me.

import java.util.Scanner;
public class Project3taxinfo {
public static void main(String[] args) {
final double RATE1 = 0.01; //1% tax on the first $50,000
final double RATE2 = 0.02; //2% tax on the amount over $50,000 up to $75,000
final double RATE3 = 0.03; //3% tax on the amount over $75,000 up to $100,000
final double RATE4 = 0.04; //4% tax on the amount over $100,000 up to $250,000
final double RATE5 = 0.05; //5% tax on the amount over $250,000 up to $500,000
final double RATE6 = 0.06; //6% tax on the amount over $500,000

[code]....

View Replies View Related

Program To Calculate Area Of Circle

Mar 11, 2015

I'm starting with my version of very basic program: calculating area of circle. And of course it doesn't get well. My question: what is wrong in this code?

public class circleAre{
double radious;
void putData(double radi){
radi = radious;

[Code] .....

View Replies View Related

Cannot Get Average Program To Calculate Properly

May 9, 2010

I am having a problem with my program. I can't get my program to calculate properly. Everything compiles and run but its just giving me a wrong answer. I am suposse to get 115.50 but instead I am getting .30...

order.java
public class Order
{
double salesTaxRate; //initializing a variable for the sales tax rate.
double subTotal; //initializing a varliable for the sub total.
double shippingCost; //initializing a variable for shipping cost.
double salesTax; //initializing a variable for sales tax.
double totalCost; // initializing a variable for totale cost.

[Code] ....

View Replies View Related







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