Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

Having problems with a beginner homework question

java beginner homework

This topic has been archived. This means that you cannot reply to this topic.
8 replies to this topic

#1 Doorhandle

Doorhandle

    CC Lurker

  • New Member
  • Pip
  • 5 posts

Posted 30 January 2015 - 02:57 PM

Hi all, I am in my first semester of learning java and am having some difficulties with a homework question. It reads as follows:

 

Write a program that reads the following information and prints a payroll statement: Employee’s name, Number of hours worked in a week, Hourly pay rate, Federal tax withholding rate, State tax withholding rate. Write this program in two versions: Using console for input and output, Using Dialog boxes for input and output.

 

We are learning about Strings, JOptionPane, character operators, and ASCII and Unicode characters. I am assuming I have to use this knowledge in some way...But I really don't know how to get started. Once I get going I think I can figure my way out, but I am really hoping someone can go over what I'll be using here. Thank you.

 

EDIT: here is all I can come up with at the moment, like I said I am pretty stuck and not sure what to do right now.

 

import java.util.Scanner;
public class Payroll {
  Scanner in=new Scanner(System.in);
  double statetax, fedtax, hours, rate;
  String name=Smith;
  String statetax=5%
  String fedtax=30%
  String hours=40
  String rate=10


Edited by Doorhandle, 30 January 2015 - 03:11 PM.


#2 divinity03

divinity03

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 117 posts

Posted 30 January 2015 - 03:01 PM

where is your code, this forum is about helping with homework not doing your homework for you. show what you have come up with and maybe you will recieve help



#3 Doorhandle

Doorhandle

    CC Lurker

  • New Member
  • Pip
  • 5 posts

Posted 30 January 2015 - 03:02 PM

I don't have any code...Like I said, I don't even know where to start. I am not asking for people to do my work for me, I am asking what tools(like scanner, JOptionPane, etc) I should be using for this particular problem, or just a general outline.


Edited by Doorhandle, 30 January 2015 - 03:05 PM.


#4 BlackRabbit

BlackRabbit

    CodeCall Legend

  • Expert Member
  • PipPipPipPipPipPipPipPip
  • 3871 posts

Posted 31 January 2015 - 09:17 AM

OK, a couple of hints:

 

About strings:  When you assign a value to a string, it must be enclosed by ""

 

like this:

String name=Smith;
  String statetax="5%";
  String fedtax="30%";
 
//  but if you will actually use those values as numbers, for calculus, you
// need to declare them as integers.
 
  int hours=40;
  int String rate=10;

 

 

You should take a look at our Java resources post, particularly at the new user tutorials, to get started with Java.



#5 Doorhandle

Doorhandle

    CC Lurker

  • New Member
  • Pip
  • 5 posts

Posted 31 January 2015 - 02:14 PM

Thanks so much, I ended coming up with a very slopper looking code that ended up working for me but I know I could make it much more efficient, and I will work on that. Thanks!



#6 Doorhandle

Doorhandle

    CC Lurker

  • New Member
  • Pip
  • 5 posts

Posted 31 January 2015 - 02:52 PM

Ok looks like ive got a bit of another problem now... I am getting the error "{" expected, here is what Ive got now:

import javax.swing.JOptionPane;
import java.util.Scanner;
public class PayrollJOptionPane;{
  Scanner in=new Scanner(System.in);
  double statetax, fedtax, hours, rate;
  System.out.println("Please enter an employee name:");
  name = in.nextline();
  System.out.println("Please enter the hours worked by " + name);
  hours = in.nextDouble();
  System.out.println("Please enter hourly wage for" + name);
  rate = in.nextDouble();
  System.out.println.("Please enter state tax rate");
  statetax = in.nextDouble();
  System.out.println("Please enter federal tax rate");
  fedtax = in.nextDouble();
  double netpay = hours * rate;
  double taxpaid = (netpay * fedtax) * statetax;
  double grosspay = netpay - taxpaid;
  System.out.println("Hours worked by" + name + ":" + hours);
  System.out.println("Net pay for" + name + ":" + netpay);
  System.out.println("Taxes paid by" + name + ":" + taxpaid);
  Systemout.println("Gross pay for" + name + ":" + grosspay);
    
  
  
  public static void main(String[] args) { 
    
  }


#7 PBJ

PBJ

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 176 posts

Posted 31 January 2015 - 02:59 PM

@doorhandle

I'd suggest using FindBugs with your respective IDE.



#8 Doorhandle

Doorhandle

    CC Lurker

  • New Member
  • Pip
  • 5 posts

Posted 31 January 2015 - 08:22 PM

I just downloaded it but I have no clue how to start using it.



#9 PBJ

PBJ

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 176 posts

Posted 02 February 2015 - 04:01 PM

@doorhandle

Here is the manual for FindBugs, please select the option most appropriate for your setup. Assuming your using eclipse, there is an add-on for FindBugs.






Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download