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 2 of 2

Thread: Help with adjusting a program. NEw to java!!!!!

  1. #1
    Banned
    Join Date
    Sep 2009
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Help with adjusting a program. NEw to java!!!!!


    Hey everyone below is the code i have and i need help with altering it. First thing is to change the do-while loop to a for loop and let the user enter COMMISSION_SOUGHT instead of fixing it as a constant.



    import java.util.*;
     
    public class SalesAmount {
     
    	public static void main(String [] args) {
     
    	final double COMMISSION_SOUGHT = 25000;
    	final double INITIAL_SALES_AMOUNT = 0.01;
    	double commission = 0;
    	double salesAmount = INITIAL_SALES_AMOUNT;
     
    	do {
    		salesAmount += 0.01;
     
    		if (salesAmount >= 10000.01)
    			commission = 
    			5000 * 0.08 + 5000 * 0.1 + (salesAmount - 10000) * 0.12;
     
    		else if (salesAmount >= 5000.01)
    			commission = 5000 * 0.08 + (salesAmount - 5000) * 0.10;
     
    		else
    			commission = salesAmount * 0.08;
    		} while (commission < COMMISSION_SOUGHT);
     
    	System.out.println(
    		"The sales amount $" + (int) (salesAmount * 100) / 100.0 + 
    		"\nis needed to make a comission of $" + COMMISSION_SOUGHT);
    		}
     
    	}
    Last edited by Freaky Chris; September 27th, 2009 at 06:08 PM.


  2. #2
    Junior Member
    Join Date
    Sep 2009
    Posts
    22
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Help with adjusting a program. NEw to java!!!!!

    To get value from user, use the following code

    final double COMMISSION_SOUGHT=Double.parseDouble(args[0]);
    actually the "Double.parseDouble()" is used to convert input String type into Double. BUt i dont know how for this syntax works. If it does not work, use the following syntax:

    final int COMMISSION_SOUGHT=Integer.parseInt(args[0]);
    And to convert do while into for loop, try this:
    int i=0;
    for(i=0;commission < COMMISSION_SOUGHT;i++){
    salesAmount += 0.01;

    if (salesAmount >= 10000.01)
    commission =
    5000 * 0.08 + 5000 * 0.1 + (salesAmount - 10000) * 0.12;

    else if (salesAmount >= 5000.01)
    commission = 5000 * 0.08 + (salesAmount - 5000) * 0.10;

    else
    commission = salesAmount * 0.08;
    }
    But i am sure that this code wont do the exact work of ur original code. Coz, as u know,do while loop will be executed atleast once.

Similar Threads

  1. Convert Java Program to Java ME code
    By rinchan11 in forum Java ME (Mobile Edition)
    Replies: 1
    Last Post: October 5th, 2009, 11:18 PM
  2. Java Messenger Program?
    By MysticDeath in forum Java Networking
    Replies: 1
    Last Post: September 9th, 2009, 12:25 AM
  3. PLEASE HELP!!!! simple java program...
    By parvez07 in forum Object Oriented Programming
    Replies: 5
    Last Post: August 26th, 2009, 07:38 AM
  4. help with simple java program
    By parvez07 in forum Java Theory & Questions
    Replies: 4
    Last Post: August 25th, 2009, 08:19 AM
  5. Java Program Help
    By javakid93 in forum Java Theory & Questions
    Replies: 6
    Last Post: July 27th, 2009, 12:03 PM