Results 1 to 3 of 3
  1. #1
    MichaelSpame is offline Member
    Join Date
    Jul 2012
    Posts
    1
    Rep Power
    0

    Default Ordering Inputted Java Values

    Hello,

    I am trying to make a prioritizer that asks for a number of values from the user using JOptionPane. The program uses a simple algorithm to calculate a numerical value. The higher the value, the more important it is to do a certain task.

    To assist in the recognition and ordering of each task, I asked for the name (nameOfTask). This is when it became difficult. I wanted to attach a numerical value to the String nameOfTask so that when I output the tasks in order of importance only the String nameOfTask is shown. I do not want the numerical value associated with that name to be shown. Am I approaching this incorrectly?

    The main objective, if I haven't made this clear, is to order these String variables based on a numerical value.

    So far, I have coded so that a numerical value can be identified but I don't know where to go from there. Here is an oversimplified version of my code:

    Java Code:
        String nameOfTask;
        double importanceOfTask;
        double amountOfTime;
        double total;
    
    
    public void calculatePriority()
    {
            this.nameOfTask = JOptionPane.showInputDialog("What is the task? ");
            
            String amountOfTime = JOptionPane.showInputDialog("How many minutes will the task take you? ");
            this.amountOfTime = Double.parseDouble(amountOfTime);
            
            String importanceOfWork = JOptionPane.showInputDialog("How important is this task? 1-10? \n(One being least important) ");
            this.importanceOfWork = Double.parseDouble(importanceOfWork);
      
            total = (amountOfTime * 2) + (importanceOfWork)
    }
    I would then like to output the task in order, highest to lowest, showing only the name of the task. For example:

    Order of tasks:
    1. Do dishes
    2. Vacuum
    3. Wash car

    Thank you for the help!

  2. #2
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    12,091
    Rep Power
    20

    Default Re: Ordering Inputted Java Values

    Don't stick the UI stuff in the class.
    You should be able to write this class without that.
    Make the UI the job of another class.

    You'll also want a Comparator (or make this Comparable), that way you can add this into a List and order it easily.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,423
    Rep Power
    20

    Default Re: Ordering Inputted Java Values

    Absolutely not an 'advanced' topic. Moving to New to Java

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Help (Java Eclipse loop using inputted number)
    By micolord in forum New To Java
    Replies: 12
    Last Post: 09-11-2011, 01:23 PM
  2. Help (Java Eclipse loop using inputted number)
    By micolord in forum Eclipse
    Replies: 1
    Last Post: 09-07-2011, 02:45 PM
  3. Sorting printed ArrayList of user inputted strings.
    By movsesinator in forum New To Java
    Replies: 3
    Last Post: 04-03-2010, 09:27 PM
  4. Java XML DOM/Transformer and attribute ordering
    By BeMathis in forum Advanced Java
    Replies: 0
    Last Post: 10-14-2009, 06:49 PM
  5. Help Creating A Graph From Inputted Data
    By adlb1300 in forum New To Java
    Replies: 6
    Last Post: 10-28-2007, 04:45 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •