Calculator That Change Input Value Into Another Value

Nov 14, 2014

I am currently working on a small java programm. I use netbeans for it. And obviously I am new to java.

Basically its a calculator that change the input value into another value: like 10 € into whatever $ and same with Inch and Centimeters.

Therefore I need a second jDialog Form where i can change the factors for the calculator and start the calculator again.

Here is my problem: I can open the second Dialog but if I want to change the factor it doesn't change the value in the variable and the second calculator frame is with the old factors. It seems the double variable isn't working globally

I will add the files later when i find out how?

View Replies


ADVERTISEMENT

Why Cannot Change Size Of TextField In Java For Calculator Application

Jan 13, 2014

package name;swing library found in javax called to use the graphical contents.

import javax.swing.*;
//creating the contents for the calculator
public class calc {
JButton btn1= new JButton("1 ");
JButton btn2= new JButton("2");
JButton btn3= new JButton("3");

[code]....

I have tried different sizes for the 'TextField' but when I change the size, the position changes instead of the size itself.

View Replies View Related

Expression Calculator - Input Mismatch Exception

Nov 2, 2014

import java.util.*;
public class CalculatorProjectVincent {
public static void main(String[] args) {
System.out.println("Welcome to this incredibly uneeded and redundant calculator program!");

breaker();
Scanner kb = new Scanner(System.in);
System.out.print("Enter an expression or EXIT to end the program. > ");

[Code] ....

When I run the program and input "v 100", it gives me the following:

----jGRASP exec: java CalculatorProjectVincent

Welcome to this incredibly uneeded and redundant calculator program!
- - - - - - - - - -
Enter an expression or EXIT to end the program. > v 100
Exception in thread "main" java.util.InputMismatchException
at java.util.Scanner.throwFor(Scanner.java:909)
at java.util.Scanner.next(Scanner.java:1530)

[Code] ............

View Replies View Related

Area Calculator - How To Move All Input / Output To Main

Nov 11, 2014

I am stuck on one of the projects: Area Calculator

I am able to code an area calc that works, but am unsure how to move all the input/output to main like the project wants. here is a piece of my code so far:

public static void main( String[] args )
{
Scanner kb = new Scanner(System.in);
int base = 0, height = 0, width = 0, radius = 0, choice;
System.out.println( "-=-=-=-=-=-=-=-=-=-=-" );
System.out.println( "1. Triangle" );
System.out.println( "2. Rectangle" );
System.out.println( "3. Square" );
System.out.println( "4. Circle" );
System.out.print( "Pick a shape: " );

[Code] ....

I have the same thing for rectangle, square, and circle (of course with the correct formulas) and the program works perfect, but the assignment is still wrong until I can move the input/output to main. what do I do?

View Replies View Related

Cannot Change Textfield Input

Jun 29, 2014

When in panel2 i type something in the search bar and then i move mouse cursor to panel1 and try to edit a JTextField input for example as in the picture 0.0 nothing happens but the mouse cursor is correctly show up in the JTextField.. What seems to solve the problem is to click anywhere outside of the application window.. but of course this is not a solution !

View Replies View Related

Change Input String To Array Of Characters

Dec 11, 2014

I am trying to change an input String to an array of characters, but it only stores the word before the space into the array. Here is the code:

Scanner scanner = new Scanner(System.in);
System.out.println(" Enter text: " );
String text = scanner.next();
char[] characterArray = text.toCharArray(); // convert string to array of characters
String char = "";
for( i = 0; i < characterArray.length; i++) {
char = char + characterArray[i]
} System.out.println(char);

Just typing hello gives me hello, but when I type hello world it does not type in the word "world".I am trying to change an input String to an array of characters, but it only stores the word before the space into the array.Here is the code:

Scanner scanner = new Scanner(System.in);
System.out.println(" Enter text: " );
String text = scanner.next();
char[] characterArray = text.toCharArray(); // convert string to array of characters
String char = "";
for( i = 0; i < characterArray.length; i++) {
char = char + characterArray[i]
} System.out.println(char);

Just typing hello gives me hello, but when I type hello world it does not type in the word "world".

View Replies View Related

How To Change Value In Array Through User Input And Print Out Result

Dec 14, 2014

I have to do a small program about parking. In the 2-d array (parking lot), contains different kinds of cars, the user have to :

1)enter which car he wanna move,
2)what direction (w,a,s,d) and after that,
3) how many moves( not out of bound) he wants to make, and finally
4) we print out the new parking lot for his next move

