L
L
lonata2018-08-07 14:17:02
Java
lonata, 2018-08-07 14:17:02

How to translate a console program into a full-fledged Java application?

I started learning Java, wrote the first program, but I want it to run as a standard program by double clicking with the .exe extension. Now this program, when launched in Idea, is displayed in the environment console. How to implement it?
The program generates an e-mail name and password for it for a new employee of the company.
Main class EmailApp:

package emailapp;

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

    Email em1 = new Email("Petya", "Ivanov");

    System.out.println(em1.showInfo());
  }
}

Email class:
package emailapp;

import java.util.Scanner;


public class Email {
  private String firstName;
  private String lastName;
  private String password;
  private String email;
  private int defaultPasswordLength = 10;
  private String department;
  private String companySuffix = "supercompany.com";
  private int mailboxCapacity = 500;
  private String alternateEmail;

    //Constructor to receive  the first name and last name
  public Email(String firstName, String lastName) {
    this.firstName = firstName;
    this.lastName = lastName;


    //Call a method asking for the department - return the department
    this.department = setDepartment();


    //Call a method that returns a random password
    this.password = randomPassword(defaultPasswordLength);


    //Combine elements to generate email
    email = firstName.toLowerCase() + "." + lastName.toLowerCase() + "@" + department + "." + companySuffix;

  }
    //Ask for the department
  private String setDepartment() {
    System.out.print("New worker: " + firstName + " " +  lastName + "\nDepartment Codes: \n1 for Sales\n2 for Development\n3 for Accounting\n0 for none\nEnter department code: ");
    Scanner in = new Scanner(System.in);
    int depChoice = in.nextInt();
    if (depChoice == 1) {return "sales";}
    else if (depChoice == 2) {return "dev";}
    else if (depChoice == 3) {return "acct";}
    else {return "";}
  }

  //Generate a random password
  private String randomPassword(int length) {
    String passwordSet = "[email protected]#$%";
    char[] password = new char[length];
    for (int i = 0; i < length; i++) {
      int rand = (int) (Math.random() * passwordSet.length());
      password[i] = passwordSet.charAt(rand);
    }
    return new String (password);
  }

  //Set the mailbox capacity
  public void setMailboxCapacity(int capacity) {
    this.mailboxCapacity = capacity;
  }

  //set the alternate email
  public void setAlternateEmail(String altEmail) {
    this.alternateEmail = altEmail;
  }

  //Change password
  public void changePassword(String password) {
    this.password = password;
  }

  public int getMailboxCapacity() { return mailboxCapacity;}
  public String getAlternateEmail() {return alternateEmail;}
  public String getPassword() {return password;}

  public String showInfo() {
    return "DISPLAY NAME: " + firstName + " " + lastName +
            "\nCOMPANY EMAIL: " + email +
            "\nPASSWORD: " + password +
            "\nMAILBOX CAPACITY: " + mailboxCapacity + "mb";

  }
}

Answer the question

In order to leave comments, you need to log in

3 answer(s)
W
Warlodya, 2018-08-07
@Warlodya

blogs.jetbrains.com/idea/2010/08/quickly-create-ja...
In short:
File -> Project Structure -> Project Settings -> Artifacts -> Click green plus sign -> Jar -> From modules with dependencies once and then Build -> Build Project
But this will not create an .exe, but a .jar that, when double-clicked, will launch the JVM if it is installed in the OS.
To create an .exe, you will have to use third-party programs, but without a serious need, you do not need this and you can do with .jar.
https://stackoverflow.com/questions/147181/how-can...

N
netrox, 2018-08-07
@netrox

https://stackoverflow.com/questions/1082580/how-to...

O
Oleg Chinakin, 2018-08-07
@SaintRepublic

Here is a short video. I guess it's possible somehow.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question