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

Thread: my High profitable items: 0 Bonus : $0.00 why??

  1. #1
    Junior Member
    Join Date
    Feb 2011
    Posts
    26
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default my High profitable items: 0 Bonus : $0.00 why??

    i have this much but i dont get why my high profitable items is 0 and bonus is 0...should be 1 and 20

    import java.util.Scanner;// program uses class Scanner
     
    	public class Assign4
    	{
    	    public static void main(String[] args)
    	    {
    	        new Assign4 ();
    	        Scanner input = new Scanner( System.in );
     
    	        double total; // sum of values
    	        double Commission=0; // Commission earned
    	        double earnings=0;// number with decimal point for average
    	        double bonus=0;// bonus amount for high value items
     
    	        total = 0; // initialize total
    	        int valueCounter = 0; // initialize loop counter
     
    	        bonus = 0; // initialize bonus
    	        int bonusCounter = 0; //initialize bonus counter
     
    	        System.out.print( "Enter item Value, or -1 to quit: " );
    	        double value = input.nextDouble();
     
    	        // loop until sentinel value read from user
    	        while ( value != -1 )
    	        {
    	            total = total + value; // add value to total
    	            valueCounter = valueCounter + 1; // increment counter
     
    	            // prompt for input and read next value from user
    	            System.out.print( "Enter item Value, or -1 to quit: " );
    	            value = input.nextDouble();
     
     
    	} // end while
     
    	// termination phase
    	// if user entered at least one amount...
    	if ( valueCounter != 0 )
    	{
    	    if ( value>=350.00 )
    	    {
    	        bonusCounter = bonusCounter + 1; // bonus counter
    	        // calculate commission with bonus earnings for high value item
    	        Commission = ((double) total /100)* 9+20;
    	        total = (double) total;
    	        earnings = (double)Commission + 200;
    	    }
    	    else if(value<350.00)
    	    {
    	        // calculate commission of total amount
    	        Commission = ((double) total /100)* 9;
    	        total = (double) total;
    	        earnings = (double)Commission + 200;
    	    }
    	}
    	// display everything
    	System.out.printf("Items Sold : " + valueCounter);
    	System.out.printf("\nTotal Amount: $%.2f\n", total);
    	System.out.printf("Commission: $%.2f\n", Commission);
    	System.out.printf("High profitable items: " +bonusCounter);
    	System.out.printf("\nBonus : $%.2f\n", bonus);
    	System.out.printf("Earnings: $%.2f\n", earnings);
    	// end if
     
     
    	// end class Assign4
     
    	}
    	}


  2. #2
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default Re: my High profitable items: 0 Bonus : $0.00 why??

    double bonus=0; // bonus initialised to zero
    ....
    bonus = 0; // totally pointless line of code
    Where in the rest of your code do you change the value of bonus?

  3. #3
    Junior Member
    Join Date
    Feb 2011
    Posts
    26
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: my High profitable items: 0 Bonus : $0.00 why??

    i dont get what ur asking

  4. #4
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default Re: my High profitable items: 0 Bonus : $0.00 why??

    You say that the bonus variable should have the value 20. But the bonus variable is used twice in the code posted, both times it is assigned the value 0. Therefore it is impossible for it to have a value of 20.

Similar Threads

  1. Eclipse is always locked [High CPU & RAM usage]
    By talha06 in forum Java IDEs
    Replies: 4
    Last Post: March 16th, 2010, 10:07 AM
  2. misalignment of list items
    By venkyInd in forum AWT / Java Swing
    Replies: 2
    Last Post: March 15th, 2010, 08:33 AM
  3. How to get a sum value from items listed in array ?
    By makarov in forum Loops & Control Statements
    Replies: 0
    Last Post: January 6th, 2010, 06:11 PM
  4. Senior Development Manager - Core Java/J2SE - £80-90K + £10K Bonus
    By iNeedJavaGurus in forum Paid Java Projects
    Replies: 0
    Last Post: September 18th, 2009, 10:00 AM
  5. Different operation on Array
    By jempot in forum Collections and Generics
    Replies: 4
    Last Post: January 27th, 2009, 06:07 AM