And i am stuck at how to move the car to corresponding position and then prompt user for the next move?

For example:

I want to move A to the right by 1 (d)

擷取.PNG
print result:
擷取1.PNG

How do I do that? The code that i have right now

public class CarParkGame {
public static void main( String [] args) {
  String carPark[][] = new String [6][6] ;
carPark[0] = new String[] {"A","A","A","0","0","0"};
carPark[1] = new String[] {"b","0","0","0","0","c"};
carPark[2] = new String[] {"b","X","X","0","0","c","<exit>"};

[Code] .....

View Replies View Related

Directly Change Java Code Using User Input

Nov 16, 2014

I'm quite new to java programming, but eager to learn. I was wondering how to change actual java code, using user input. For example:

Java Code: int x = 0;
// Start the program and enter 3
// Now the code is
int x = 3 mh_sh_highlight_all('java');

View Replies View Related

Swing/AWT/SWT :: How To Change Button Text And Actions In Input Dialog Box

Oct 20, 2014

I'd like to change the text on the two buttons which I have in my Dialog Box, how should I do this?

Also, when I click the X Button in the top right of the Dialog Box, nothing happens, and the program only stops when I end it in jGrasp. How do I make this button close the program when clicked on?

import javax.swing.*;
import java.util.Random;
public class SwingInputExample {
public static void main(String args[]) {

[Code] .....

View Replies View Related

Generate QR Code From Input Text And Display Information About Input / Output Bits

Nov 12, 2014

I am trying to write a program that will generate a QR Code from an input text and also display some information about the input/output bits. So far I have created the frame and what to do next. And I'm not sure if I am on the right track since my level of programming is not that great. By the way, I am using zxing libraries from GitHub. I know, there are plenty of generators online for the QR Code, but that is not what I am looking for. As you can see on the attached image, I am more interested in the efficiency of encoding 2D data. Also, I noticed that almost all the online projects regarding 2D codes are for Android. Which is not very useful.

// QR Code Generator
package qrcode;
import javax.swing.JFrame;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.border.EtchedBorder;
import javax.swing.border.TitledBorder;

[Code]....

View Replies View Related

Create Program That Prompts Input And Creates File With That Input As Name

Jul 14, 2014

So I was going to try to create a program that prompts input and creates a file (That didn't exist before) with that input as name.Then, the program prompts inputs after stating questions such as 1 + 1, then if the user inputs an answer, put "Question # = Correct "or" Wrong.Code SO Far:

Java Code:

import java.io.BufferedReader;
import java.io.File;
import java.io.InputStreamReader;
public class File_Read {
public File_Read() {//File_Read is the Interactive object

[code]....

So that it puts the Correct or Wrong into the file.

View Replies View Related

Tip Calculator For Fun

Oct 18, 2014

So, I'm working on a Tip Calculator for fun. I have everything worked out for the most part. The feature I am trying to add is to give the user the amount of change they'll get back from their transaction. I do not ask the user any information other than what is their bill.

Please enter your bill total : 5.50
Please enter your name : some name
Total : 5.50
Tax : 0.48 -- Based off a tax rate of 8.75%
Total with Tax : 5.98 --
20 percent Tip : 1.10
Total with Tax and 20 percent Tip : 7.08
Total change : <-- I believe this will be about $2.92

I want the total bill to round to the nearest $10 value (e.g. for $5.50, calculate bill to $10. For $13.00, calculate bill to the $20.00, and so on... This way I get an accurate amount of change to give back to the user.

View Replies View Related

MVC Calculator - How To Get It To Actually Calculate

Sep 28, 2014

I made a MVC calculator. I was wondering if you could take a look at my design and if I was on track. I am still working on getting it to actually calculate something. All the buttons respond and print text on the JTextField but it is not calculating.

package calculator.MVC;
import javax.swing.JButton;
import javax.swing.JTextField;
public class CalculatorModel {
private int sum;
private int number;
private char opt;

[code]....

View Replies View Related

Calculator Only Return 0.0?

Sep 2, 2014

I am making a calculator in Java. However, when I press the "=" button on my calculator, it always returns 0.0, no matter what. I don't understand why? The code is below:

import javax.swing.*;//import the packages needed for gui
import java.awt.*;
import java.awt.event.*;
import java.util.Arrays;
import java.util.List;
import static java.lang.Math.*;
public class CalculatorCopy {

[Code] ....

View Replies View Related

How To Add Loop In Calculator

Mar 11, 2015

import javax.swing.*;
public class BasicCalculator{
public static void main (String[] args) {
String output="";
double n1,n2;
String operation;
operation= JOptionPane.showInputDialog("Please enter your operation");

[Code] ....

How to add a loop in this problem:

View Replies View Related

While Loop Pay Calculator

Dec 2, 2014

I have the basic workings of this program just doing all the printing at the end is throwing me off. Anyway here are some of the requirements and my code:

1. Allow the user to input an individual's hours worked.
2. Accumulate the total regular hours worked, the overtime hours worked, the amount of the regular pay, the amount of overtime pay, and the total payroll, for all of the employees entered.
3. Allow the user to enter a zero (0) as the Boolean expression to end the loop.
4. When the loop ends print out all of the accumulated totals with appropriate labels, each on a separate line.

import java.util.Scanner;
public class WhileLoopPayCalc
{
public static void main(String [] args)
{
final double REGULAR_HOURS = 40f;
final double HOURLY_WAGE = 12.5f;
final double OVERTIME = 1.5f;

[code]....

View Replies View Related

Calculation In Awt Calculator

Jul 10, 2014

I am facing problem during calculation in my awt calculator. It is showing NumberFormatException. Below is part of code.

if(e.getSource()==b14)//On button 14, label is "/"
{
String v1=tf.getText().toString();
num1=num1+Integer.parseInt(v1);//num1 is as integer variable
tf.setText("");//tf means textField
}else

[code]....

View Replies View Related

Calculator In Java

Oct 28, 2014

I can not this to work correctly.

public static void main(String[] args) {
FloatWrapper x1=new FloatWrapper(0);
FloatWrapper x2=new FloatWrapper(0);
do{
switch(menu()){
case 'a': if(dataInput(x1,x2)) add(x1,x2); break;
case 'b': if(dataInput(x1,x2)) subtract(x1,x2); break;

[code]....

View Replies View Related

Trying To Create A Calculator

Sep 16, 2014

I'm new to java and have been coding for a few hours. I tried to create a calculator (Which has no GUI, just text inputs)which will let you select how to process the two integer (Add, minus, times etc.) I cant seem to get it to work. I will put in the process way such as times and have entered two integers and every time it doesn't work. Here is my code:

import java.util.*;
public class Calculator
{
public static void main (String args[])
{
int input1 = 0;
int input2 = 0;
int answer = 0;

[code]....

View Replies View Related

Create A Calculator With JCreator

May 24, 2010

I have got a problem when coding a java program to create a calculator with JCreator. How to write codes for decimal point.

Decimal point should not be set to the text more than 1 time until an operator is pressed. How can I use a Boolean value to solve this problem.

View Replies View Related

PostFix Calculator Project?

Apr 2, 2015

So I am working on a PostFix calculator that is used in command line for a class project, and I am having a little trouble on developing a memory for it. I have been told to create a hashMap and I have researched it and understand the basics of it. I have the calculating method working, but what I am having trouble trying to implement a way for the user to declare variables. For example this what the user should be able to do:

> a = 3 5 + 1 -
7
> bee = a 3 *
21
> a bee +
28

[code]....

I just need to be able to save the answers as a variable the User names, such as the example and let the user be able to use the variables later.

View Replies View Related

Random Number Calculator

Feb 1, 2015

the program basically has a random number generating, and I want to ask the user to try to guess the number, and keep guessing until the number is right. In addition to this, I need to put in extra conditions for too high or too low by 10. So for example, if they user guesses a number and its off by more than 10, then it prints that they guessed too high, and if its below 10 they guessed too low.

import java.util.*;
public class RandomNum
{
public static void main(String[] args)
{

Scanner scan = new Scanner(System.in);

[code].....

Modify the program to keep the user trying to guess the number till he/she gets it right, and stop once you guess the right number.Too high, high, too low, too low( If it's off by more than 10 = way too high, if its less than 10, way too low)

View Replies View Related

Basic Calculator Functions

Jul 2, 2014

my task is to add a few functions to an example calculator. I managed to add a divide button but I simply can't figure out how to add a working Pi and reciprocal function.

package newjavaproject;
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
public class CalculateurNC extends Applet {

[code]....

View Replies View Related

How To Make Calculator Using Stacks

Feb 5, 2014

I got to make a java code for my class. I must make a calculator using stacks. I have a code but i got some mistakes. Here is the code

Java Code:

package stackscalc;
import java.util.Scanner;
import java.util.Stack;
import java.util.EmptyStackException;
class Arithmetic {
int length;
Stack stk;
String exp,

[Code] .....

View Replies View Related

Else Without If Error - Simple Calculator Using JOP

Oct 8, 2014

import javax.swing.JOptionPane;
public class Calculator {
public static void main ( String args[] ) {
double n1 = Double.parseDouble(JOptionPane.showInputDialog(" Enter first number: "));
double n2 = Double.parseDouble(JOptionPane.showInputDialog(" Enter second number: "));
String x = JOptionPane.showInputDialog("Enter operator: ");
double result;

[code].....

Write a program that mimics a calculator. The program will need to accept as input two numeric double values, and accept the operation to be performed as the third input. The operation to be performed will be input in the form of the character representing the java operator for the operation to be performed (i.e + for addition, - for subtraction, * for multiplication, / for division, or % for modulus). Once the program has read these 3 inputs it should output the numbers, the operator, and the result. (For division, if the denominator is zero, the program will output an appropriate message (i.e division by zero is an invalid operation). Please use the JOptionPane class for both accepting the required inputs and for the required output demonstrated below.Some sample output may look as follows:

3 + 4 = 7
13 * 5 = 65
10 / 3 = 3.33333333

Error Messages:
3 errors found:
File: /Users/gcaruso/Documents/CISS 110/Module 3/Module 4/Calculator.java [line: 23]
Error: /Users/gcaruso/Documents/CISS 110/Module 3/Module 4/Calculator.java:23: 'else' without 'if'
File: /Users/gcaruso/Documents/CISS 110/Module 3/Module 4/Calculator.java [line: 31]
Error: /Users/gcaruso/Documents/CISS 110/Module 3/Module 4/Calculator.java:31: 'else' without 'if'
File: /Users/gcaruso/Documents/CISS 110/Module 3/Module 4/Calculator.java [line: 37]
Error: /Users/gcaruso/Documents/CISS 110/Module 3/Module 4/Calculator.java:37: 'else' without 'if

View Replies View Related

Make A Calculator Using Java GUI

Jul 29, 2014

I am trying to make a calculator using Java GUI. I've managed to make an ActionListener and add it to a button, but I've made an error in my code that I'm unsure of how to solve. Because of how I've written the code, only one number can be placed in the text field. For example, the an ActionListener for the three button on the calculator was added to the button, but no matter how many times the user presses the button, only one 3 will appear in the text field. The code is below:

import javax.swing.*;//import the packages needed for gui
import java.awt.*;
import java.awt.event.*;
public class Calculator {
public static void main(String[] args) {
JFrame window = new JFrame("Window");//makes a JFrame
window.setSize(300,350);

[code].....

As you can see, because the compiler forces the String variable to be final, so when the user presses the button, the code simply shows how a space character and three character would look like, because the String variable can't change. How do I write my code so that every time the user presses the button, a character is added to the text field?

View Replies View Related







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