You are on the Welcoming Committee at “Geeks –R- Us”, you are tasked with buildi
ID: 3789705 • Letter: Y
Question
You are on the Welcoming Committee at “Geeks –R- Us”, you are tasked with building a basic information data sheet on the new potential employees. Write a program that will display a (prototype of new layout) the first name, middle initial, last name, full name (store first name, middle name and last name into full name) age, salary and sex of new employee. Then displays that person’s name with the first name first, middle initial followed by a period, and last name then age, salary and sex on the monitor. Make sure the output is easy to read and understand. Use good programming techniques. Should do this homework twice, one using System.out.println(" "); and one using JOptionPane. If you do both each is worth 50 points. also could you recomend a compiler that i can use to run it and use it?
Explanation / Answer
I mostly compile my java code on command line. You can download the JDK (java development kit) from Oracle website depending on your system configuration i.e 32 bit or 64 bit system ( Windows, linux, Mac) .. The website has separate binaries for each environment.
NOTE : Don't forget to add the java's "bin" directory path into the PATH system variable (You can get this information easily on internet). You can also install Eclipse IDE after java installation to compile, run or debug code.
Please save the following code in "Information.java" file.
Compilation command : javac Information.java
Command to run the code: java Information
PROGRAM :
import java.util.*;
import java.io.*;
import javax.swing.JOptionPane;
public class Information
{
String first_name;
String last_name;
String middle_name;
int age;
float salary;
char sex;
void printInfo_JoptionPane(){
JOptionPane emp_panel = new JOptionPane("Employee Information");
String full_name = first_name + " " + middle_name.charAt(0) + ". " +last_name;
String emp_sex = "";
if(sex == 'M' || sex == 'm')
emp_sex = "MALE";
if(sex == 'F' || sex == 'f')
emp_sex = "FEMALE";
emp_panel.showMessageDialog(null,"EMPLOYEE NAME : " + full_name + " " +
"EMPLOYEE AGE : " + age + " " +
"EMPLOYEE SALARY : " + salary + " " +
"EMPLOYEE SEX : " + emp_sex);
}
void printInfo_console(){
Scanner seeker = new Scanner(System.in);
System.out.println("Plese enter the following information : ");
System.out.print("FIRST NAME :");
first_name = seeker.next();
System.out.print("MIDDLE NAME :");
middle_name = seeker.next();
System.out.print("LAST NAME :");
last_name = seeker.next();
System.out.print("AGE :");
age = seeker.nextInt();
System.out.print("SALARY :");
salary = seeker.nextFloat();
System.out.print("SEX :");
sex = seeker.next().charAt(0);
System.out.println("");
System.out.print("EMPLOYEE NAME : " + first_name + " ");
if((middle_name != null) && (middle_name.length() != 0))
System.out.print(middle_name.charAt(0) + ". ");
if((last_name != null) && (last_name.length() != 0))
System.out.println(last_name);
System.out.println("EMPLOYEE AGE : " + age);
System.out.println("EMPLOYEE SALARY : " + salary);
if(sex == 'M' || sex == 'm')
System.out.println("EMPLOYEE SEX : MALE");
if(sex == 'F' || sex == 'f')
System.out.println("EMPLOYEE SEX : FEMALE");
}
public static void main(String []args){
Information empRecord = new Information();
empRecord.printInfo_console();
empRecord.printInfo_JoptionPane();
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.