Happy New Year Program Using Eclipse IDE

in utopian-io •  7 years ago  (edited)

Hello Everyone, This is a short Java program using Eclipse IDE. This program uses Multiple Classes to print out a Happy New Year message to the screen. The program has two classes; a mainClass and a secondClass. A simple method with a parameter is used in secondClass to achieve this. The message to be displayed is written in the secondClass and the called in the main class using a “dot” (.) separator. When the program is run, it displays a Happy New Year Pop-Up Message to the screen.

1.png

2.png

This program illustrates how a user can use multiple classes to write a program, also, using methods to make a program a lot shorter than when all the code is contained in the main class.

3.png

Program prompts user to enter year when it is run.

4.png

A message is displayed on the screen.

5.png

Program ends if user exits prematurely.

6.png

GitHub Account

7.png

8.png

Source Codes from GitHub Account

SECOND CLASS

Line 1: Import Statement

Line 3: Package Name

Line 4: Method. A method with a single parameter is written. The Method will display a Message to the screen when called.

Line 5: Method Closing Brace.

Line 6: Package Closing Brace.

MAIN CLASS

Line 1: Import Statement

Line 3: Package Name

Line 4: Main Method. Every Java program needs a Main Method to run.

Line 5: Exception Handling try Statement.

Line 6: Variable declaration and Initialization. The user enters a value and it is stored as a String.

Line 7: Conversion. A String variable is converted into an Integer and stored as an Integer variable.

Line 8: Object. An object of the secondClass is created. Objects are needed so the user can call Methods contained in the secondClass.

Line 9: The object created is used to call a Method in the secondClass. An Integer variable is passed as argument for the method to be called successfully. The program displays the message on the screen after the Method is called.

Line 10: Exception Handling try Statement Closing Brace.

Line 11: Exception Handling catch Statement.

Line 12: A message is displayed on the screen if the user ends the program prematurely.

Line 13: Exception Handling catch Statement Closing Brace

Line 14: Main Method Closing Brace.

Line 15: Package Closing Brace.

Code Block

SECOND CLASS

import javax.swing.JOptionPane;
public class secondClass {
    public void displayMessage(int year) {
        JOptionPane.showMessageDialog(null, "Happy New Year " + year);
    }
}

MAIN CLASS

import javax.swing.JOptionPane;
public class mainClass {
    public static void main (String args []) {
        try {
        String numberYear = JOptionPane.showInputDialog("Enter Year");
        int numberYearInt = Integer.parseInt(numberYear);
        secondClass message = new secondClass();
        message.displayMessage(numberYearInt);
    }
        catch (Exception e) {
            JOptionPane.showMessageDialog(null, "You have ended the program");
        }
    }   
}



Posted on Utopian.io - Rewarding Open Source Contributors

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
Sort Order:  

Thank you for the contribution. It has been approved.

You can contact us on Discord.
[utopian-moderator]

happy new year

Happy New Year to you.

Your contribution cannot be approved yet because it is attached to the wrong repository. Please edit your contribution and fix the repository to https://github.com/eclipse/che to reapply for approval.

You may edit your post here, as shown below:

You can contact us on Discord.
[utopian-moderator]

Hey @will-ugo I am @utopian-io. I have just upvoted you!

Achievements

  • You have less than 500 followers. Just gave you a gift to help you succeed!
  • Seems like you contribute quite often. AMAZING!

Suggestions

  • Contribute more often to get higher and higher rewards. I wish to see you often!
  • Work on your followers to increase the votes/rewards. I follow what humans do and my vote is mainly based on that. Good luck!

Get Noticed!

  • Did you know project owners can manually vote with their own voting power or by voting power delegated to their projects? Ask the project owner to review your contributions!

Community-Driven Witness!

I am the first and only Steem Community-Driven Witness. Participate on Discord. Lets GROW TOGETHER!

mooncryption-utopian-witness-gif

Up-vote this comment to grow my power and help Open Source contributions like this one. Want to chat? Join me on Discord https://discord.gg/Pc8HG9x

Congratulations you have selected for big upvote from utopian-io