Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6830011
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:34:04+00:00 2026-05-26T22:34:04+00:00

Just a really quick question about something small. The following is part of a

  • 0

Just a really quick question about something small. The following is part of a programming assignment for my programming 2 class. It focuses on inheritance and multiple classes. I’ve answered the question but want to consolidate the classes into a main function and actually build something rather than just submitting the bare minimum.

My question is the section of code below. The user runs the program, is presented with a dialog asking him as to what he’s like to add (a CD or a Movie, they’re both separate classes).

What I would like though, is for the user to actually name the specific instance of the class while the program is running. So, the user will click Movie for example, be prompt to enter a name and then next line to use the constructor in the movie class to create a new instance class with the name the user entered? Is this possible? I tried using a simple string x = JOptionpane and then naming the class x also, but it didn’t work. I’m thinking there might be some method that will refer to the string? like contents.x maybe?

thanks in advance!

import javax.swing.JOptionPane;
public class Main 
{

    public static void main (String args [])
    {
    Object[] options = {"Movie",
                "CD",
                "Cancel"};
            int n = JOptionPane.showOptionDialog(null, "Would you like to add an item?","Product",
                        JOptionPane.YES_NO_CANCEL_OPTION,
                            JOptionPane.QUESTION_MESSAGE,
                                null,
                                    options,
                                        options[2]);

    switch(n)
    {
    case 0: 
    String moviet = JOptionPane.showInputDialog("Title:");
    int movieID = Integer.parseInt(JOptionPane.showInputDialog("ID:"));
    Movie moviett = new Movie(moviet, movieID);


    }


    }

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T22:34:04+00:00Added an answer on May 26, 2026 at 10:34 pm

    If it’s not too far beyond your class’ content, you could use a Map<String, Media>1 to store instances identified by a runtime-specified string.

    Map<String, Media> instances = new HashMap<>();
    // snip...
    String moviet = JOptionPane.showInputDialog("Title:");
    int movieID = Integer.parseInt(JOptionPane.showInputDialog("ID:"));
    Movie moviett = new Movie(moviet, movieID);
    instances.put("some user-provided string", moviett);
    

    1Assuming that Movie and CD both extend/implement Media.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using EF4. Just a quick question, is this a really good framework?
Just a quick question. In WP7, is it really bad design/idea to store complex
i just noticed the guard method/class mentioned in this question and i don't really
Just a quick question really: I'm running a method to pull records from an
I just had a quick question about how stack variables versus heap variables work.
Just a quick question really. I am re-writing a site and I am converting
Good evening everyone, I have a quick question on a homework assignment my class
Just a quick architecture question really on storing calendar data. Basically, I have a
Just a really quick question here. I'm using virtual functions to read in from
Just a quick question because I really can't find a simple solution to my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.