Results 1 to 14 of 14
  1. #1
    rasmus07 is offline Member
    Join Date
    Feb 2010
    Posts
    7
    Rep Power
    0

    Question Need help with Max or min values!

    Hello!!
    Can anyone help me with this??

    * How does initalvalues of variable "min" and the variable "max" to the outcome
    * How does if-rates to the outcome(results)
    * How does for-loop to the outcome(results)

    the "outcome" I mean the way the code expects the minimum and maximum sales.

    What if this rate! How does it know why it is max or min value.
    Java Code:
    import java.util.Scanner;
    
        public class Sales
       {
           public static void main(String[] args)
          {
             final int SALESPEOPLE = 5;
             int[] sales = new int[SALESPEOPLE];
          
             int sum;
             int max = -1000;
             int min = 1000;
             int personMax=0;
             int personMin=0;
             int newValue=0;
             int newValue2=0;
             int top=1;
             int above=0;
          	
             Scanner scan = new Scanner(System.in);
             for (int i=0; i<sales.length; i++)
             {
                int count = i; 
                count += 1; 
                System.out.print("Ange försäljning för säljare " + count + ": ");
                sales[i] = scan.nextInt();
             }
             System.out.print("---------------------");
          
             System.out.println("\nFörsäljarna Säljer:");
             System.out.println("--------------------");
             sum = 0;
          	
             for (int i=0; i<sales.length; i++)
             {
                int count = i; 
                count += 1;	
             	//Vad gör den här if satsen!!! Hur vet den varför den blir max eller min värde.
                if(sales[i]>max)
                {
                   max = sales[i];
                   personMax= i+1;
                }
                if(sales[i]<min)
                {
                   min = sales[i];
                   personMin= i+1;
                }
                System.out.println("Försäljarens nummer är:" + count + " = " + sales[i] + "$ ");
                sum += sales[i];
             
             }
             System.out.println("\nDen Totala försäljningen är: " + sum + "$ ");
             System.out.println("Den genomsnittliga försäljningen är: " + sum/SALESPEOPLE + "$ ");
             System.out.println("Den största försäljningen är: " + max + "$ av Säljare " + personMax );
             System.out.println("Den minsta försäljningen är: " + min + "$ av Säljare " + personMin );
             System.out.println("Ange ett nummer:");
             newValue= scan.nextInt();
          
             for (int i=0; i<sales.length; i++)
             {
                if (sales[i] > newValue)
                {
                   newValue2 = i+1;
                   top = sales[i];
                   System.out.println("id: "+newValue2 + " med "+ top+"$.");
                   above++;
                }
             }
             System.out.println("Människor som överstiger detta värde är: " +above+ "st " );  
          }
       }
    Last edited by Eranga; 03-03-2010 at 01:44 PM. Reason: code tags added

  2. #2
    Addez is offline Senior Member
    Join Date
    Aug 2009
    Posts
    294
    Rep Power
    0

    Default

    Could you use english next time please?
    I mean serious, I couldnt understand any of the questions (maybe Its just me)
    Idk what ur asking, but I can read the swedish u wrote, at this point:
    Java Code:
    //Vad gör den här if satsen!!! Hur vet den varför den blir max eller min värde.
    if(sales[i]>max)
    {
    max = sales[i];
    personMax= i+1;
    }
    the max value will be equal to the last persons value that exceeded previously last persons value.
    For example, we have 3 people, A,B and C.
    As value is 500
    Bs value is 200
    and Cs value is 800

    First a comes in, he is bigger than max (500>-1000)
    When he have been there, the max value equals to his value and the personMax value gets one more point.
    Then B comes, he is not bigger than max (200<500) so nothing happens
    Then C comes, he is bigger and the max value equals now to 700, which is his value. and the personMax gets one more point.

    Outcome: max = 700 ; personMax = 2

    Hope this helps :D

  3. #3
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

  4. #4
    rasmus07 is offline Member
    Join Date
    Feb 2010
    Posts
    7
    Rep Power
    0

    Default

    What question do you not understand Addez??

    Hello!!
    Can anyone help me with this??

    * How does initalvalues of variable "min" and the variable "max" to the outcome
    * How does if-rates to the outcome(results)
    * How does for-loop to the outcome(results)

    the "outcome" I mean the way the code expects the minimum and maximum sales.

    What if this rate! How does it know why it is max or min value.
    Java Code:
    import java.util.Scanner;
    
    public class Sales
    {
    public static void main(String[] args)
    {
    final int SALESPEOPLE = 5;
    int[] sales = new int[SALESPEOPLE];
    
    int sum;
    int max = -1000;
    int min = 1000;
    int personMax=0;
    int personMin=0;
    int newValue=0;
    int newValue2=0;
    int top=1;
    int above=0;
    
    Scanner scan = new Scanner(System.in);
    for (int i=0; i<sales.length; i++)
    {
    int count = i; 
    count += 1; 
    System.out.print("Ange försäljning för säljare " + count + ": ");
    sales[i] = scan.nextInt();
    }
    System.out.print("---------------------");
    
    System.out.println("\nFörsäljarna Säljer:");
    System.out.println("--------------------");
    sum = 0;
    
    for (int i=0; i<sales.length; i++)
    {
    int count = i; 
    count += 1; 
    
    if(sales[i]>max)
    {
    max = sales[i];
    personMax= i+1;
    }
    if(sales[i]<min)
    {
    min = sales[i];
    personMin= i+1;
    }
    System.out.println("Försäljarens nummer är:" + count + " = " + sales[i] + "$ ");
    sum += sales[i];
    
    }
    System.out.println("\nDen Totala försäljningen är: " + sum + "$ ");
    System.out.println("Den genomsnittliga försäljningen är: " + sum/SALESPEOPLE + "$ ");
    System.out.println("Den största försäljningen är: " + max + "$ av Säljare " + personMax );
    System.out.println("Den minsta försäljningen är: " + min + "$ av Säljare " + personMin );
    System.out.println("Ange ett nummer:");
    newValue= scan.nextInt();
    
    for (int i=0; i<sales.length; i++)
    {
    if (sales[i] > newValue)
    {
    newValue2 = i+1;
    top = sales[i];
    System.out.println("id: "+newValue2 + " med "+ top+"$.");
    above++;
    }
    }
    System.out.println("Människor som överstiger detta värde är: " +above+ "st " ); 
    }
    }
    Last edited by Eranga; 03-03-2010 at 01:44 PM.

  5. #5
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,430
    Rep Power
    7

    Default

    * How does initalvalues of variable "min" and the variable "max" to the outcome
    What?
    * How does if-rates to the outcome(results)
    What?
    * How does for-loop to the outcome(results)
    What?

    And still no code tags.
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

  6. #6
    rasmus07 is offline Member
    Join Date
    Feb 2010
    Posts
    7
    Rep Power
    0

    Default

    How do I enter the code tags. I can not explain it any other way! Excuse me!

  7. #7
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,430
    Rep Power
    7

    Default

    [CODE&#93;Your code goes here[/CODE&#93;
    Last edited by PhHein; 03-03-2010 at 01:50 PM.
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

  8. #8
    Addez is offline Senior Member
    Join Date
    Aug 2009
    Posts
    294
    Rep Power
    0

    Default

    Quote:
    * How does initalvalues of variable "min" and the variable "max" to the outcome

    What?

    Quote:
    * How does if-rates to the outcome(results)

    What?

    Quote:
    * How does for-loop to the outcome(results)

    What?
    Ty, this is exacly what I dont understand! Thanks phein XD
    And even if you could speak english, I would not want to help you anymore.

  9. #9
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,305
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by PhHein View Post
    What?
    Don't you understand anything? The OP wants to know how they do to the outcome(result). That's easy, the answers are fish, green and yes in that particular order. Glad to help.

    kind regards,

    Jos ;-)

  10. #10
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,430
    Rep Power
    7

    Default

    Quote Originally Posted by JosAH View Post
    Don't you understand anything? The OP wants to know how they do to the outcome(result). That's easy, the answers are fish, green and yes in that particular order. Glad to help.

    kind regards,

    Jos ;-)
    Huh? No 42 involved :confused:
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

  11. #11
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,305
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by PhHein View Post
    Huh? No 42 involved :confused:
    No, that would've been the answer to the fourth (the ultimate) question. Next time please pay a bit of attention ;-)

    kind regards,

    Jos

  12. #12
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,430
    Rep Power
    7

    Default

    Oooh, ok. Sorry, Jos.
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

  13. #13
    rasmus07 is offline Member
    Join Date
    Feb 2010
    Posts
    7
    Rep Power
    0

    Lightbulb

    Addez, sure I can English. I can not help it if you do not understand and I have not asked you for help. If you do not want to help so you do not need it. There are many who can and want to help me.

  14. #14
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,430
    Rep Power
    7

    Default

    Quote Originally Posted by rasmus07 View Post
    Addez, sure I can English.
    It seems you constantly forget verbs. That's why people have trouble to understand you.
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

Similar Threads

  1. HashMap contains all values but doesn't show all values
    By xcallmejudasx in forum New To Java
    Replies: 3
    Last Post: 05-10-2009, 11:35 PM
  2. Byte Values
    By javaplus in forum New To Java
    Replies: 1
    Last Post: 06-23-2008, 12:08 AM
  3. Replies: 0
    Last Post: 05-22-2008, 10:53 AM
  4. wrong values
    By mark-mlt in forum New To Java
    Replies: 8
    Last Post: 04-25-2008, 11:11 AM
  5. Replies: 4
    Last Post: 04-15-2008, 01:04 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
  •