Calculations On Text Box Inputs

Mar 7, 2014

I have made a simple form, it consists of 3 text box's textbox1, textbox2 and textbox3 as well as 1 button button1. What I want to be able to do is put numbers into textbox 1 and 2 and then show the multiplication of these numbers in textbox 3 when the button is pressed and I was wondering what is the standard way of reading these numbers from the text box and allowing us to do the conversion obviously in the textbox its a string and we need to convert to an int or double or whatever to be able to perform calculations on them then convert it back into a string to display in text box 3?

View Replies


ADVERTISEMENT

Adding Inputs To Table With Columns And Perform Calculations Later

Nov 22, 2014

I am trying to put together a small application in my spare time. Nothing major, but one thing I want it to do is accept a few inputs, and take those and add them to a table with columns for use later (printing, calculations, etc). I was originally looking at something like Jtable, but that looks just like an excel spreadsheet done Java, so not what I'm looking for.

I'm looking for something that's read-only, where I can insert data from input fields, and then perform calculations with the column data later.

View Replies View Related

Calculations Within A Set Method

Feb 13, 2015

I am almost done with the assignment, but I am having an issue with this step: "Create a field to hold the gallery commission. This field cannot be set from outside the class. it is computed as 20% of the price, and should be set whenever the price is set. Put the code to calculate and set the commission in the setPrice() method"

