Programming asissitance


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 13 of 13

Thread: Programming asissitance

  1. #1
    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. #2
    Join Date
    Jul 2005
    Location
    the Netherlands
    Posts
    128
    Quote 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. #3
    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. #4
    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. #5
    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. #6
    Join Date
    Jul 2005
    Location
    the Netherlands
    Posts
    128
    Quote 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. #7
    Join Date
    Aug 2005
    Posts
    9
    I will, thanks

  8. #8
    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. #9
    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. #10
    Join Date
    Aug 2005
    Posts
    9
    thank you

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

  12. #12
    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. #13
    Join Date
    Jul 2005
    Location
    the Netherlands
    Posts
    128
    Quote 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

  1. How can I get a programming job?
    By scott in forum Careers
    Replies: 5
    Last Post: 01-25-2008, 02:40 PM
  2. initial Java programming
    By Kallahan in forum Java
    Replies: 1
    Last Post: 01-20-2003, 09:28 AM
  3. Outsource your Java & C++ programming to Novosoft!
    By Novosoft in forum web.announcements
    Replies: 0
    Last Post: 02-14-2001, 04:50 AM
  4. Replies: 1
    Last Post: 04-10-2000, 01: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
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center