tools's Profile User Rating: -----

Reputation: 1 Apprentice
Group:
Active Members
Active Posts:
68 (0.09 per day)
Joined:
26-September 12
Profile Views:
40,760
Last Active:
User is offline Jul 02 2014 03:58 AM
Currently:
Offline

Previous Fields

Country:
DK
OS Preference:
Mac
Favorite Browser:
Chrome
Favorite Processor:
Intel
Favorite Gaming Platform:
XBox
Your Car:
Mitsubishi
Dream Kudos:
0
Icon   tools has not set their status

Posts I've Made

  1. In Topic: How do I sort an arraylist of objects by a property of the objects

    Posted 14 Feb 2014

    Try publishing the Item class


    EDIT: sorry for late answer I am living in a different time zone
  2. In Topic: RoR: path will not load by url argument

    Posted 13 Feb 2014

    #2 sepp2k thank you I will take a look on it actually I think I chaging it to the create method
  3. In Topic: How do I sort an arraylist of objects by a property of the objects

    Posted 13 Feb 2014

    ArrayList<Item> items = new ArrayList<Item>();
    ArrayList<Item> costSorted = new ArrayList<Item>(items);
    Collections.sort(costSorted); 
    


    If you want to keep an unsorted list
  4. In Topic: How do I sort an arraylist of objects by a property of the objects

    Posted 13 Feb 2014

    Use the Comparable interface

    so your compareTo method in your Item class:
    public int compareTo(Item item){
      if(item.cost == this.cost){
        return 0;
      }else if(this.cost < item.cost){
        return -1
      }else{
        return 1
      }
    }
    
    
    


    and then the sort method from the ArrayList class should work
  5. In Topic: Having trouble with arrays and user input!

    Posted 13 Feb 2014

    AS #2 Golossos sugest a while loop, but I would like to recommend this structure instead

    You write now where if ther is a max of 10 scores so I would use an ArrayList
    
    ArrayList<int> table = new ArrayList<int>();
    
    int curret_score;
    
    System.out.print("Enter number: ");
    while( (current_score = kbReader.nextInt()) >= 0){
      if(current_number <= 10){
        table.add(current_score);
      }else{
        System.out.println("Number has to be less than or equal to 10");
      }
      System.out.print("Enter number: ");
    }
    
    


    Then the average let say you have a mehtod for calculating the sum of scores in the array:

    int sumOfScores(ArrayList<int> list){
      int sum = 0;;
      for(int i = 0; i < list.size(); i++){
        sum += list.get(i);
      }
      return sum;
    }
    
    


    If you don't know += is a compound assignment operator, where you just add sum with the new number instead of sum = sum + list.get(i)


    Then you can say:
    double average = sumOfScores(table) / table.size(); //or size()-1 don't recall
    
    


    - Hope I could help

My Information

Member Title:
D.I.C Head
Age:
Age Unknown
Birthday:
Birthday Unknown
Gender:
Location:
Denmark
Full Name:
Lars Nielsen
Years Programming:
5
Programming Languages:
ColdFusion, Ruby, Java, Objectiv C, C++ & C#

Contact Information

E-mail:
Private

Friends

tools hasn't added any friends yet.

Comments

tools has no profile comments yet. Why not say hello?