Results 1 to 4 of 4
  1. #1
    William is offline Member
    Join Date
    Feb 2012
    Posts
    3
    Rep Power
    0

    Default More help needed please!!!

    Please could someone step by step guide me through this question, as i have been sat here trying to do it for ages and it never seems to work.

    Hi, been trying this question all day. It is as follows:

    Write a program that repeatedly asks the user to type in the name of a current film and then asks for its release date. It should then stop when the code word "QUIT" is entered, and name the film that was released first. If several films were released in the earliest year the program should return the name of the last film entered. The program should run as follows(input is in bold):

    Name a film? Inception
    What year was Inception released? 2010

    Name a film? Tangled
    What year was Tangled released? 2011

    Name a film? Dirty Dancing
    What year was Dirty Dancing released? 1987

    Name a film? Philadelphia
    What year was Philadelphia released? 1993

    Name a film? Quit

    The earliest film was Dirty Dancing released in 1987



    Here is the code that I have written so far:

    import javax.swing.*;
    class Ex5
    {
    public static void main (String[]args)
    {
    film();
    System.exit(0);
    }

    public static void film()
    {

    String film2 = "null";
    String film1;
    String textInput;
    int year1 = 2012;

    film1 = JOptionPane.showInputDialog("Name a film?");


    while ( !film1.equalsIgnoreCase("quit")&!film2.equalsIgnor eCase("quit"))
    {
    int year2 = 0;

    textInput = JOptionPane.showInputDialog("What year was " + film1 + " released?");
    year2 = Integer.parseInt(textInput);

    film2 = JOptionPane.showInputDialog("Name a film?");

    if(year2<=year1)
    {
    year2 = year1;
    film1 = film2;
    }

    }

    JOptionPane.showMessageDialog(null,"The earliest film was " +film1+ " released in " +year1);

    }
    }

    I understand that i need variables inside and outside the while loop. I just dont know how to compare them properly.

    Please help!

    THANKSSSSSSSSSSS

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,165
    Rep Power
    20

    Default Re: More help needed please!!!

    So what problem are you having?
    What is it doing that it shouldn't be doing?

  3. #3
    William is offline Member
    Join Date
    Feb 2012
    Posts
    3
    Rep Power
    0

    Default Re: More help needed please!!!

    It doesn't quit when I want it to, and it doesn't show the earliest film at the end of the program. I have tried changing it all round in every which way, but nothing seems to work. I am sure there is something simple that i just can't see but i cant find it.

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,165
    Rep Power
    20

    Default Re: More help needed please!!!

    Do some debugging.
    Stick some System.out.println()'s in there to see what values you are getting and what it is doing.

Similar Threads

  1. help needed
    By radhi16 in forum New To Java
    Replies: 2
    Last Post: 01-27-2011, 05:44 PM
  2. Help Needed^^
    By hitech83 in forum New To Java
    Replies: 5
    Last Post: 01-24-2011, 10:08 PM
  3. Help needed!
    By decoy in forum New To Java
    Replies: 2
    Last Post: 10-06-2010, 02:14 PM
  4. Help needed
    By saibru in forum CLDC and MIDP
    Replies: 0
    Last Post: 03-23-2009, 10:40 AM
  5. help needed!!! :S
    By mark-mlt in forum Networking
    Replies: 1
    Last Post: 04-14-2008, 10:27 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •