Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Need to add an error, and return the correct values in a dialog box

  1. #1
    Junior Member
    Join Date
    Jul 2021
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Need to add an error, and return the correct values in a dialog box

    Hi!
    Sorry in advance if this is really long or a bad question, I am new to Java and object-oriented programming and easily confused.

    My class very briefly in the first assignment like.... 4 weeks ago touched on the JOptionPane, but I can't find anything I need from the book or from the first assignment except the basics, so I was hoping someone could help!

    This is the assignment:

    "Write an application containing three parallel arrays that hold 10 elements each. The first array hold four-digit student ID numbers, the second array holds first names, and the third array holds the students’ grade point averages. Use dialog boxes to accept a student ID number and display the student’s first name and grade point average. If a match is not found, display an error message that includes the invalid ID number and allow the user to search for a new ID number."

    I am stuck on the error message, mainly: I have not worked in JOptionPane more than once, and what you'll see in my code is basically all I've ever done.
    Furthermore, what I have doesn't return the correct values: the dialog box returns the correct text, but the wrong format and a bunch of weird symbols instead of the corresponding FirstName and GPA ("First name: [Ljava.lang.String;@57e1b0cGPA:[D@4232c52b").

    This is my code so far:

    import javax.swing.JOptionPane;

    public class Assignment1 {
    public static void main(String[]args) {

    int [] StudentID = {1234, 5678, 9101, 1213, 1415, 1617, 1819, 2021, 2223, 2425};
    String[] FirstName = {"Bob", "Joe", "Jane", "John", "Roman", "Billy", "Casy", "Kylie", "Raimy", "Abby"};
    double [] GPA = {3.4, 3.6, 2.1, 1.2, 4.0, 3.7, 1.0, 3.7, 3.9, 3.4};

    JOptionPane.showInputDialog(null, "Enter student ID");



    JOptionPane.showMessageDialog(null, "First name: " + FirstName + "GPA: " + GPA);
    }

    }




    I've attempted if....else, and a do....while, but I'm really confused by how to check if the user-input number = the StudentID

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Need to add an error, and return the correct values in a dialog box

    how to check if the user-input number = the StudentID
    Use the == operator in an if statement to do that.
    Use a loop to iterate through all the values in the StudentID array.
    Access the elements in the array using array notation: StudentID[i] refers to the element at index i

    Please edit your post and wrap your code with code tags:

    [code]
    **YOUR CODE GOES HERE**
    [/code]

    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. This code is not giving correct values
    By Metamorphoseon in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 24th, 2014, 09:30 PM
  2. can i return two values from a return method?
    By tonu in forum Object Oriented Programming
    Replies: 4
    Last Post: January 1st, 2014, 11:02 AM
  3. Return the rgb values from a jpg image
    By newparticipant in forum What's Wrong With My Code?
    Replies: 1
    Last Post: May 25th, 2011, 03:47 PM
  4. Replies: 1
    Last Post: March 22nd, 2010, 04:34 PM
  5. Replies: 0
    Last Post: February 2nd, 2010, 08:20 AM

Tags for this Thread