Make A Simple Calculator Program

Mar 11, 2015

i am working on my assignment in Compro 2, we are ask to make a simple calculator program

here's my code;

import javax.swing.JPanel;
import javax.swing.JButton;
import javax.swing.JFrame;
import java.awt.BorderLayout;

[code]...

View Replies


ADVERTISEMENT

How To Make A Simple Connect Four Program Without GUI

Nov 19, 2014

My code below is trying to make a connect four program without GUI. I'm having trouble with getting the players to make their moves. What should I put in my "makeAMove" method...

Java Code:

public class Connect

final static int MAXROW = 6;
final static int MAXCOL = 7;
public static void main(String[] args){

[code]....

View Replies View Related

Make Simple Program Which Takes In Argument?

May 12, 2015

So I'm trying to make a simple program which takes in an argument (target) and then looks through an ArrayList of strings. If it finds a string that begins with (target) then it will return the index of that string. If it doesn't find a string which begins with (target) then it will return -1 instead.

For some reason, the program is always returning -1, rather than the index of the string within the ArrayList when there is one which matches the search criteria.

Here is the code:

public int getIndex(ArrayList<String> text, String target)
{
int i = 0;
int index = -1;
boolean found = false;

[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

Calculator - Simple Else If Statement

Jan 12, 2014

Started java a couple days ago, and now im working on a calculator. But i'm having a problem with else-if statement. I've made a simple version of the problem here so its easier to identify. If i type in 17, it will give me the answer that i want it to. But if i type in 38, nothing happens.

Java Code:

import static java.lang.System.out;
import java.util.Scanner;
public class Firstclass {
public static void main(String[] args) {
Scanner answer = new Scanner(System.in);
out.println("Whats your name?");
if (answer.nextLine().equals("bob")) {
out.println("How old are you?:");
if (answer.nextLine().equals("17")) {
out.println("Nice");
} else if (answer.nextLine().equals("38")) {
out.println("good");
}
}
}
} mh_sh_highlight_all('java');

View Replies View Related

Simple Calculator Swing Java

Dec 13, 2014

I am a beginner with Java. I have never used SWING before but I have to use it now and I am clueless. I don't know if what I am doing is right.I need to create a simple calculator. My problem is getting the buttons the user clicks to appear in a text field. I know I haven't added the =/*- buttons yet.

I have left actionPerformed practically blank, what to put in ?

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
/**
* Created by IntelliJ IDEA.
* Date: 11/12/2014
* Changing Face Program.
*/
public class Calc extends JFrame implements ActionListener

[code]...

View Replies View Related

Simple Printing Calculator With Accumulator

Feb 13, 2014

Here's the lab assignment: This program is a simple "printing" calculator. It will accept input from the user in the following form:

number operator

The number entered will be expected to be a float type.

The operator will be expected to be one of the following:

'E' or 'e' - Enter the number into the accumulator (this will destroy the current value). This operator is used to set the accumulator to a known value.
'A' or 'a' - Add the number to the current value in the accumulator
'S' or 's' - Subtract the number from the current value in the accumulator
'M' or 'm' - Multiply the number times the current value in the accumulator
'D' or 'd' - Divide the current value in the accumulator by the number (do not divide the accumulator by zero)
'P' or 'p' - Raise the current value in the accumulator to the power of the number, for this problem truncate the number to its integer value. (negative numbers will not be allowed) SDo not use the "Math.pow()" method to solve this problem.
'T' or 't' - Terminate processing and print the final result. The number accompanying this operator should be ignored.

The 't' or 'T' stop signal is entered by the user, the program will print out the final value contained in the accumulator and terminate.

A sample session would be the following:

User inputs: Calculator outputs:

10.0 e = 10.0000
2 D = 5.0000
2 P = 25.0000
55.0 s = -30.0000
100.25 E = 100.2500
4 m = 401.0000
0 t = 401.0000

When the program starts the initial value for the accumulator is set to zero.

If the user gives an input that would result in an error if the operation were to be attempted, an error message is printed and the current accumulator value. This calculator handles three types of input errors:

1). if the user enters an invalid operator, the message is printed : an invalid operator was entered - please reenter

2). if the user attempts to cause a divide by zero, the message is printed : attempt to divide by zero - please reenter

3). if the user attempts to raise the accumulator to a negative power, the message is printed: negative powers are not allowed - please reenter

By looking at the requirements, here's how I would like to setup the program if I knew the proper syntax and all:

Step 1: Create Class called 'calculatorProgram'

Step 2: Use code that will allow UserInput after program executes (Our teacher forbids us to use Scanner, wants us to use InputStreamReader and BufferedReader)

Step 3: Create Variables:
*Fnum (It will be the Accumulating number)
*Ans (displayed after Fnum + operator)
*Operators: E, A, S, M, D, P, T (define their functions)

Step 4: -Tell user: "How to use the calculator and what letters to use for their function"
-Ask user to: "enter a number and an Operator function"

Step 5: Begin with a While loop( != 'T' || != 't'){} -I think that's how the loop should be formatted

Step 6: Design proper If/else and nested If/else statements for each operator and its function, be sure to use nested if/else for invalid operators, divide by 0, and using negative powers.

Assuming I knew how to write Java this is how I would want to code my program. I understand the concept or I/O and the purpose of Conditional statements just I have a hard time knowing how to place the variables in the right places and writing proper syntax.

View Replies View Related

Calculator That Ranges From Simple Math To Trig

Nov 15, 2014

I am trying to make a calculator that ranges from simple math to trig. I am trying to start the j-frame for it and I already have most of the formulas programmed with the if-else statements and such. How do I go about starting the jFrame and marrying the 2 codes together to start it. (I have taken a bit of programming but relatively new to writing j-frames and using other classes and putting them together).

View Replies View Related

Java Simple While Loop Wage Calculator

Nov 13, 2014

I need to do a simple while loop pay calculator. I am very new and not sure what I need to do to put all the requirements in the new code from another code. Here is my code that doesn't work yet.

1.Place the wage calculation routines in a while loop.
2.Allow the user to input an individual's hours worked.
3.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.
4.Allow the user to enter a zero (0) as the Boolean expression to end the loop.
5.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;
double wage = 0f;

[Code] ....

View Replies View Related

Simulate Simple Calculator That Performs Basic Arithmetic Operations Of JAVA

Sep 9, 2014

How can i write a java program that simulate a simple calculator that performs the basic arithmetic operations of JAVA. (JOption Pane and Repeat control structure)

Example : Addition, Subtraction, Multiplication, Division.

The program will prompt to input two floating point numbers and a character that represents the operations presented above. In the event that the operator input is valid, prompt the user to input the operator again.

Sample Output :

First number 7
Second number 4
Menu

<+> Addition
<-> Subtraction
<*> Multiplication
</> Division

Enter Choice: * <enter>

The answer is 28.

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

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

Make A Calculator Using Stacks

Feb 4, 2014

i got a problem with this program.I am supposed to make a calculator using stacks but it seems that i m stack. i can t get the right recognition

for () and {} []

its not necessary to use all these symbols.just a simple () will do .here s the program

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

View Replies View Related

Make A Calculator Layout

Apr 30, 2015

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.

public class MySecondCalculator extends JFrame {
JTextArea screen;
JMenuBar mb;
JMenu file;
JMenuItem open;
JButton one, two, three, four, five, six, seven, eight, nine, zero, decimal, add, subtract, multiply, divide, equals;
 
[code]....

View Replies View Related

Make GPA Calculator For 5 Courses Of Grades

Nov 7, 2014

I have to make a gpa calculator for 5 courses of grades A B+ C+ D F, and worth 4, 3.5, 3, 2.5, 2,1,0 respectively. using 10 input text boxes, and a button

Create two arrays of length 5: one to hold the numerical values of letter grades, the other to hold the number of credit hours. Initialize both to have 0’s. Write a function that takes a letter grades entered by a user and returns its numerical equivalent.

Use an ‘if…else if… else’ construct.

Write a function that can operate on the two arrays and return the GPA. Use a for loop that runs from 0 to 5, multiplies the corresponding array elements and adds them together, divides that total by the total number of credit hours, and returns that value.

Input elements:

In the first 10 textfields, use the onchange attribute to fill the arrays with user entries.

Hint: For the course grade entries it should look like

onchange= ‘array1[0] =
first_function(this.value)’ etc.

The button should make the value of the last text area equal to the return value of the second function.

i have my whole code completed but when i press the button it returns the points value '0' so i think there is an error in my if else statements (ltonum function)

<DOCTYPE! html>
<html>
<head>
<title> Assignment 9: Javascript 3
</title>
<!-- Assignment 9, Due November 8, 2014, Jamie Zajac, TA Kartik-->
<style>
body
{
background-color: lemonchiffon;
color: midnightblue;

[Code] ....

View Replies View Related

How To Make A Simple Password Strength Indicator

Jun 18, 2014

I am developing a number of Data Structures in Bluej. Iv created a nice little arraylist program, and want to add a password generator to this program. People are already prestored within the arraylist, and contain attributes such as ID, name, password, etc. I can search a persons name within the list and then view their ID, password, and encrypted password. I want to add a field which will show password strength, bare in mind the password is already stored within the program and will not be entered via the user.

I understand that this could be done via a regular expression, or using some count method where certain goals/sets of characters increase the count which determine strength.

View Replies View Related

How To Make Simple Java Application Installable

Sep 9, 2014

I want to create simple java application which has 3 text fields and the application will have database connection. Once done, I want to run this application on other systems without using any IDE. So how do I do this? How can I make an application installable on other system so that on clicking on it, it will start executing?

View Replies View Related

How To Add Action Listener To Code To Make Calculator Work

Mar 7, 2014

here is the code i already have made;

import java.awt.*;
import javax.swing.*;
public class EX_7_2 extends JFrame
{
public EX_7_2()
{
setLayout(new BorderLayout(5, 10));

[Code] ....

View Replies View Related

Make Simple Caesar Cipher That Takes In String As First Argument

Jan 21, 2014

I'm trying to make a simple Caesar cipher that takes in a String as the first argument and a integer shift as the second argument. Namely, there appears to be a problem with the loop and how I have declared the array - I want the converted characters to be put into a new array called newCharacterArray, converted back to a String and displayed in the command prompt window.

public class Caesar {
public static void main(String inString, int k) {
System.out.println("String: " + inString);
char inStringArray[] = inString.toCharArray();

[code]....

View Replies View Related

Make A Simple Platformer Game In Java - Moving Characters

May 24, 2015

I am trying to make a simple platformer game in Java. When I try to move the character I made it only moves over then immediately back

import java.awt.event.KeyEvent;
public class UCC
{
private int xLoc;
private int yLoc;
private int xSpeed;
private int ySpeed;
private double gravity;
private int size;
 
[code]....

View Replies View Related

Grade Calculator Program

Nov 12, 2014

how to I modify my program so that it asks the user how many studens are in the class then according to the value the user inputs that is how many times the program will ask the user for a grade. Once the graded are entered it will then output the class average, minimum, and maximum. I believe that you'd use a for loop yet I am troubled.

import java.util.Scanner;
public class GetLetterGrade{
public static void main(String [] args){
Scanner reader = new Scanner(System.in);

[code]...

View Replies View Related

Grading Calculator In Java Program?

Sep 26, 2014

i have a similar problem but what i need to do is to detect an exused absent of which in my notepad is represented by 00 and 0 being an unexcused absent, anyway if a student has an excused absent example a quiz for that day will be deducted from the total quizzes example if i was the teacher and had 2 quizzes of 10 items each and she was absent in one of the quizes instead of let say her score was 9 on the first quiz it should go 9/10 and if it was an unexcused absent 9+0/20 anyway this is my java code and notepad example

import java.io.*;
import java.util.*;
import java.lang.*; 
public class GradingSystem {
public static void main (String[] args) throws FileNotFoundException

[code]...

View Replies View Related

Program Calculator Using Switch Case

Oct 14, 2014

I am making a programme for a calculator to - Divide, multiply, add and subtract. I have the code written but when I am running it and trying to add it was for some subtracting ....

import javax.swing.JOptionPane;
public class calculator3 {
public static void main(String[] args){
String number1,number2,operatorstring;
double result=0,a,b;

[Code] ....

View Replies View Related

Calculator Program - Using Decimal And Operators

Oct 20, 2014

How do I get the code to use decimals? Also whenever you input 1, 2 or 3 as one of the operators, it always does that operator as well as the 4th operator at the end. So it always does subtraction. However when you use 4 as the only operator it works perfect.

import java.util.Scanner;
public class Program05 {
public static void main(String[] args) {
Scanner stdIn = new Scanner(System.in);
 double left;
double right;
 
[Code] ......

View Replies View Related

Carpet Calculator Program With Aggregations?

Nov 26, 2014

I'm doing a Carpet Calculator Program with aggregations and can't seem to get my RoomCarpet class to work properly. This is what I have so far:

package roomDimensions;
/*
*
* Raul Caltenco

[Code].....

View Replies View Related

Running A Simple GUI Program

Nov 23, 2014

I'm getting back into the swing of things with Java after using I'm asked to utilize a simple GUI in order to take in the starting data, I cannot seem to get this to work. I'm getting this error Exception in thread "main" java.lang.NullPointerException

at java.awt.Container.addImpl(Unknown Source)
at java.awt.Container.add(Unknown Source)
at Input.buildPanel(Input.java:53)
at Input.<init>(Input.java:27)
at InputDemo.main(InputDemo.java:5)

I've created two classes

import javax.swing.*;
public class Input extends JFrame {
private JPanel panel;
private JLabel messageLabel;
private JLabel messageLabel1;
private JLabel messageLabel2;
private JTextField shiftHrs;

[code]....

View Replies View Related







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