Build A Calculator In Java?

Aug 28, 2014

I wanted to build a calculator in java but I have a problem I wanted to when I type "plus" , go to This IF but don't go

import java.util.Scanner;
public class Session {
static String amal;

[code]....

View Replies


ADVERTISEMENT

Build A Clash Of Clans Troop Calculator

Apr 22, 2014

For my first attempt at writing a program that consists of more than one class, I am trying to build a Clash of Clans troop calculator. It will allow the user to configure an army composition and return the cost to train, the total damage per second, and the total training time. Cost and damage will vary based on the levels of each type of troop. Total troop capacity will depend on the number and level of the available army camps. URL...

Eventually it will need a GUI, but I'm just trying to plan out the components right now. I started by writing a masterclass called Troop, and subclasses for each type of troop.Troop class:

public class Troop {
private int qty;
private int level;
private static int HOUSING_SPACE;
private static int TRAINING_TIME;
private int elixirCost = 0;
private int darkElixirCost = 0;
private int damagePerSecond = 0;
private int hitPoints = 0;

[code]....

I made each type of troop its own class because 1) the setElixirCost(), setDamagePerSecond(), and setHitPoints() methods will all use different values for each different troop type and 2) I thought building an Army of one of each object would be the easiest way.

Now I'm trying to figure out the best way to build the Army class. It will basically just be a collection of Troop objects, with a few methods to return the total training time, total elixir cost, total hitpoints, and total damage per second. Should it be its own class? I thought about making it just an array of Troops, but it needs to have its own field for max housing space so the client can warn the user to stop adding troops when all army camps are full.

View Replies View Related

Build A Fan In Java?

Nov 5, 2014

i am having problems with making it start. i have the buttons set but when i click on them they don't do anything.

