0

I am having problems figuring out how to get the results from the strings and then give myself the option to sort through them alphabetically (or numerically). I have the code to the point where it shows the input data but don't know where to go from there. I'm fairly new to java so I don't even know if I'm doing the first part right. I have looked in to sort options with Arrays but am not to sure how to use them (or if I have done it right to allow myself to use them). Any help would be appreciated. Below is a copy of my code.

The questions I am trying to solve is "Your program should then use a menu that allows the user to display, search and exit. Display should display the list of the entries, sorted by last name, first name, or birth-date as requested by the user. Search should search for a specific entry by a specific field (last name, first name or birth-date) as requested by the user."

import javax.swing.JOptionPane;
public class Program2

{
//Loop #    
    public static void main(String [] args)
    {
    int Runs;

        do{
            String runQuestion = JOptionPane.showInputDialog(null, "Number of patients to enter in? (1-2)", "Total # Of Patients", JOptionPane.QUESTION_MESSAGE);

                Runs = Integer.parseInt(runQuestion);

                if( Runs < 1 || Runs > 2)
                {                                                                               //Small test numbers for now
                JOptionPane.showMessageDialog(null, "Please pick a number between 1 and 2", "Wrong Number Chosen", JOptionPane.INFORMATION_MESSAGE);
                }
            }

            while(Runs < 1 || Runs > 2);
            Questions(Runs);
    }


//Data Gathering Questions      
    public static void Questions(int Runs)
    {   
    for(char index = 0;index < Runs;index ++)
        {
        //Questions     
        String firstName = JOptionPane.showInputDialog(null, "Patients First Name?", "First Name", JOptionPane.QUESTION_MESSAGE);
        String lastName = JOptionPane.showInputDialog(null, "Patients Last Name?", "Last Name", JOptionPane.QUESTION_MESSAGE);
        String dateBirth = JOptionPane.showInputDialog(null, "Patients Date of Birth?", "DOB", JOptionPane.QUESTION_MESSAGE);
        String firstSort = String firstName;

        //Data Table print list
        System.out.println(firstName + " " + lastName + " " + dateBirth);
        }

    }
}

Edited by Dani: Formatting fixed

3
Contributors
6
Replies
8
Views
6 Years
Discussion Span
Last Post by JamesCherrill
0

You can use a array and can use sorting algorithm(insertion sort,quick sort,etc) to sort.......

0

Your data has 3 distinct components (last name, first name, birth-date) for each patient, so a simple array isn't going to be enough here. In Java I would expect to see another class called Patient that contains these fields. Is there such a class somewhere in this exercise?

0

Your data has 3 distinct components (last name, first name, birth-date) for each patient, so a simple array isn't going to be enough here. In Java I would expect to see another class called Patient that contains these fields. Is there such a class somewhere in this exercise?

No there is not. How would I go about adding it so that my results can be sorted?

0

If you haven't covered that in your course already, the maybe your teacher had another solution in mind? This could be a good time to review your course notes so far...

0

Like I have said already I am not the best at understanding things in Java but once I can sort of visually see what's going on it makes sense to me. For the sort he said it was fine to do either 1 routine or 3. Not any specific guidelines on how the inputs are grouped together or how they are sorted as long as you can sort each one individually.

0

In real life you would group the inputs together in a little class, but like I said, if you haven't covered that in your course yet then there must be another way.
Just in case, here's the official beginners tutorial on classes - maybe that will seem familiar to you, but if not I wouldn't spend too much time on it.
http://download.oracle.com/javase/tutorial/java/javaOO/index.html

Maybe someone else has an idea of how to do this sensibly without a class? Come on guys!

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.