QuestionQuestion

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 PreviewSolution 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);
      
    }
}...
$2.00 for this solution

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Java Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats