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.


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

Results 1 to 3 of 3

Thread: JOption help

  1. #1
    Junior Member
    Join Date
    Sep 2014
    Thanked 0 Times in 0 Posts

    Default JOption help

    Please don't bash me for I am new to Java. I am learning but am lost on a simple problem I'm sure. We have been working with a basic text editor and getting our results to show up on the consel. No problem. Now with little knowledge we are supposed to get our code to show up in dialog boxes using import javax.swing.JOptionPane; I have tried many time and been reading online on how to do it but I keep getting all sorts of errors. The book i have does not talk much about JOption. So I went back and put my code back to what I had originally. My code is posted below and any help would be much appreciated. Like I said, I am new and still learning but have been stuck here for a few days getting confused after reading all sorts of stuff online. Thanks in advance! I also want to try and be able to enter a interest rate and have it display in the last message but that is giving me trouble too.

    import javax.swing.JOptionPane;
    import java.util.Scanner;

    public class RetirementGoal2

    public static void main(String[] args)

    Scanner sc = new Scanner(System.in);

    int year;
    double money;

    do {
    System.out.print("Enter number of years before retirement: ");
    year = sc.nextInt();
    System.out.print("Enter annual amount of money: ");
    money = sc.nextDouble();
    if (year < 1 || money <= 0)
    System.out.println("ERROR: Invalid input. Enter new values again.");

    while (year < 1 || money <= 0);

    for (int x = 1; x <= year; x++)
    for (int y = 0; y < x; y++)
    money += money * 0.05;
    System.out.println("You will have $" + money +
    " at retirement.");

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Eastern Florida
    Thanked 2,455 Times in 2,406 Posts

    Default Re: JOption help

    I keep getting all sorts of errors.
    Please copy the full text of the error message and paste it here. It has important info about the error.

    Please edit your post and wrap your code with code tags:
    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Super Moderator
    Join Date
    Jun 2013
    So. Maryland, USA
    My Mood
    Thanked 698 Times in 680 Posts

    Default Re: JOption help

    Welcome to the forum! Please read this topic to learn how to post code in code or highlight tags and other useful info for new members.

    Please post your code correctly using code or highlight tags per the above link.

    No bashing here. We can't really help you with the code that works - there's nothing broken to help you fix. Post the code and the errors, as Norm said, so that we can help you fix code that's broken.

Similar Threads

  1. Java joption
    By darking123 in forum Object Oriented Programming
    Replies: 9
    Last Post: February 5th, 2013, 10:51 AM
  2. Help incorporating a Joption Pane
    By Dysun in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 15th, 2012, 05:25 PM
  3. JOption Output Message
    By richW in forum What's Wrong With My Code?
    Replies: 4
    Last Post: February 15th, 2012, 11:17 PM
  4. [SOLVED] I have a problem with this Joption programme.
    By Leprechaun_hunter in forum What's Wrong With My Code?
    Replies: 7
    Last Post: April 12th, 2011, 03:31 AM
  5. JOption Pane help
    By dallas1125 in forum AWT / Java Swing
    Replies: 5
    Last Post: November 18th, 2009, 05:08 PM