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 Programming: Arrays Of Marks & Circles
Homework Solution
$50.00
Java
Programming
Codes
Computer Science
Algorithms
Arrays
Marks
Circles
Geometry
Mathematics
Radius
Random Numbers
Boundaries
Statements
Loops
Variables
Points
Coordinates
Perimeters
Area
Data Structures Questions
Homework Solution
$25.00
Data Structures
Algorithms
Codes
Computer Science
Stack
Values
API
Implementation
Push
Peek
Pop
Development
Fragments
Summation
Order
Simple Calculator in Java
Homework Solution
$25.00
Programming
Computer Science
Java
Calculator
Mathematics
Operations
Variables
Statements
Functions
Methods
Strings
Integers
Sentences
Expressions
Wrong Inputs
Errors
Java Program
Homework Solution
$30.00
Computer
Science
Java
Programming
Comments
Enhance
Better
Performance
Unit
Testing
Java Programming Problems
Homework Solution
$38.00
Java
Programming
Computer Science
Palindromes
Methods
Functions
Loops
Input
Output
Insertion Sort
Algorithms
Arrays
Integers
Strings
Get help from a qualified tutor
Live Chats