473,398 Members | 2,188 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

need help with a program for school

someone check out this program and tell me what im doing wrong please...every time i fix some errors i get even more than before (right now theres 10). note that im a beginner/noob, and that this doesnt work when i click run java application, either. im not sure what exactly i should put in the main method either...

import javax.swing.*;
import java.text.*;

public class Salary
{
public static void main(String[] args)
{
double pay;
pay = getExp1();
pay = getExp2();
pay = getExp3();
finish();
}
public static int getYears()
{
boolean done = false;
int years = 0;
while (!done)
{

String strYears = JOptionPane.showInputDialog(null, "How many years have you worked here?", "Experience", JOptionPane.QUESTION_MESSAGE);

if (strYears == null) finish();

try
{
int years = Integer.parseInt(strYears);
if (years <= 0) throw new NumberFormatException();
else done = true;
}
catch(NumberFormatException e)
{
JOptionPane.showMessageDialog(null, "Your entry was not in the proper format.", "Error", JOptionPane.WARNING_MESSAGE);
}
}

String strHours = JOptionPane.showInputDialog(null, "How many hours have you worked?", "Hours worked", JOptionPane.QUESTION_MESSAGE);
double hours = Double.parseDouble(strHours);

if (years <= 5)
years = getExp1();
else if ((years > 5) && (years <= 10))
years = getExp2();
else if (years > 10)
years = getExp3();
}
public static int getExp1(int years, double hours)
{
double pay;

if (hours > 40)
pay = (16.00 * hours);
else
pay = (12.00 * hours);
return pay;
}
public static int getExp2(int years, double hours)
{
double pay;

if (hours > 40)
pay = (24.00 * hours);
else
pay = (16.00 * hours);
return pay;
}
public static int getExp3(int years, double hours)
{
double pay;

if (hours > 40)
pay = (37.50 * hours);
else
pay = (25.00 * hours);
return pay;
}
public static void output(double pay)
{
DecimalFormat twoDigits = new DecimalFormat("$#0.00");
JOptionPane.showMessageDialog(null, "Your gross pay is " + twoDigits.format(pay), "Gross Pay", JOptionPane.INFORMATION_MESSAGE);
}
public static void finish()
{
System.exit(0);
}
}

and heres the errors:
K:\School Rules!!!!!!!1!\Ch. 4\Salary.java:16: getExp1(int,double) in Salary cannot be applied to ()
pay = getExp1();
^
K:\School Rules!!!!!!!1!\Ch. 4\Salary.java:17: getExp2(int,double) in Salary cannot be applied to ()
pay = getExp2();
^
K:\School Rules!!!!!!!1!\Ch. 4\Salary.java:18: getExp3(int,double) in Salary cannot be applied to ()
pay = getExp3();
^
K:\School Rules!!!!!!!1!\Ch. 4\Salary.java:34: years is already defined in getYears()
int years = Integer.parseInt(strYears);
^
K:\School Rules!!!!!!!1!\Ch. 4\Salary.java:48: getExp1(int,double) in Salary cannot be applied to ()
years = getExp1();
^
K:\School Rules!!!!!!!1!\Ch. 4\Salary.java:50: getExp2(int,double) in Salary cannot be applied to ()
years = getExp2();
^
K:\School Rules!!!!!!!1!\Ch. 4\Salary.java:52: getExp3(int,double) in Salary cannot be applied to ()
years = getExp3();
^
K:\School Rules!!!!!!!1!\Ch. 4\Salary.java:62: possible loss of precision
found : double
required: int
return pay;
^
K:\School Rules!!!!!!!1!\Ch. 4\Salary.java:72: possible loss of precision
found : double
required: int
return pay;
^
K:\School Rules!!!!!!!1!\Ch. 4\Salary.java:82: possible loss of precision
found : double
required: int
return pay;
^
10 errors

Tool completed with exit code 1
Nov 8 '06 #1
5 2214
sicarie
4,677 Expert Mod 4TB
Trimmed quote:

public static void main(String[] args)
{
double pay;
pay = getExp1();
pay = getExp2();
pay = getExp3();
finish();
}

and heres the errors:
K:\School Rules!!!!!!!1!\Ch. 4\Salary.java:16: getExp1(int,double) in Salary cannot be applied to ()
pay = getExp1();
^
K:\School Rules!!!!!!!1!\Ch. 4\Salary.java:17: getExp2(int,double) in Salary cannot be applied to ()
pay = getExp2();
^
K:\School Rules!!!!!!!1!\Ch. 4\Salary.java:18: getExp3(int,double) in Salary cannot be applied to ()
pay = getExp3();
^
I can tell you that the first three errors are because you pass nothing to the getExp1(), getExp2(), and getExp3() methods, but I am curious about something, are you trying to create just this class (to include in another program), or is this a program all its own? (that will help decide what to do with those statements, if they should be deleted or not...)
Nov 8 '06 #2
Trimmed quote:



I can tell you that the first three errors are because you pass nothing to the getExp1(), getExp2(), and getExp3() methods, but I am curious about something, are you trying to create just this class (to include in another program), or is this a program all its own? (that will help decide what to do with those statements, if they should be deleted or not...)
its a program all on its own
Nov 9 '06 #3
sicarie
4,677 Expert Mod 4TB
its a program all on its own
Ok, so you are going to have all your input and output in the main portion. It looks like most of the stuff you want in main() is declared right below getYears(), down to getExp1() (and I'm pretty sure you can delete the pay = getExp() lines in main() right now - you already have it declared elsewhere). The double pay needs to be declared outside main().

Try making those changes, see what errors you are getting, if things are making a little more sense. The main() portion of the program is what you want to be executed, everything else is definitions to support and manipulate that main program.

Let me know how that looks and the error messages you get!
Nov 9 '06 #4
well nevermind now, i just got my teacher to help me out at the beginning of class today. i only had that error trapping thing for the getYears method and i was supposed to have it for hours too but i couldnt figure it out. so i just turned it in without it. there were also some precision errors i had to fix (changing the ints to doubles and whatnot).

but thanks anyways
Nov 9 '06 #5
sicarie
4,677 Expert Mod 4TB
well nevermind now, i just got my teacher to help me out at the beginning of class today. i only had that error trapping thing for the getYears method and i was supposed to have it for hours too but i couldnt figure it out. so i just turned it in without it. there were also some precision errors i had to fix (changing the ints to doubles and whatnot).

but thanks anyways
Yeah, it seemed like you had the idea, and almost all of the code, there were just a few little things here and there.
Nov 9 '06 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Elezar Simeon Papo | last post by:
Hello All, I have a tab separated input file (data.txt) in text format - the file looks like this SCHOOL DEPART1 DEPART2 DEPART3 Harvard Economics Mathematics Physics...
66
by: genestarwing | last post by:
QUESTION: Write a program that opens and read a text file and records how many times each word occurs in the file. Use a binary search tree modified to store both a word and the number of times it...
22
by: the_grove_man | last post by:
I purchased a book titled "Pro ASP.NET 2.0" to get up to speed on web stuff because I ususally do Windows Form Applications.. But in the first chapters I was reading this week it brought to mind...
10
by: preethamkumark | last post by:
- The program first creates a shared memory buffer containing an array of 20 integers. - Each slot of the buffer can have either 0 or 1, where 0 represents an empty slot, and 1 represents an...
5
by: shanknbake | last post by:
Here is my code. I've noted where the program crashes. I'm doing this program as a project for school. //cqueue.h file //HEADER FILE http://rafb.net/paste/results/Nh0aLB77.html...
3
by: dreams | last post by:
Hi every one :) would any one help me in this program: I have a base class called "Person" and two derived classes "Student" and "teacher" i have a function in class Student called getStudents...
0
by: Mary | last post by:
First of all, I want to thank all of you who post out here regularly. I have learned so much over the last couple of years! During my 10 years as a Cobol programmer, working with dozens of other...
1
by: muld | last post by:
I've inherited a database system designed to calculate sickness absence statistics. There is a main table with an employee ID which also holds the number of days worked by that person in a year ....
1
by: 9107you | last post by:
I just started the course and this crazy teacher wants me to do this hard ass question The government of Mississauga has asked you to write a program that would calculate taxes for Mississauga...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.