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;
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 {
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.
// set up the generator CMSSignedDataGenerator gen = new CMSSignedDataGenerator(); gen.addSigner(key, cert, CMSSignedDataGenerator.DIGEST_SHA224); gen.addCertificatesAndCRLs(certsAndCRLs); addsigner and addCertificatesAndCRLs are not found in netbeans.
Which version of Bouncy Castle and JDK version this supports?
Write a function (or functions) that given a collection of files will produce a sum of integers from each line of each file. Each file can have any number of lines from 1 to N. Each line can contain only one integer and no other alphanumeric characters. All of the numbers from all of the files should be added to the final result. The result is just one number.
For either, what we are looking for is:
1. Clear separation of concerns 2. Well defined objects / interfaces 3. Application of good OO design principles to solve the problem 4. No code duplication 5. Test Driven Development 6. Well refactored code 7. Well tested code
This code is for a game I'm making. I'm new to using modulus, and I've been looking all over the place for a tutorial that I can understand. No luck. :
What I'm trying to do is get the console to print "enemy hits player" as soon as enemyAttacksPlayer() is called.
After one second, "player hits enemy" should be printed, so it alternates between these two lines every second.
The issue is when I call enemyAttacksPlayer(), it takes a few seconds to print any lines, and this delay is kinda annoying.
public int time = 0; public void enemyAttacksPlayer() { time++; if (time % 120 == 60) { System.out.println("enemy hits player"); } if (time % 120 == 0) { System.out.println("player hits enemy"); } }
1. public void f(int i, long j){System.out.println("1");} 2. public void f(int...i){System.out.println("2");} 3. public void f(long l, long p){System.out.println("3");} 4. public void f(int j, int k){System.out.println("4");}
With the function call: f(1,2), the output is: 4.
My questions are the following:
a. Why is the compiler choosing #4 to execute and not the rest? b. If I remove 4 and replace it with: 5. public void f(long j, int k){System.out.println("5");}, why does the compiler now give an error complaining of ambiguous function defintions when 'f' is called?
I have made a class here that has two methods. As you guys can notice, in my two methods that I made, I have listed some arguments in there with parameters. My question is that the variables im using in first method, can they be identical on my second method? Is this ok to do?
public class StudentScore { private int math; private int science; private int calc; private int history; private int pe;
I am writing a program for my Java class and I have every function of the program working aside from the modify and delete button. I'm not sure how to make them work. The course material doesn't cover these functions at all.
Here is what I have so far.. which is practically nothing. If I need to post any other code I will, I just don't want to post more than needed because going through unnecessary code can waste time.
public void actionPerformed(ActionEvent e) { inventoryTotalField.setText(String.valueOf(genre[ArrayIndex].getInventoryTotal())); //add button functions if (e.getActionCommand() == "First")//if first button is clicked { ArrayIndex = 0;//set array index to the first element in the array setFieldValues(); // display dvd info on the form
Assignment 13 – Plot functions using abstract methods (Plot functions using abstract methods) Write an abstract class that draws the diagram for a function. The class is defined as follows:
Java Code:
public abstract class AbstractDrawFunction extends JPanel { /** Polygon to hold the points */ private Polygon p = new Polygon(); protected AbstractDrawFunction() { drawFunction();
[code].....
For each function, create a class that extends the AbstractDrawFunction class and implement the f method. Figure below displays the drawing for the first three functions.how to make the jframe to work so that I displays the panel
Assignment 13 – Plot functions using abstract methods
Write an abstract class that draws the diagram for a function. The class is defined as follows:
public abstract class AbstractDrawFunction extends JPanel { /** Polygon to hold the points */ private Polygon p = new Polygon(); protected AbstractDrawFunction() { drawFunction();
For each function, create a class that extends the AbstractDrawFunction class and implement the f method. Figure below displays the drawing for the first three functions.
I am a 3rd year electrical engineer and I am working on a project on solar cell design in the developing world.For my project I am looking to create a very simple web page which can be used by people in the developing world to determine whether a photo voltaic system is suitable to their needs.
For this I want to have simple boxes where a user can input numbers and I used complex calculations to return values (a lot of trigonometric functions etc.), the values then should have the opportunity to be altered to the users digression. This will create a solar model.
For the load aspect of it I am looking to have drop down boxes for a number of components which the user can select and will have a numerical value in Watts which will sum to give total load on system. Ideally I would like to show this graphically in a pie chart showing how much energy each component is taking to give the option to remove.
I am also creating a statistical model which determines the likelihood of having no sunlight on a given day which looks at the solar output, battery capacity and load on the system and will return reliability of the system - this has not been completed but should be shortly.
Aim is to keep web page as simple as possible as unskilled computer users may want to use it.
I am working on a number of utility functions for square matrices and arrays, and I keep having trouble with segmentation faults.
arrayUtils~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ public class ArrayUtils { //This function takes an array a, and returns the sum between indices //i and j, where i is the lower index and j is the upper index. int size makes //sure that the function doesn't go out of bounds. public static int subSum(int[] a,int i, int j) { int sum=0;
I'm trying to make a code that will draw "roses" using polar functions. The code below is what I have, but when I run it nothing happens. What's missing?
package rose; import edu.princeton.cs.StdDraw; public class Rose { public static void main(String [] args) { int N = Integer.parseInt(args[0]); StdDraw.setCanvasSize(512, 512);
I am writing a java application that will function as a lottery game, using arrays it prompts the user to enter 5 digits and matches them against the random lottery numbers generated.
import java.util.Random; import java.util.Scanner; public class App { public static void main(String[] args) { int NUM_DIGITS = 5;
I want to add admin-functions with a login at the main-window.I added first a Key Listener and later a Key Binding to replace the Key Listener.Both worked if i don't changed the background.Now the Key Binding is on a transparent JPanel in front of all other objects. "createback ground (boolean vorwrts)" removed the JLabel wich is the behind all objects and add a new JLabel at this position. Here is the "main code" for this Problem:
//[...]import public class Surface{ int dx,dy;JFrame O,Ox; protected JButton Bx; String[] Names; Image [] Images=null,QImages=null; JLabel background=null;JPanel Top; protected boolean view=true,play=false;
The program below compiles and functions correctly for the most part. It is supposed to be a simple GUI Text Editor with Edit and Format functions. The content pane is supposed to be a scroll pane, however no matter how much I type into the editor, the scroll bar does not appear. Also, the none of the functions under the "Edit" menu work.
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