Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 8 of 8

Thread: Need help with simple code

  1. #1
    Junior Member
    Join Date
    Jul 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Need help with simple code

    Hello all I could really use help with the following. . . I understand the logic behind programming but, I suck at Java syntax.

    • A salesperson will earn a fixed salary of $50,000.00.
    • A salesperson will also receive a commission as a sales incentive. Commission is a percentage of the salesperson’s annual sales. The current commission is 5%.
    • The total annual compensation is the fixed salary plus the commission earned.

    It has to meet the following requirements

    • The application should have (at least) two classes: an originally-written main class source code file and an originally-written subclass file that work in conjunction. Importing other Java library subclasses is encouraged.
    • There should be proper documentation (comments) in both source code files.
    • The application should ask the user to enter annual sales, and it should display the total annual compensation.

    Any and all help would be appreciated.


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    6,370
    My Mood
    Mellow
    Thanks
    254
    Thanked 786 Times in 771 Posts

    Default Re: Need help with simple code

    We can't write it for you. Make an effort and we can help. Apply the logic you think you understand and learn the Java syntax you're not confident in along the way. Use your textbook, class notes, and tutorials as needed.

  3. #3
    Junior Member
    Join Date
    Jul 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Need help with simple code

    This is an online class so there really are no class notes . . . If I was in a physical class it would probably a bit easier to grasp. I could write out psuedocode but I'm not sure how that will help me with creating a class in the actual Java language. I'm not looking for a handout, just a hand up. Thanks in advance.

  4. #4
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: Need help with simple code

    Quote Originally Posted by DreC32 View Post
    I could write out psuedocode but I'm not sure how that will help me with creating a class in the actual Java language
    Pseudocode would translate to any language, as it is just a step by step outline of what is necessary to solve the problem. Writing java to solve a problem can be difficult, but writing java to perform the steps of a given solution is much easier. Start with the pseudocode and move on from there

  5. #5
    Junior Member
    Join Date
    Jul 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Need help with simple code

    This is what I have so far . . . I'm Using NetBeans . . . I'm not sure if I have satisfied the class within a class requirements and the math is not responding like I need it to.

    /*
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    */
    package javaapplication2;

    /**
    *
    * @author crowder, andre
    */
    import java.util.Scanner;
    public class JavaApplication2 {

    /**
    * @param args the command line arguments
    */
    public static void main(String[] args)
    {
    Scanner in=new Scanner(System.in);
    double ast;
    double com;
    double total;
    com= .05;
    System.out.println("Please enter your annual sales total.");
    ast=in.nextDouble();
    total= ast*com;
    System.out.println("Your total compensation plus commission is " +total+ast);






    }
    }

    --- Update ---

    Okay I have made a couple more changes. I have not found a way to deal with the decimal place being too short or eliminate it all together. . . any help would be greatly appreciated. . . also I still don't know if I have satisfied the double class requirement. . . Lord know I didn't comment anything.

    /*
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    */
    package javaapplication2;

    /**
    *
    * @author crowder, andre
    */
    import java.util.Scanner;
    public class JavaApplication2 {

    /**
    * @param args the command line arguments
    */
    public static void main(String[] args)
    {

    Scanner in=new Scanner(System.in);
    double total;
    double com;
    double ast;
    double annual;
    com = .05;
    System.out.println("Please enter your annual sales total.");
    ast=in.nextInt();
    total= com*ast;
    annual= ast+total;
    System.out.println("Your total commission is " +total);
    System.out.println("Your total compensation plus commission is " +annual);
    }
    }

  6. #6
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: Need help with simple code

    Please use code tags when posting code. Assistance can be found on the Announcements page.

    Quote Originally Posted by DreC32 View Post
    don't know if I have satisfied the double class requirement. . .
    Did you write two classes, in two separate files? If so, maybe, and if not, then definitely not.

    What do you mean the decimal place is too short? Are you seeing rounding/truncation errors in the math? Please describe the problems you have left and ask specific questions about what you do not understand

  7. #7
    Member llowe29's Avatar
    Join Date
    Jul 2013
    Posts
    118
    My Mood
    Tired
    Thanks
    9
    Thanked 6 Times in 6 Posts

    Default Re: Need help with simple code

    Use system.out.printf();
    Here is the API
    Complete Printf for Java Format String Specification

  8. #8
    Member llowe29's Avatar
    Join Date
    Jul 2013
    Posts
    118
    My Mood
    Tired
    Thanks
    9
    Thanked 6 Times in 6 Posts

    Default Re: Need help with simple code

    Also it would be ast = in.NextDouble() not in.nextInt() because you declared ast as a double.

Similar Threads

  1. Looking for a simple code
    By Pipar in forum Java Theory & Questions
    Replies: 7
    Last Post: July 22nd, 2013, 02:12 PM
  2. Something wrong with really,really simple code.
    By Programmer142 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: December 5th, 2011, 08:01 AM
  3. Simple code, cant get it working.
    By Malmen in forum What's Wrong With My Code?
    Replies: 0
    Last Post: November 8th, 2011, 03:28 PM
  4. Need help with simple code
    By suxen in forum What's Wrong With My Code?
    Replies: 2
    Last Post: February 21st, 2011, 08:10 PM
  5. [SOLVED] Help with simple Applet code
    By that_guy in forum What's Wrong With My Code?
    Replies: 13
    Last Post: January 11th, 2011, 10:22 PM