-
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.
-
 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.
-
**********************************************************************
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);
-
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.
-
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.
-
 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.
-
-
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*/
}
-
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.
-
-
 Originally Posted by jose
thank you
You're welcome.
-
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
-
 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!
Similar Threads
-
By scott in forum Careers
Replies: 5
Last Post: 01-25-2008, 01:40 PM
-
By Kallahan in forum Java
Replies: 1
Last Post: 01-20-2003, 08:28 AM
-
By Novosoft in forum web.announcements
Replies: 0
Last Post: 02-14-2001, 03:50 AM
-
By Philip King in forum authorevents.appleman
Replies: 1
Last Post: 04-10-2000, 12:27 AM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks