Question

1. Define a class person.
Attributes    String fname, String lname. String MI, int age, String Sex, int Phone, int Zip.

2. Define a subclass of person, employee with attributes
                         Ssn, payrate, jobtitle, dependents.

    The methods for both classes will include a get and set for each attribute.
Each class will have a default constructor that initializes all strings to “unknown” and all numbers to 0.
The employee class will have two constructors. One that has parameters for every attribute and puts those values into the parameters.
Employee will also have a method getgrosspay(hours) and returns grosspay = hours*payrate.

3. Write a main class employeeex which defines two employee variables and prompts the user for input for each employee variable and use the default constructor for the first employee and uses the set methods to enter the values.
For the second employee enter the values into input variables and use the second constructor to define the variable.
Then enter the hours worked for each employee and output the employee’s name and gross pay.

Solution Preview

This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.

package personapp;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.util.Scanner;
import javax.swing.JOptionPane;

/**
*
* @author
*/
public class Personapp {

    /**
    * @param args the command line arguments
    */
    public static void main(String[] args) throws FileNotFoundException {
         
       String fname = JOptionPane.showInputDialog("Enter the first name of the person");
       String lname = JOptionPane.showInputDialog("Enter the last name of the person");
      
       String MI = JOptionPane.showInputDialog("Enter the MI of the person");
       String a = JOptionPane.showInputDialog("Enter the age of the person");
       int age = Integer.parseInt(a);   
    String Sex = JOptionPane.showInputDialog("Enter the sex of the person");
       String p = JOptionPane.showInputDialog("Enter the phone of the person");
       int Phone = Integer.parseInt(p);   
       String z = JOptionPane.showInputDialog("Enter the zip code of the person");
       int Zip = Integer.parseInt(z);   
   
      
       String sn = JOptionPane.showInputDialog("Enter the SSN of the person");
       int ssn = Integer.parseInt(sn);
      
       String pay = JOptionPane.showInputDialog("Enter the payrate of the person");
       double payrate = Double.parseDouble(pay) ;
      
       String jobtitle = JOptionPane.showInputDialog("Enter the jobtitle of the person");
       String dependents = JOptionPane.showInputDialog("Enter the dependents of the person");
      
       employee e1 = new employee();
       e1.setAge(age);
       e1.setDependents(dependents);
       e1.setFname(fname);
       e1.setLname(lname);
       e1.setMI(MI);
       e1.setPayrate(payrate);
       e1.setPhone(Phone);
       e1.setSSN(ssn);
       e1.setSex(Sex);
       e1.setZip(Zip);
      
       /*=======================================*/
      
       fname = JOptionPane.showInputDialog("Enter the first name of the person");
       lname = JOptionPane.showInputDialog("Enter the last name of the person");
      
       MI = JOptionPane.showInputDialog("Enter the MI of the person");
       a = JOptionPane.showInputDialog("Enter the age of the person");
       age = Integer.parseInt(a);   
    Sex = JOptionPane.showInputDialog("Enter the sex of the person");
         p = JOptionPane.showInputDialog("Enter the phone of the person");
         Phone = Integer.parseInt(p);   
       z = JOptionPane.showInputDialog("Enter the zip code of the person");
       Zip = Integer.parseInt(z);   
   
      
       sn = JOptionPane.showInputDialog("Enter the SSN of the person");
       ssn = Integer.parseInt(sn);
      
       pay = JOptionPane.showInputDialog("Enter the payrate of the person");
       payrate = Double.parseDouble(pay) ;
      
       jobtitle = JOptionPane.showInputDialog("Enter the jobtitle of the person");
       dependents = JOptionPane.showInputDialog("Enter the dependents of the person");
      
       employee e2 = new employee(ssn, payrate, jobtitle, dependents, fname, lname, MI, age, Sex, Phone, Zip);
      
      
       /*===================================*/
      
       String hour = JOptionPane.showInputDialog("Enter the hours worked of the firsr person");
       double h1 = Double.parseDouble(hour) ;
       hour = JOptionPane.showInputDialog("Enter the hours worked of the second person");
       double h2 = Double.parseDouble(hour) ;
      
       double g1 = e1.getGrossPay(h1);
       double g2 = e1.getGrossPay(h2);
      
       JOptionPane.showMessageDialog(null, " Name Gross pay \n " + e1.getFname() + " " + e1.getLname() + " " + g1 + " \n" + e2.getFname() + " " + e2.getLname() + " " + g2 , "Output",
JOptionPane.INFORMATION_MESSAGE);
      
    }
}...

This is only a preview of the solution. Please use the purchase button to see the entire solution

Assisting Tutor

Related Homework Solutions

Java Problems: Student Details & Fibonacci Series
Homework Solution
$20.00
Java
Programming
OOP
Computer Science
Fibonacci Series
Students
Classes
Instances
Loops
Conditions
Statements
Variables
Integers
Mathematics
Java Programming Assignment
Homework Solution
$20.00
Java Test Application
Java Programming
Program
3-D Geometric Shape
Java Class
Constructor
Parking Problem in Java
Homework Solution
$30.00
Java
Programming
Codes
Classes
Computer Science
Parking
OOP
Car Model
License Number
Owner Name
Strings
Integers
Statements
Input
Output
Constructor
Public Methods
Functions
Personal Name List in Java
Homework Solution
$8.00
Java
Programming
Computer Science
Codes
Algorithms
Personal Name List
Records
Errors
Arrays
Items
Variables
Statements
Characters
Moving Elements
Input
Output
Cylinder Containers in Java
Homework Solution
$25.00
Java
Programming
Codes
Algorithms
Computer Science
Statements
Variables
Loops
Input
Output
Integers
Strings
Geometry
Mathematics
Cylinder
Radius
Finance
Costs
Containers
Companies
Functions
Get help from a qualified tutor
Live Chats