DevX Home Today's Headlines   Articles Archive   Tip Bank   Forums

1. Registered User
Join Date
Aug 2005
Posts
9

## Programming asissitance

I am a beginner and I am having trouble understanding java. I need to write a program that recieved inputs of numbers worked and out puts
pay:\$.01 on day 1. Total Salary \$.01
pay:\$.02 on day 2. Total Salary \$.03
pay:\$.04 on day 3. Total Salary \$.07
ECT. Can any one assist me in writting this program.

2. Registered User
Join Date
Jul 2005
Location
the Netherlands
Posts
128
Originally Posted by jose
I am a beginner and I am having trouble understanding java. I need to write a program that recieved inputs of numbers worked and out puts
pay:\$.01 on day 1. Total Salary \$.01
pay:\$.02 on day 2. Total Salary \$.03
pay:\$.04 on day 3. Total Salary \$.07
ECT. Can any one assist me in writting this program.
Sure, you can get help here. But I don't think there are a lot of people willing to write the programm for you.
So let's see what you got sofar and tell us what it is you don't understand.

3. Registered User
Join Date
Aug 2005
Posts
9
**********************************************************************
This class has two methods. The output method and the sequence of numbers
used for this class.***************************************************/
/* In this project I will have 30 days of pay and total sallary doubleing
every day by .02 increasing the sallary by the total pay for the day.*/

import java.util.*;
import java.text.DecimalFormat
/*This will import a decimal format to the pay and total salary*/

public class PenniesForPay
{
/**We will start by identifying the methods**/
public static void main (String[] args)
{
Scanner scannerObject = new Scanner(System.in);

/*Variables*/

int payPerDay;
int totalSalary;
int days;

payPerDay = .01 * .02;
days = 40;
totalSalary = payPerDay + totalSalary;

Systemprintln(pay: "\$" + on day "days". + totalSalary);

4. Registered User
Join Date
Jul 2005
Location
the Netherlands
Posts
128
Code:
```/*Variables*/
int payPerDay;
int totalSalary;
int days;

payPerDay = .01 * .02;
days = 40;
totalSalary = payPerDay + totalSalary;

Systemprintln(pay: "\$" + on day "days". + totalSalary);```
Ok, payPerDay is an int and you can't use decimals there, only whole numbers. And why do you multiply values? Isn't it a fixed amount someone would get for a days work?

Wouldn't totalSalary be the number of days times payPerDay.

Also don't forget semicolons after every line!
And ininitiase your variables like this:
Code:
```int payPerDay = 0;
int totalSalary = 0;
int days = 0;```
After you did all that try printing it out like this:
Code:
`System.out.println("Pay per day: "+payPerDay+", and worked: "+days+" number of days, so the total is: "+totalSalary);`
It's alse a wise thing to read some Java tutorials:
http://java.sun.com/docs/books/tutorial/

Good luck.

5. Registered User
Join Date
Aug 2005
Posts
9
Thanks I will try that and I will read the tutorials. I will do my best to learn it but it is some times hard to understand.

6. Registered User
Join Date
Jul 2005
Location
the Netherlands
Posts
128
Originally Posted by jose
Thanks I will try that and I will read the tutorials. I will do my best to learn it but it is some times hard to understand.
Everything is hard at the beginning. One step at a time.
Do post if you get stuck.

Good luck.

7. Registered User
Join Date
Aug 2005
Posts
9
I will, thanks

8. Registered User
Join Date
Aug 2005
Posts
9
I can't come up with the pay per day and total salary. can any one help?
below is my program. Can any one assist me.

/**********************************************************************
This class has two methods. The output method and the sequence of numbers
used for this class.***************************************************/
/* In this project I will have 30 days of pay and total sallary doubleing
every day by .02 increasing the sallary by the total pay for the day.*/

import java.util.*;
import java.text.DecimalFormat;
/*This will import a decimal format to the pay and total salary*/

public class penniesforpay078
{
/**We will start by identifying the methods**/
public static void main (String[] args)
{
Scanner scannerObject = new Scanner(System.in);

/*Variables*/

int count;
int payPerDay = 0;
int days = 0;
int totalSalary = 0;
double payday = 0;

/*This count would increment the days by one each time
the loop will stor the number.*/

count=1;

for(days=1; days<=40;days++)

{
if(payPerDay >= 0.00)

{
DecimalFormat twoDigits = new DecimalFormat ("0.00");
double payDay = 0.01;
payday = payPerDay;
totalSalary += payPerDay;

}

else

{
payPerDay *= 2;
totalSalary += payPerDay;

}

/*The println is made to print what ever you ask it to.*/

System.out.println("pay: \$ "+payPerDay+" on day: "+days+". Total Salary \$ "+totalSalary);
System.out.println("\n");

} /*end of method penniesForPay078*/

} /*end of class penniesForPay078*/
}

9. Registered User
Join Date
Jul 2005
Location
the Netherlands
Posts
128
Hey Jose,

I see you've put a lot of effort in it up till now. But I think you're getting a bit of-track now. If I read through your first post, you said you needed the following output:
pay:\$.01 on day 1. Total Salary \$.01
pay:\$.02 on day 2. Total Salary \$.03
pay:\$.04 on day 3. Total Salary \$.07

But I see you do a lot more then necessary. The following code will do just that what you described:
Code:
```import java.text.DecimalFormat;

public class penniesforpay078 {

// main method
public static void main (String[] args) {

// variables
int numOfDays = 30;
double payPerDay = 0.01;
double totalSalary = 0.0;

for(int i = 1; i <= numOfDays; i++) {

totalSalary = totalSalary + payPerDay;
DecimalFormat df = new DecimalFormat("0.00");
System.out.println("pay:\$ "+payPerDay+" on day "+i+". Total Salary \$"+df.format(totalSalary));
payPerDay = payPerDay * 2;

} // end for loop

} // end main

} // end class penniesforpay078```
Read it through carefully and try to understand what's happening. Good luck finishing your assignment.

10. Registered User
Join Date
Aug 2005
Posts
9
thank you

11. Registered User
Join Date
Jul 2005
Location
the Netherlands
Posts
128
Originally Posted by jose
thank you
You're welcome.

12. Registered User
Join Date
Aug 2005
Posts
9
I modified it a little and it still worked thank you for the help. I will be on here a lot and I will be reading the tutorials

13. Registered User
Join Date
Jul 2005
Location
the Netherlands
Posts
128
Originally Posted by jose
I modified it a little and it still worked thank you for the help. I will be on here a lot and I will be reading the tutorials
Ok, well done Jose.
Happy programming!

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•

 FAQ Latest Articles Java .NET XML Database Enterprise