import java.util.Scanner;
public class PaintingHarness
{
public static void main(String[] args)
{
// put code here
// Created object so we can take input from the Scanner
Scanner input = new Scanner(System.in);
Painting myPainting = new Painting();

[code]....

View Replies View Related

Accessing Data For Calculations?

Feb 18, 2015

I've created a method to calculate the ratio of one vowel to another, but I was hoping to get some feedback on another way I could approach the problem. The first bit of code is to find the vowels and assign them to an array ( for me, it seemed the easier thing to do in order to easily access the data). In the other bit of code, I have a method with two arguments (the vowels) to calculate the ratio.

public void findVowels(StringBuilder message, String delimiter) {
subString = message.toString().toLowerCase().split(delimiter);
vowelCounter = new int[5][subString.length];
// Remove all whitespace
for (int index = 0; index < subString.length; index++) {
subString[index] = subString[index].replaceAll("s", "");

[code]....

View Replies View Related

Complex Number Calculations

Jan 25, 2014

A complex number is defined as z=a+i*b, where a is the real part, and b is the imaginary part. In other words, in order to define a complex number, we need the two floating numbers a and b. Write methods that perform for each of the following operations with complex numbers z1 = a1 + i*b1, and z2 = a2 + i*b2:

Addition: z1 + z2=(a1+a2) + i*(b1+b2)
Subtraction: z1 - z2=(a1-a2) + i*(b1-b2)
Multiplication: z1*z2 = (a1*a2 - b1*b2) + i*(a1*b2 + b1*a2)
Division: z1/z2 = (a1*a2 +b1*b2)/(a2^2 + b2^2) + i*(b1*a2 - a1*b2)/(a2^2 + b2^2)

Create a test program that asks for the real and imaginary parts of two complex numbers from the user, and displays the results of the four operations, writing the formula as shown above, and replacing the a1, a2, b1 and b2 with the numbers entered by the user.The professor used the incorrect complex number equations and has notified the students of his error. I have run into a few problems thus far.

1. I'm not sure how to use floating numbers with the Math.pow(double, double) function, since its requires doubles!? So instead of using floating numbers, I've knowingly switched them all to double in order to see if the code itself is working properly for the purposes of this forum. Is there a way that I can modify this function so that it will work for floating numbers?

2. Regarding the division method, an error stating that c and d have not been initialized and I'm not sure how to change it because the other calculation methods work fine. Why do I need to initialize c and d in the division method and not the others?

3. Am I on the right path? I have surfed the web to see how others completed the program and they all appear very different than mine...

package program5;
import java.util.Scanner;
public class Program5 {
  static double a, b, c, d;
static double i = Math.pow(-1,1/2);
 
[code]...

View Replies View Related

Program Returns 0 For All Calculations

May 28, 2014

this program works but returns zero for all the calculations. I checked everything there is no error but I dont know why is returning 0.

package mshproject3;
import java.util.StringTokenizer;
import javax.swing.JOptionPane;
public class HayloFactoryController {
public static void main(String[] args) {
String firstName = "";
String lastName = "";
String phoneNumber = "";
int aNbrOfVehicles = 0;
int aNbrOfFuelTanks = 0;
HayloFactory factory;

[code]....

View Replies View Related

Array In Class Calculations Out Of Bounds?

Mar 26, 2014

It seems that all of my arrays in the class Calculations are out of bounds, and I do not seem to know why.

Java Code:

/**
public class DataAnalyzer
{
public static void main (String[] args) {
//This creates an instance of ReadFiles
ReadFiles aReadFiles = new ReadFiles();
Calculations aCalculations = new Calculations();

[code]....

View Replies View Related

What Code To Manipulate Strings To Do Calculations

Dec 4, 2014

I have some data files that take this form:

D14
J3
N1
a26

[code]...

I also have this code that takes the file, goes through each line using a loop and counts the total of all the integers on each line, it also then loops and takes each integer on each line and divides it by the total calculated in the previous loop but I don't know what code to manipulate the strings to do these calculations. After these calculations I want to write the updated values to the text file I originally took the data in from. So as an example the total I already for this file to be '232' so the first line would be D 0.06 because 14/232 = 0.06034482758 and rounded to 2 decimal points is 0.06.

import java.io.File;
import java.io.FileReader;
import java.io.LineNumberReader;
import java.io.PrintWriter;
import java.util.Scanner;
public class Normalise {
private static Scanner scanner;
//private static PrintWriter out;

[code]....

View Replies View Related

Using Two Dimensional Arrays To Make Calculations

May 10, 2014

I am having problems figuring out how to make calculations using a two dimensional array. The problem is finding the distance of a projectile given the launch velocity and angle. The equation is x = v^2*sin(2theta)/g. I understand how to implement this equation using the toRadians() and Sin() methods. What I don't understand is how to calculate the distance values with a multi dimensional array.

double [][] data = { {20, 15},
{50, 35},
{80, 45},
{100, 65},
{150, 85},
{10, 50},
{110, 8}};

My array has the velocities on the left and angles on the right. I tried using nested loops but I don't know how to access the two pieces of data at a time which I need.

View Replies View Related

RMI With Doing Calculations Across A Server / Client Platform

Apr 6, 2014

It's an RMI program that has to be able to return the mean, mode and median of a set of numbers.It's composed of 4 classes; a client, an implementation class (with the math), an Interface, and a server class.

import java.rmi.NotBoundException;
import java.rmi.RMISecurityManager;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
import java.io.*;
 
[code]....

View Replies View Related

How To Perform Calculations Using Stacks Java

Nov 23, 2014

I am doing a calculator using stacks but when i try to calculate I getting the wrong data example stack contains 8 and user enter -3 stack should change to 5.

package comp10152.lab5;
import java.util.Scanner;
import java.util.Stack;

[Code].....

View Replies View Related

Lottery Odds Program - Using For And While Loops With Calculations

Oct 13, 2014

/**
* In this program, use for and while loops with calculations to get the lottery odds.
*/
import java.util.Scanner;
import java.util.Random;
public class Lottery
{
public static void main (String []args)

[Code] .....

I need getting my numbers matching. When, I run the program each time no matter what number it keeps saying sorry no matches. However, I do need the program to have matches.

View Replies View Related

2D Array Computation - Performing Certain Matrix Calculations

Apr 22, 2015

I've created several methods in another class to perform certain matrix calculations. Do I need to have mutator method in this calculation class to define the column length of the matrix object? I understand why the following code is not working, but I was hoping to get a quick and easy workaround. I'm not sure how to initialize the size of the column for newMatrix within the method.

public int [][] sum(int matrixOne[][], int matrixTwo[][]) {
int sumMatrix [][] = new int[matrixOne.length]["WHAT TO PUT HERE"];
for (int i = 0; i < matrixOne.length; i++) {
for (int j = 0; j < matrixOne[i].length; j++) {
sumMatrix[i][j] = matrixOne[i][j] + matrixTwo[i][j];
System.out.println("matrixSum" + sumMatrix[i][j]);
}
}
return sumMatrix;
}

Then I will use this method to print the new matrix:

public void printMatrix(int newMatrix [][]) {
for (int i = 0; i < newMatrix.length; i++) {
for (int j = 0; j < newMatrix[i].length; j++) {
System.out.print(newMatrix[i][j] + " ");
}
System.out.println("");
}
}

Is all of this overkill and should I just define all the methods within the same class to avoid these issues?

View Replies View Related

Generate Conditions To Perform Calculations On Whole Numbers?

Dec 12, 2014

I have to ask the user to enter 4 whole numbers, and then the program will calculate:

> x numbers are positive and even
> x numbers are positive and odd
> x numbers are negative and even
> x numbers are negative and odd

but I have trouble with the conditions. How do I form the conditions to calculate this? My professor said I can do this with only four IFs (or ELSE IF). This is what I did:

import java.util.Scanner;
public class Calc{
public static void main(String [] args){
Scanner sc = new Scanner(System.in);
 
int pe = 0, po = 0, ne = 0, no = 0;
/* four variables for each result
pe - positive even
po - positive odd
ne - negative even
no - negative odd

[Code[ ....

View Replies View Related

Grade Average Program - Hit Button Reseved For Calculations

Nov 23, 2014

I have written a simple grade average program. This is my code:

package programs;
 import java.util.Scanner;
 public class GradeAverage {
 public static void main(String[] args) {
 Scanner input = new Scanner(System.in);
int number;
int counter = 0;
int grade;
 
[Code] ....

Now the program is working just fine but what I don't like about it is the fact that you have to enter the number of grades before entering the grades. What I would prefer is to write your grades, hit some button that is reserved for calculating the average and then get the output.

View Replies View Related

Calculations / Conversions - Calculate Correct Amount Of Change Due To A Customer

Sep 12, 2014

Here are the instructions to my assignment:

A shopkeeper in Diagon Alley needs you to write a program that will calculate the correct amount of change due to a customer. (In Diagon Alley they use three coins with different values, given below).

1. Prompt the user to input the amount of sale in Galleons, Sickles, and Knuts.

2. Prompt the user to input the amount of money given by the customer in Galleons, Sickles, and Knuts.

3. Create constants that represent:

a. 1 Galleon = 17 Sickles

b. 1 Sickle = 29 Knuts

4. Perform the necessary calculations and conversions to compute the correct change in the least number of coins.

5. create a formatted receipt recording the entire transaction.

Here are what is steps 1 and 2 and 5 but problem with are 3 and 4. I need to create the constants and use proper conversions to give the right amount of change back.

Java Code:

import java.util.Scanner;
public class OperatorFormatting {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("Welcome to Flourish and Blotts");

[Code] ....

Basically, on steps 3 and 4 which are creating the constants and using the to make the proper conversions to give the customer the proper amount of change Due.

View Replies View Related

Simple Program Giving Negative Result For Amount Of Calculations Done

Mar 5, 2014

Why this extremely simple program seems to be giving me a negative value for amount of calculations done within one minute ( Just using it as a bit of fun to see how different computers in the office perform).

Java Code:

class Benchmark {
public static void main(String[] args) {
long endTime = System.currentTimeMillis() + 60000;
int count = 0;
for (int i = 0; System.currentTimeMillis() < endTime; i++) {
double x = Math.sqrt(System.currentTimeMillis());
count = i;
}
System.out.print(count + " calculations per minute");
}
} mh_sh_highlight_all('java');

I am getting results between -2.1billion and -3.4billion which to me would make sense since they are not the best computers in the world but I would be expecting a positive value?

View Replies View Related

PageRank In Naive Manner With Graph Nodes As Pages And Subsequent Calculations

Apr 15, 2014

Trying to implement PageRank in a naive manner with graph nodes as pages and subsequent calculations. Correcting the code.

import java.util.*;
import java.io.*;
class PageRank {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter no.of pages");
int n=sc.nextInt();

[Code] .....

View Replies View Related

Creating Simple Text Editor - Delete Selected Text Inside Text Area

May 13, 2015

This is the code that I wrote but I have two problem with two buttons one of them ... I want to delete the selected text inside the text Area which represented as b[8] and the other button that I want to select parts of the texts which represented as b[0]....

Here is the code..

package KOSAR2;
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;

[Code] .....

View Replies View Related

Displaying Inputs To TXT File?

Oct 13, 2014

so far this is what i have written. The program works correctly but I need to be able to have the numbers i am entering to show up on the .txt file.

import java.util.Scanner;
import java.io.*;
public class LargestAndSmallest {
public static void main(String[] args) throws IOException {
Scanner input = new Scanner(System.in);

[code].....

View Replies View Related

Modifying Files Using Inputs From GUI

Feb 25, 2015

I want to work on a project in which I have a GUI where I can choose certain variables from drop down menus. I want to use these variables to modify a few configuration files. I have looked upon internet for a few methods which can be used for the same. However, I am not sure about the method I should use. The files I want to modify consist of 10 -15 lines.

View Replies View Related

Using User Inputs In Other Class?

Feb 8, 2014

I have a LoginScreen class and one other class in my project. I want use user inputs (Username And Password) on other class if users details is true. I am stcuk at this point because when user attempt to Login connection is succesfully and other frame is coming to screen but i can reach user details anymore. Let me explain with codes;

LoginScreen class

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package deneme3;
import java.sql.Connection;

[code]....

You can see Button Action in MainProgramWindow " System.out.println( ??? );" How i can retrieve users inputs from this class ?

View Replies View Related

Multiple Key Inputs Not Working

Sep 16, 2014

i am currently making a game in java and currently i am working on the basic mechanics. most of it is working fine but i cannot seem to make it so when the user presses and movment key and space to fire a bullet the bullet fires in the direction they are moving. here is the code i have for movement.

public void keyPressed(KeyEvent e) {
// TODO Auto-generated method stub
int bulletx = Player.x + 100;
int bullety = Player.y + 20;
int key = e.getKeyCode();
if( key == e.VK_W){
p.moveUp();
}
if(key == e.VK_S){
p.moveDown();

[code]....

View Replies View Related

Sudoku Is Not Working For Few Inputs

Apr 22, 2015

The thing my coding for sudoku is not working for few inputs... it works fine with all its value initially at 0, but when i place numbers more than 4 at random places it stops responding (it doesn't show any value). My assignment is to get a solved sudoku for these values:

//Sample Input:
{0,2,7,3,8,0,0,1,0},
{0,1,0,0,0,6,7,3,5},
{0,0,0,0,0,0,0,2,9},
{3,0,5,6,9,2,0,8,0},
{0,0,0,0,0,0,0,0,0},
{0,6,0,1,7,4,5,0,3},
{6,4,0,0,0,0,0,0,0},
{9,5,1,8,0,0,0,7,0},
{0,8,0,0,6,5,3,4,0}

My current code

public class Sudoku {
static int userGrid[][]=new int[][]
{{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0}};//[horizontal][vertical]
static int grid[][]=new int[9][9];//the grid that the program experiments on

[Code] .....

View Replies View Related

Exceptions For Multiple Inputs

Oct 29, 2014

I'm writing a program that accepts three doubles from the user, and performs calculations on them. I want to be able to handle input mismatch exceptions on each individually (i.e., if the user enters a double for the first, then a letter for the second, I'd like to be able to keep the value entered for the first, and only require that the user try again with the second, then the third, etc.)... I tried putting each input instance into its own try/catch blocks, but it always goes back to #1 when an invalid input is entered. Right now, I have all three in one try/catch:

Java Code:

package com.itse2317;
import java.util.Scanner;
import java.util.InputMismatchException;
class Triangle
{
public static double side1 = 0.0, side2 = 0.0, side3 = 0.0;

[code]...

View Replies View Related

LWJGL Keyboard Inputs Not Recognized

May 10, 2014

I wanted to create a simple window with the LWJGL and a key input request which closes the window.I also wanted to create the classes in seperated packages, so it's more organized.The window displays but if I press that certain key nothing happens.Here is the Main class:

package bb.main;
import bb.input.Input;
import bb.main.render.SimpleRenderer;
public class Main {
public static void main(String[] args){
SimpleRenderer createWindow = new SimpleRenderer();
Inputinput= new Input();

[code]....

View Replies View Related







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