The Artima Developer Community
Sponsored Link

Java Answers Forum
Just Started Java... need some help please!

1 reply on 1 page. Most recent reply: Mar 10, 2008 4:10 AM by shipra kumar

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
Cameron Miller

Posts: 1
Nickname: ch0de
Registered: Mar, 2008

Just Started Java... need some help please! Posted: Mar 3, 2008 7:11 AM
Reply to this message Reply
Advertisement
Hello.... I am new to the world of programming... I need to know what is wrong with the code below and what I need to do to complete it... If you can, can you explain my errors?

Thank you very much in advance!

State Withholding Tax = 7.5%
Federal Witholding Tax = 28.0%
Dependent Deductions = 5.0%
Calculate Total Witholdings
Calculate take-home pay as salary minus total witholdings plus deductions.

// This program calculates an employee's take home pay.
public class Salary
{
public static void main(String args[])
{
double salary = 750.00;
double stateTax = 7.5;
double federalTax = 28.0;
double numDependents = 2;
double dependentDeduction = 5.0;
double totalWithholding;
double takeHomePay;

// Calculate state tax here.

System.out.println("State Tax: $" + stateTax);

// Calculate federal tax here.

System.out.println("Federal Tax: $" + federalTax);

// Calculate dependent deductions here.

System.out.println("Dependents: $" + dependentDeduction * numDependents);

// Calculate total withholding here.


// Calculate take home pay here.

System.out.println("Salary: $" + salary);
System.out.println("Take Home Pay: $" + salary - totalWithholdings + dependentDeduction);
System.exit(0);
}
}


shipra kumar

Posts: 3
Nickname: shipra31
Registered: Mar, 2008

Re: Just Started Java... need some help please! Posted: Mar 10, 2008 4:10 AM
Reply to this message Reply
There were some syntatical errors.
May be the following code can solve ur problem

2 things which i found missing were:
1) totalWithHoldings was not declared.
2)last print statement didnt have the necessary bracket

public class Salary
{
public static void main(String args[])
{
double salary = 750.00;
double stateTax = 7.5;
double federalTax = 28.0;
double numDependents = 2;
double dependentDeduction = 5.0;
double totalWithholdings;
double takeHomePay;


// Calculate state tax here.
System.out.println("State Tax: $" + stateTax);

// Calculate federal tax here.
System.out.println("Federal Tax: $" + federalTax);

// Calculate dependent deductions here.
System.out.println("Dependents: $" + dependentDeduction * numDependents);

// Calculate total withholding here.
totalWithholdings=50.00;

// Calculate take home pay here.
System.out.println("Salary: $" + salary);
System.out.println("Take Home Pay: $" + (salary - totalWithholdings + dependentDeduction));
System.exit(0);
}
}

Flat View: This topic has 1 reply on 1 page
Topic: Just Started Java... need some help please! Previous Topic   Next Topic Topic: Java class inheritance and exceptions

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use