Minus Expenses From Monthly Income And Display Net Income In JLabel
Jun 26, 2014
I am trying to build an app for managing expenses to practice with java programming. I am stuck on the ActionEvent block. The program i am trying to make needs to minus the expenses from the monthly income and display the net income in JLabel.
package mybudgetapp;
import java.awt.BorderLayout;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
[Code] .....
View Replies
ADVERTISEMENT
Nov 3, 2014
I'm writing some code which calculates the tax payable based on income, and I need to have a separate method which then calculates the income AFTER the tax has been deducted. I've done this quite easily by re-writing the code in the next method, however is there a more efficient way around this where I can pass the values from the first method to do the calculation...
public class TaxCalculator {
// Main method calling taxpayablereturn and taxafterdeduction
public static void main(String[] args) {
System.out.print("Tax Payable = £"
+ TaxCalculator.taxpayablereturn(570));
[Code] ......
View Replies
View Related
May 12, 2014
With fields that holds a tax payer social security number, last name, first name, street address, city zip code, annual income, marital status and tax liability, include a constructor that requires argument that provide values for all other fields other than the tax liability. the constructor calculates the tax liability based on annual income and percentage in the ff table
Income
0-20,000
20,000-50,000
50,000 and over
marital status
single married
15% 14%
22% 20%
30% 28%
View Replies
View Related
Nov 27, 2014
I have written the following code to calculate tax payments based on income and filing status :
import java.util.Scanner;
public class computeTax {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
// prompt for filing status
System.out.println("enter '0' for single filer,");
[Code] ....
The while loop initiated on line 21 is there so that in case the wrong input is given at the prompt given in line 24, the program outputs "please type the right answer" with the command on line 254 before looping back to line 24 and prompting the user to enter his status number. The program works as long as the input at line 28 is an integer. Not surprisingly if the erroneous input here is not an integer, the program outputs the following error message :
Exception in thread "main" java.util.InputMismatchException
at java.util.Scanner.throwFor(Scanner.java:909)
at java.util.Scanner.next(Scanner.java:1530)
at java.util.Scanner.nextInt(Scanner.java:2160)
at java.util.Scanner.nextInt(Scanner.java:2119)
at computeTax.main(computeTax.java:28
To try to solve this I used the Try / Catch technique with the following version of the code :
import java.util.Scanner;
public class computeTax {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
// prompt for filing status
System.out.println("enter '0' for single filer,");
[Code] ....
View Replies
View Related
May 8, 2014
I'm having problems getting my program to display a JLabel. The program draws shapes of random size and color across a panel. I have this part working. (There is more code for the drawing of shapes, I left it out for easier reading). When I try to add a JLabel in the main method, it does not display.
import javax.swing.JFrame;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class TestDraw {
[Code] .....
View Replies
View Related
Mar 27, 2015
i have very critical problem in my collage project i have try many code but still i cant solve this problem, i want to display image on jlabel or jpanel with respect of components size without use of drawimage method
View Replies
View Related
Sep 30, 2014
The problem I'm trying to resolve now is getting my ActionEvent to send the value input in the JTextArea out to be calculated, then to display the result in my result JLabel.
Here is an image of the GUI :
The basic procedure the teacher is asking for is the user is supposed to enter a temperature in the input. The user then clicks the input scale, and then on the output scale selection the converted value is to be displayed in the output area.
As I mentioned my problem is in the sending of the input value to my calculation area, and getting the value to display in the JLabel.
How should I approach this solution? Do I need to have a listener after the JTextArea of the input box? Will that allow me to limit the input values to numbers only?
final JTextArea inputText = new JTextArea("" + (char)176,1,4);
//ReadConsole equivalent to specific input was a number?
Here is the section of code my ActionListener is:
//celOut represents the Celcius output scale JRadioButton.
celOut.addActionListener (new ActionListener () {
@Override
public void actionPerformed(ActionEvent e) {
//if the Celcius Input Scale is selected.
if(cel.isSelected())
[Code] ....
All the calculations are required to occur in a separate java file, which what I think is tripping me up. How do I send a value from the JTextArea into the Calc.celToFahr method?
//contents of my Calc.java calculation class.
public class Calc {
public static double celToFahr(double cel){
return cel * (9./5.) + 32.;
}
public static double fahrToCel(double fahr){
return (fahr - 32.)*(5./9.);
}
}
View Replies
View Related
Feb 12, 2014
I have deduct a number of days excluding holiday and weekends .So if I have to deduct 4 days from current day (02/12) and assuming 02/10 is a holiday my answer will be 02/05
Now below is the code I have come up with however its not working with the hardcoded dates I am passing in to the Holiday Calendar String .Only the last value is considered . How I should store this values and compare with the date
package date_calculation;
/**
* Returns a tick for each of
* the dates as represented by the <code>dtConstants</code> or the list of <code>dtDateTimes</code>
* occurring in the period as represented by begin -> end.
*
[Code]...
View Replies
View Related
Sep 25, 2014
This is for a mortgage calculator and we have to use the math.pow method. I am getting results, but the results are wrong. The monthly payment is coming out to big.
Here is what it should be:
Enter loan amount: 10000
Enter rate: 4.5
Enter number years: 3
The monthly payment is: $297.47
Here is what I'm getting.
Enter loan amount: 10000
Enter rate: 4.5
Enter number years: 3
The monthly payment is: $566.06
Here is my code. I believe my issue is in the math.pow formula.
Scanner in = new Scanner(System.in); // input object
double loanAmount; //user input
double interestRate; // user input
double yearNumber; // user input
double monthlyPayment; // answer to math
double finalPayment; // output
double monthNumber; // year number converted of months
double monthlyRate; // converted intersted rate
[Code] ....
The monthly payment is: $%.2f", monthlyPayment); // Shows monthly payment
View Replies
View Related
Jun 11, 2014
I want to Write a program that calculates the minimum fixed monthly payment needed in order pay off a credit card balance.
the Amount is 3,500 the annual rate is 9.9%, the minimum payment is 2% a month. the fixed payment is 150.
By a fixed monthly payment, we mean a single number which does not change each month, but instead is a constant amount that will be paid each month.
The program should print out :
payment information:
new balance total .......
current payment due .......
if you make minimum payment (2%) you will pay of in .... months and you Will end up paying an estimated total of $........
if you make the fixed rate payment, you will pay of in .... months and you Will end up paying an estimated total of $........ and you will save $........
View Replies
View Related
May 29, 2014
I started taking a java programming class javascript eclipse The program says it wants a monthly temperature chart of two places..Declare an array of values for Blueville temperatures and another array for Orlando temperatures. Then, use what you have learned to produce a program to output the following table:
Blueville Monthly temperatures
jan feb mar apr may jun jul aug sep oct nov dec
3 3 5 10 16 20 24 23 16 10 5 3
Orlando Monthly Temperatures
jan feb mar apr may jun jul aug sep oct nov dec
14 16 12 23 24 25 27 30 25 22 17 15
The warmest month in Blueville is _______
The warmest month in Orlando is ________
The month with the greatest temperature spread is __________
View Replies
View Related
Feb 20, 2011
What to do with this JAVA code?
This is the code that I need to do without using the Joptionpane:
An Internet service provider has three different subscription packages for its customers:
Package A: For $9.95 per month 10 hours of access are provided. Additional hours are $2.00 per hour.
Package B: For $13.95 per month 20 hours of access are provided. Additional hours are $1.00 per hour.
Package C: For $19.95 per month unlimited access is provided.
Write a program that calculates a customer's monthly bill. It should ask the user to enter the letter of the package the customer has purchased (A, B, or C) and the number of hours that were used. It should then display the total charges.
This is what I have so far : Cannot use Joptionpaneshowinputdialog
/* A demonstration of how to use Decision Structures
import java.util.Scanner;
/**
This program demonstrates a switch statement.
*/
public static void main(String[] args)
{
char packageLetter;
int hoursUsed;
[Code] ....
View Replies
View Related
Dec 21, 2014
I am doing a program where i have to implement a payroll system into a company for hourly, fixed monthly and commission paid workers. I also have to put the method which i did. the problem is I cant tell if my calculation is wrong or if i am missing a codes some where. The output is not giving me the answer that I was at least expected,
Here is my method:
{
< double total_deduction;>
< total_deduction = gross_pay - deduction;>
< return total_deduction;>
}
< public static double calGrossH(double hours_worked, double pay_rate)>
[Code] .....
I have done a lot researching and have come up with some search with almost the same calculation and I have also asked employees of a company on how they calculated hourly rate, commissions rate and fixed rate for all workers and gotten the same response but for some reason the output is not what it is supposed to output. here is my output.
<
un:>
<please enter the number of employees to be processed 31>
<please enter employee id number 3669>
<please enter employee first name>
[Code] ....
I dont know if I am missing some calculation somewhere or codes been researching and bussing my brains to figure out where is the missing codes or calculation.
View Replies
View Related
Oct 18, 2014
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
[Code]....
I am trying to Make A GUI which has a Jcombo box i also want it to have a jlabel that up dates depending on which option the user selects from the JcomboBox
for exampl if i select lion i want it to say you chose lion on the Jlabel and if i choose ostrich i want it to say ostrich and so on
View Replies
View Related
Jan 9, 2014
I am trying to move a JLabel in a JPanel, but can't seem to make it work. I can't provide a compiling code, but a few fragments. I have a JLabel [] array. i want to move with the mouse elements of this array. Let's say i want to move JLabel[i]. I implemented this:
Java Code:
static int labelY;
static Point labelX;
static Boolean flag = false;
jLabel[i].addMouseListener(new MouseAdapter(){
public void mousePressed(MouseEvent evt){
labelY=evt.getY();
[Code]...
I used the bool flag because i can't make changes to the label when it is inside an anonymous class. I also tried using setLocation but that did not work also. I don't get any errors when compiling. But when i run it and try to drag the JLabel[i] i get a long list of errors:
Java Code:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at puzzle.hw$1$2.mouseDragged(hw.java:276)
at java.awt.Component.processMouseMotionEvent(Unknown Source)
at javax.swing.JComponent.processMouseMotionEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
[Code]...
View Replies
View Related
Sep 26, 2014
I read many posts online and watched tutorials on YouTube. I can't seem to get this work. Notice I am not using any drawing/graphics capabilities - I'd like to keep it this way as we have not gotten that far yet in my studies.The image is in a source folder titled Images under/in my project.
Java Code:
private JPanel jpImage = new JPanel();
private JLabel lblImage;
private ImageIcon image;
private Image img;
// All those above defined prior to method
// Within method (relevant to code above) ...
[code]....
View Replies
View Related
Apr 5, 2014
So Im making a game with a start screen followed by my game. I have a button centered but Im having a hard time displaying my label. Here's my code:
import java.awt.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JFrame;
public class TitleScreen extends JPanel implements ActionListener{
[Code] ....
View Replies
View Related
Jan 13, 2015
I want a JLabel with scrolling text as marquee effect...
View Replies
View Related
Jul 21, 2014
I have written a code to rotate a Jlabel but i am facing some problems.
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.MouseInfo;
import javax.imageio.ImageIO;
[Code] ....
View Replies
View Related
Apr 5, 2014
So Im making a game with a start screen followed by my game. I have a button centered but Im having a hard time displaying my label. Here's my code:
import java.awt.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JFrame;
public class TitleScreen extends JPanel implements ActionListener{
[Code] ....
View Replies
View Related
Mar 18, 2014
Write a class named FileDisplay with the following methods:
1.) constructor: the class's constructor should take the name of a fil as an arugment.
2.) displayHead: This method should display only the first five lines of the file's contents
Here is the following code I have made so far
import java.io.*;
public class FileDisplay
{
private String filename;
public FileDisplay(String Filename) throws IOException
[Code] ....
First, in my constructor I have taken in an argument and used that argument to open up an output file. Meanwhile, I'm trying to work n the displayhead method to print out information and to read data to. I haven't opened up my input file yet, but I'm not understand how can I read a print data to an output file. in
public void displayHead()
{FileWriter file=new FileWriter(Filename)}
do I make create another instance of the filewriter class to output data?
In simple words, suppose to I want to display some messages on my output file in the displayhead function. Since I already have opened up the file in the constructor, how do I combine that in this method...
View Replies
View Related
Jan 13, 2015
I have tried to set a background Image to a calculator usinf JLabel. However I've ended up with my image to the left of my calculator , my calculator textfield becoming the size of the background image and then all my buttons below it.
Like so(if you can view the image)..Calculator.jpg
How can I fix this so the background is behind my buttons and my text area is a normal size again.
My code is below :
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
/**
* Program using SWING components to create a Christmas themed Calculator.
*/
public class GridBag1 extends JFrame implements ActionListener
[Code] ....
View Replies
View Related
May 6, 2014
How can I access to a jLabel of a class from another class or edit its text?
View Replies
View Related
Dec 20, 2014
I am trying to make movingLabel move to a different JPanel each time the JButton is clicked. I can see that the random integer is changing each time the button is clicked, but the movingLabel wasn't doing anything. I noticed that if I click the button and then resize the JFrame with my mouse, it shows in the correct panel. Is there something I am missing, or is there a way to make it automatically display in the correct panel without having to manually resize the JFrame each time? I was thinking that I could add something that resizes the window slightly each time the button is clicked to show it, but I don't think that is probably the "right" way to do it.
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.Random;
public class JMovingFrame extends JFrame implements ActionListener
[code]...
View Replies
View Related
May 26, 2014
I am currently trying to make a method that will enable a jLabel to be dragged across the screen. I want to be able to drag the object pretty much anywhere on the screen(I hope to eventually make a destination for it where it can be dropped but I will get to that later). I have looked on various places on the internet on how to achieve this and the most simple solution does something like this:
Java Code:
jLabel6.setText("jLabel6");
jLabel6.addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
public void mouseDragged(java.awt.event.MouseEvent evt) {
jLabel6MouseMoved(evt);
}
});
private void jLabel6MouseDragged(java.awt.event.MouseEvent evt) {
x = evt.getX();
[Code]...
This actually works somewhat but it is very faulty. For example the jLabel keeps appearing and reappearing as I drag it. Furthermore when I drag it I can see a duplicate Jlabel being dragged as well in the top left hand screen. So how might I fix this?
View Replies
View Related
Feb 18, 2014
I'm using NetBeans.
I have a JFrame with four JPanels, SensorLL, SensorLC, SensorCR and SensorRR. They are instances of the class SensorUI. Each has a JLabel called Sensor.
The class SensorUI has a method writeSensor that writes to the JLabel "Sensor". I will have four temperature sensors. I have not started the code to read the temperature sensors yet. I will have a timer that will run once a second. When it fires I will read the sensors and display the result in the
JLabel "Sensor" in each jPanel.
I use MyMain to call FrameDemo and create the JFrame and a method
in FrameDemo to add the JPanels using addObject.
I can use SensorLL.writeSensor will write text to JLabel Sensor while in Mymain.
Then I start the timer ReadSensor.
When it times out it calls SampleSensors
For an experiment, while in SampleSensors I try to write to the JLabel in the instance SensorLL with
SensorLL.writeSensor("xx_");
I can't because it says it can't find the symbol variable SensorLL in SampleSensors class.
How can I "get to" that JLabel text when ever I need to?
Java Code:
public class MyMain {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
//SensorUI SensorLL = null;
System.out.println("Start of main");
//Schedule a job for the event-dispatching thread:
//creating and showing this application's GUI.
FrameDemo.createAndShowGUI();
[Code] .......
View Replies
View Related