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;
Write a java program that calculate the grade point of three subjects and their credit hours through if the grade points and the credit hours are
Subject---grade---gradepoint-----credit hours Maths------A--------4.0---------3 English composition-----B-------3.0-----2 French-----B+ ---- 3.3----------3
Now,if the grade point is equal to 4 ,print out First class If the grade point is equal or greater than 3.0 but less than 4,print out Second class upper If the grade point is equal or greater than 2.0 but less than 3,print out second class lower Use the if-else-if statement
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.
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 {
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");
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;
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
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;
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
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.
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)
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 {
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:
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?
Why I am getting errors for this program I (tried) to write. I am new to java.
import java.util.Scanner; public class TheBarkingLot { public static void main(String args[]) { int n; Scanner input = new Scanner(System.in); System.out.println("How many large dogs are boarding today?");
I've made a calculator that can add, subtract, multiply, and divide, but I still need a clear function and a square root one for it. I've tried going on the various calculator tutorials, but they don't work.
And here's my code:
import java.awt.*; import java.awt.event.*; import javax.swing.*; public class Calculator extends JPanel implements ActionListener { private JTextField display = new JTextField("0"); private String button = "789/456*123-0.+="; private double result = 0;
How to make my program look nice. I have to create a mortgage calculator with no functionality, so it basically just has to be a window that looks like this:
Here's my code:
import javax.swing.*; import java.awt.*; import java.awt.event.*; public class MortgageCalculator { public static void main(String[]args) { CalcWindow calculator = new CalcWindow();
[Code] .....
Here is the output I am getting:
How do I make my program output look similar to the 1st picture?
im considered quite the "javanoob" as my account name states..The assignment is to basically take a number that is entered by a user, and based off what they type in, display a corresponding grade letter. For example, if they enter a number between 90-100, they should receive a response that they received an "A". Now, this is fairly simple using an if/else statement, but my professor wanted us to implement this, using a switch case to teach us the difference.
import java.util.*; public class SwitchTest { public static void main(String[] args) { Scanner scan = new Scanner(System.in);
System.out.println("Please enter a number to find out what letter grade you have recieved");
So I'm making a calculator using JFrame and that stuff and I need figuring out the GridLayouts. I'm not doing this for homework or anything just for fun. I don't need all the grid layouts.
I need to create a simple Java program for a commission calculator with the following requirements: I need to ask the user to enter their total sales (as a double) in at the keyboard and I need to use "if" statements to tell them their commission (sales * commission rate) using the following criteria:
o < $8000 in sales – Commission rate = 10% o $8000 to $12000 in sales – Commission rate = 12% o $12000.01 to $18000 in sales – Commission rate = 15% o $18000.01 to $20000 in sales – Commission rate = 18% o > $20000 in sales – Commission rate = 20%
Then for the output the user’s Commission in a well formatted way (use the DecimalFormat class) .In comment blocks have a description of what the program does.
import java.util.Scanner; public class CommissionCalculator //This program calculates the commission of sales { public static void main(Strings[] args) { // create a scanner Scanner input = new Scanner(System.in); //define variable double sales; //inputted sales amount double commission = 0; //commission pay amount
I want to make a calculator program as my first ever program and I've been working on the layout and I think I have it close to where I want it but will probably tweak it in the future after I get it to work. My problem is I'm trying to add a MenuBar to it but it is not showing up. I tried having it all over my code but whereever I put it the MenuBar doesn't show up.