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 need to create a grocery store calculator in Netbeans GUI. It should function as follows:
1. Click "Checkout" 2. Enter item price screen pops up. 3. Input item price, and store price in Item price, subtotal and display in those text fields. Also store item number in number of items and display in text field, all after you click "Ok". 4. Enter item price screen should automatically pop back up. (Loop) 5. Once you are finished with all items, when you click "Ok" or "Cancel" with nothing in the text field. It should calculate sales tax/ total sale and display both. 6. Rest button should reset to the beginning and Exit button should exit program.
GUI 1.jpgGUI 2.jpg
The good news is my program works right now. Although I do not believe I am using the setter/getter methods correctly. More importantly I do not fully understand them. I left out the Generated code due to the length.
import java.text.NumberFormat; import javax.swing.JOptionPane; public class Assignment4 extends javax.swing.JFrame { NumberFormat nF = NumberFormat.getCurrencyInstance(); private Object JoptionPane; private double purchase; //private instance variables private int numItems; //private instance variables
I've been trying this for hours but it's not working. I'm trying to add the sea glass look and feel library to my project but I still get the error:
Exception in thread "main" java.lang.NoClassDefFoundError: List (wrong name: list)
What should I do? I've added the library to "project settings >Required Libraries" and did not forget to check the box. I've also imported the L&F so it can't be that.
I pulled off an all nighter in order to finish off this project for my computer studies class but i keep getting an error cannot find symbol at line 96?
import java.io.*; import java.util.*; import java.util.Random; public class SlotMachine { //Generates 3 random numbers for slot machine public static void main(ArrayList<Integer> slotMachine) {
I search this source code in google about library system then i run this in my JCreator then that error appear . I think that problem is all about "main". where can i put that main ?
In the class below I'm trying to create a class that will accept dates in various formats and create a range. The first constructor is easy because I send it the begin date and end date as Date objects. Now I want to send a month(and year) in a constructor and derive the begin and end dates from it. In my constructor that accepts the month/year I need to put the this(startDate, endDate) at the top to be allowed, but the parameters are not built yet.
package com.scg.athrowaway; import java.util.Calendar; import java.util.Date; public class DateRange { private Date startDate; private Date endDate;
I'm having some difficulty with my bank account project. I'm supposed to create a menu where the user can create a new account, withdraw, deposit, view their balance, and exit. There's issues with the account creation.
Here's my necessitated class below: BankAccount, TestBankAccount, SavingsAccount, CurrentAccount, and Bank
I certify that this assignment is my own work and that I have not copied in part or whole or otherwise plagiarized the work of other students and/or persons.
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 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;
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 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?