mport java.awt.*;
import javax.swing.*;
public class Fan extends JFrame {

[Code].....

View Replies View Related

Build Tree Structure From Array In Java

May 31, 2014

I never used tree, node etc. Consider an array of strings that come from html tags. This needs to be turned into a tree structure. Here, any Hn is the child of the most recent Hn-1

String[] Headers = {"H1", "H1", "H2", "H3", "H3", "H2", "H2", "H3",
"H4", "H2", "H2", "H2", "H1", "H2", "H2", "H3", "H4", "H4", "H2" };

Desired output -

ROOT
H1
H1
...H2
......H3
......H3
...H2
...H2
......H3
.........H4
...H2
...H2
...H2
H1
...H2
...H2
......H3
.........H4
.........H4
...H2

ANSWER -

class Example {
static class Node {
final String name;
final int indent;
Collection<Node> children = new LinkedList<> ();

[Code] .....

View Replies View Related

Using Only Java Swing Without Windows Builder To Build GUI Application?

Oct 8, 2014

Difference between using windows builder in eclipse v/s using only java swing without windows builder to build GUI application?

View Replies View Related

Java Tree Structure - Build Tree Based On Traversal Results

Jun 17, 2014

How to do draw the original binary tree based on traversal results?

A binary tree has this pre-order traversal result: A,B,D,H,I,E,F,C,G,K,J (TreeNodes) And the same tree gives the following in-order traversal: B,H,I,D,A,C,F,E,K,G,J. Can you draw the tree structure?

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

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

How To Build Java Peer To Peer Application

May 6, 2014

how to build a P2P app in java because I have difficulties working with a tool called JXTA.

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

GPA Calculator In Java Using Loops And Switch

Apr 25, 2015

I am trying to make GPA calculator. I decided to use only switch statement and make it as simple as possible. The point is to enter as many classes and students as user wants. I keep getting credit points 0 at the end and also text format is not good too. Here is the code.

import java.util.Scanner;
import java.io.*;
public class SwitchExercise{
public static void main(String[] args) {
String grade = "";
String grades="";
String coursename="";
String headingleft="COURSES";

[code]....

View Replies View Related

Java Calculator - Multiplication And Division

Apr 24, 2015

I am having problems with my code I have added the multiplication and division but they will not display also how can I correct any error when dividing by zero?

import java.awt.*;
import java.awt.event.*;
public class calculator2 extends java.applet.Applet implements ActionListener {
TextField txtTotal = new TextField("");
Button button[] = new Button[10];

[Code] .....

View Replies View Related

Java Calculator - Numbers Are Not Adding

Jul 12, 2014

So I was making a Java Calculator that only adds. The problem is that the numbers are not adding. I think it is because whatever has been clicked is not being saved to be added.

import java.awt.BorderLayout;
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

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

Java Calculator Using Stack Data Structure

May 21, 2014

My assignment is to design a simple GUI calculator using the stack data structure to perform additions, subtractions, multiplications and divisions. But i having error while i press the action there.

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
import java.util.Stack;
public class JCalculator implements ActionListener {

[Code] ...

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

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

Java Calculator - Making Numbers To Stay At Textfield

Jul 12, 2014

How can I make the numbers to stay at the textfield of my calculator instead of disappear like when I type 1 then hit the + sign the number 1 disappears from the textfield I would like to have this (1+1) showing in the text field and also if try to press only + , * , - , / to show error.

this is my code

public class Calculator extends javax.swing.JFrame {
private double TEMP;
private double SolveTEMP;
Boolean addBool = false;
Boolean subBool = false;
Boolean divBool = false;
Boolean mulBool = false;
String display = "";

[Code] ....

View Replies View Related

Java Project - UPC Calculator / Calling ToString Method?

Feb 20, 2014

Our goal is to write a pretty simple program, one that takes the 12 digit UPC code entered by a user and to not only spit it back out in a format with dashes using toString, and also returns the first digit, a 2 more groups of digits numbering 2-6 and 7-11, and finally display the 12th digit. It then performs an equation to check the last digit and make sure the UPC code is correct.

However, being so new to java (I only learned visual basic before), with this I was introduced to two new concepts that for some reason I simply cannot grasp for the life of me: Using and calling the toString method, and calling on methods that are created in a completely different class file.

The first section of code is my UPC class, which is meant to contain all my methods as well as the toString to be called on:

public class UPC
{
// Instance variables
private int itemType; // digit 1
private int manufacturer; // digits 2,3,4,5,6
private int product; // digits 7,8,9,10,11
private int checkDigit; // digit 12

[Code] .....

View Replies View Related

JAVA Calculator - Equals Method To Return Appropriate Value Using Standard Arithmetic

Apr 18, 2014

I am having trouble using the equals method to return the appropriate value using standard arithmetic.

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

[Code] ....

I know that "inText.setText(Integer.toString(secondOperand));" in the code is wrong, I just don't know the right 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 Build A GUI

May 18, 2014

how to build a GUI. I typed (not copy and paste) this code line by line to understand and get a meaning to each command. I ran into some errors while compiling and decided I would try to fix it. I ran into a problem there.....

import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;

[Code].....

View Replies View Related

How To Build Graphics

Jan 5, 2014

He said that if you need something that Swing can't provide, like a bar graph, you build it. Now, being used to just writing a method that will open up a JFrame, how you would actually build graphics on your own. How in the world would that work? How would one write their own methods to make a window or to build a graph?

View Replies View Related

How To Build GUI With JFrame

Nov 10, 2014

how to build GUI's with JFrame and I was firstly very confused as to when and what is always needed for any GUI in Java. How do I know everything I need for a GUI? Are there certain things every GUI will need by default?

Additionally below I have a code snippet of when this person used the "this" as an argument to a JButton and Im just really confused for when I can use it and when I can't.

public UIStuff(){
super("Multiple Button Events");
init();
} // end multi-button
 
[code]....

View Replies View Related

How To Build Triangle Using Loops

Jan 16, 2014

I need to build the triangle like below. How to solve this using loops.

*
* *
* * *
* * * *
* * * * *

View Replies View Related

Build A Calendar In BlueJ

May 25, 2014

i have a problem, i need build a calender in BlueJ. The program need to found if I put this one year have to give me the full schedule but only the first semester.

View Replies View Related







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