Results 1 to 12 of 12
  1. #1
    smalljynx is offline Member
    Join Date
    May 2015
    Posts
    3
    Rep Power
    0

    Default Help with Homework

    I have the code built correctly I believe but it is still not looping. Can anyone help me please, I do not get this at all.

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,422
    Blog Entries
    7
    Rep Power
    28

    Default Re: Help with Homework

    It's Monday, so no crystal balls are allowed in the building; show us the (relevant) code if you want to get help.

    kind regards,

    Jos
    Build a wall around Donald Trump; I'll pay for it.

  3. #3
    smalljynx is offline Member
    Join Date
    May 2015
    Posts
    3
    Rep Power
    0

    Default Re: Help with Homework

    Here is what I have so far. I have dissected this code a million times and this is what I am starting over with now. How do I get to loop to 100K, 105K,110K etc?


    import javax.swing.*;
    import java.text.DecimalFormat;
    import java.util.Scanner; //Use for input from comamndline.
    import java.text.NumberFormat; // Use to control decimal output
    import salescommission.Compensation;
    public class Sales {

    /**
    * @param args the command line arguments
    */
    public static void main(String[] args)
    {
    DecimalFormat dol = new DecimalFormat ("#,###,##0.00");
    Scanner input = new Scanner (System.in); //object to read commandline input
    System.out.print("Please enter the salesperson's total sales: "); // prompt the user to enter sales on the commandline
    Compensation c = new Compensation(); //create object form the Compensation class
    c.setSalary(35000); // initialize the Salary to 35000
    c.setCommission(8.0); // initialize the commission to 8 percent
    c.setSales(input.nextDouble()); //read the sales form the commandline
    System.out.println("Salesperson's total compensation: $" + dol.format(c.getCompensation())); //print results of annual compensation formatted as $

    int sum = 100000;
    int salesAmount = 100000;
    for (int i = salesAmount; i <= salesAmount*1.5; i=+5000)
    sum += i;
    System.out.println(sum);

    }
    }

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    12,059
    Rep Power
    26

    Default Re: Help with Homework

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  5. #5
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,422
    Blog Entries
    7
    Rep Power
    28

    Default Re: Help with Homework

    For starrters:

    1) put [code] ... [/code] tags around your code for readabilty; (that's what Darryl was trying to say to you)
    2) I don't see a loop anywhere in your code (a for loop maybe?)

    kind regards,

    Jos
    Build a wall around Donald Trump; I'll pay for it.

  6. #6
    Artemia is offline Member
    Join Date
    May 2015
    Location
    Netherlands
    Posts
    39
    Rep Power
    0

    Default Re: Help with Homework

    if I'm reading it correctly
    this is your for loop
    Java Code:
    int sum = 100000;
    int salesAmount = 100000;
    for (int i = salesAmount; i <= salesAmount*1.5; i=+5000)
    sum += i;
    System.out.println(sum);
    shouldn't it be
    Java Code:
    int sum = 100000;
    int salesAmount = 100000;
    for (int i = salesAmount; i <= salesAmount*1.5; i=+5000){
        sum += i;
        System.out.println(sum);
    }
    the curly brackets and spaces before the content of the loop are basically there to say 'we are part of this loop and have no connection to anything outside of it' right?
    so it's important to have them there
    Last edited by Artemia; 05-25-2015 at 10:32 PM.

  7. #7
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    14

    Default Re: Help with Homework

    That only depends on whether the OP wanted the final sum or intermediate sums. In any event, that was not the problem. The loop is infinite because i never changes. The update of i in the for loop is incorrect. The OP keeps setting i to 5000. It should be i += 5000, not i =+5000;

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  8. #8
    smalljynx is offline Member
    Join Date
    May 2015
    Posts
    3
    Rep Power
    0

    Default Re: Help with Homework

    Correcting the brackets and placing the addition sign in proper place worked. Thanks everyone for your help and time

  9. #9
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    5,114
    Rep Power
    12

    Default Re: Help with Homework

    Quote Originally Posted by JosAH View Post
    It's Monday, so no crystal balls are allowed in the building; show us the (relevant) code if you want to get help.
    Only on Monday? You should have a word with the doorman then as he confiscates them on any day of the week.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  10. #10
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,422
    Blog Entries
    7
    Rep Power
    28

    Default Re: Help with Homework

    Quote Originally Posted by gimbal2 View Post
    Only on Monday? You should have a word with the doorman then as he confiscates them on any day of the week.
    Erm,yes he owns a second hand crystal ball shop downtown; except for a few scratches here and there, they're fine balls; that's were I got mine recently ...

    kindest regards,

    Jos
    Build a wall around Donald Trump; I'll pay for it.

  11. #11
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    5,114
    Rep Power
    12

    Default Re: Help with Homework

    I thought I recognized that particular shade of pink. Well have fun with it.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  12. #12
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    12,059
    Rep Power
    26

    Default Re: Help with Homework

    They look red to me, all three of them
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Homework Help
    By EZ-Ed in forum New To Java
    Replies: 3
    Last Post: 04-10-2012, 07:11 PM
  2. Homework help
    By noobster in forum New To Java
    Replies: 13
    Last Post: 10-31-2010, 09:02 PM
  3. Homework Help
    By Kyoto in forum New To Java
    Replies: 2
    Last Post: 07-30-2010, 12:30 AM
  4. Homework help please
    By chick in forum New To Java
    Replies: 22
    Last Post: 03-19-2010, 07:39 AM
  5. Please Help with Homework
    By theuser in forum Advanced Java
    Replies: 2
    Last Post: 07-30-2009, 03:37 PM

Posting Permissions

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