Results 1 to 3 of 3
Thread: Ordering Inputted Java Values
- 07-10-2012, 02:18 PM #1
Member
- Join Date
- Jul 2012
- Posts
- 1
- Rep Power
- 0
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:
I would then like to output the task in order, highest to lowest, showing only the name of the task. For example: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) }
Order of tasks:
1. Do dishes
2. Vacuum
3. Wash car
Thank you for the help!
- 07-10-2012, 03:46 PM #2
Moderator
- Join Date
- Apr 2009
- Posts
- 10,460
- Rep Power
- 16
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.
- 07-16-2012, 05:05 AM #3
Similar Threads
-
Help (Java Eclipse loop using inputted number)
By micolord in forum New To JavaReplies: 12Last Post: 09-11-2011, 01:23 PM -
Help (Java Eclipse loop using inputted number)
By micolord in forum EclipseReplies: 1Last Post: 09-07-2011, 02:45 PM -
Sorting printed ArrayList of user inputted strings.
By movsesinator in forum New To JavaReplies: 3Last Post: 04-03-2010, 09:27 PM -
Java XML DOM/Transformer and attribute ordering
By BeMathis in forum Advanced JavaReplies: 0Last Post: 10-14-2009, 06:49 PM -
Help Creating A Graph From Inputted Data
By adlb1300 in forum New To JavaReplies: 6Last Post: 10-28-2007, 04:45 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks