In: Computer Science
I am having problems with :
If 6 is selected, then you will get an employee pay amount from the user. This will be a double. Only allow them to enter one pay amount and then display the main menu again.
AND:
if 2 is selected you will promt the user for a grade (double) from 0-100. Only allow them to enter one grade and then display the main menu again
The project:
Create a project called P03. Inside of P03 you’re going to have four classes: 1) EntrySystem.java...
(3 bookmarks)
Create a project called P03. Inside of P03 you’re going to have
four classes:
1) EntrySystem.java (which will contain your main method)
2) Person.java which will be your super class will have the
following properties:
first name (string)
last name (string)
id number (string)
phone (string)
street address (string)
city (string)
state (string)
zip (string)
3) Student.java will inherit from Person and will have the
following additional properties:
major (string)
grades (Arraylist of doubles)
advisor (string)
Student will also have a method called displayStudent() which will display all of the students information as well as their GPA in a neatly formatted way
. 4) Employee.java will inherit from Person and will have the
following additional properties:
department (string)
supervisor (string)
paychecks (ArrayList of doubles)
Employee will also have a method called displayEmployee() which
will display all of the employees information as well as their pay
average and pay total in a neatly formatted way. You can also add
and use the HelperClass.java.
You'll create two interfaces:
PayrollInterface.java with the following methods:
AddCheckAmount(double check)
GetPayTotal()
GetPayAverage()
GradesInterface.java with the following methods:
AddNumericalGrade(double grade)
CalculateGPA()
you will use Student to create an ArrayList of Student Java Objects
called students, and Employee to create an ArrayList of Employee
Java Objects called employees.
In EntrySystem.java you’ll have a menu with the following
options:
1) Add a Student
2) Add a Student Grade
3) View All Students
4) Clear all Students
5) Add an Employee
6) Add an Employee Pay Amount
7) View All Employees
8) Clear All Employees
9) Exit
If 1 is selected,you will prompt the user for each field of the
Student class to enter. You will validate strings to make sure they
are not empty. You will validate ints and doubles to make sure they
are proper ints and doubles. You will then add the Student Object
to an ArrayList called students, returning the user back to the
menu. Feel free to use the Helper Class we've been working
with.
HELP
If 2 is selected you will promt the user for a grade
(double) from 0-100. Only allow them to enter one grade and then
display the main menu again.
If 3 is selected, you will display the list of students in a neatly
formatted way by looping through students and calling
displayStudent() for each. If there are no students entered, then
tell the user this.
If 4 is selected, you will clear the students ArrayList.
If 5 is selected, then you will prompt the user for each field to
enter for the Employee class. You will validate strings to make
sure they are not empty. You will validate doubles to make sure
they are proper doubles.
HELP
If 6 is selected, then you will get an employee pay amount
from the user. This will be a double. Only allow them to enter one
pay amount and then display the main menu again.
If 7 is selected, you will display the list of employees in a
neatly formatted way calling displayEmployee() for each. If there
are no employees, then tell the user this.
If 8 is selected, you will clear the employees ArrayList.
When 9 is selected, you will exit the program.
HELP PLEASE
/********************Person.java************************/
package P03;
public class Person {
/**
* fields
*/
private String firstName;
private String lastName;
private String idNumber;
private String phoneNumber;
private String streetAddress;
private String city;
private String state;
private String zip;
/**
*
* @param firstName
* @param lastName
* @param idNumber
* @param phoneNumber
* @param streetAddress
* @param city
* @param state
* @param zip
*/
public Person(String firstName, String lastName,
String idNumber, String phoneNumber, String streetAddress,
String city,
String state, String zip) {
super();
this.firstName = firstName;
this.lastName = lastName;
this.idNumber = idNumber;
this.phoneNumber =
phoneNumber;
this.streetAddress =
streetAddress;
this.city = city;
this.state = state;
this.zip = zip;
}
//getter and setter
public String getFirstName() {
return firstName;
}
public String getLastName() {
return lastName;
}
public String getIdNumber() {
return idNumber;
}
public String getPhoneNumber() {
return phoneNumber;
}
public String getStreetAddress() {
return streetAddress;
}
public String getCity() {
return city;
}
public String getState() {
return state;
}
public String getZip() {
return zip;
}
}
/***********************************Student.java******************************/
package P03;
import java.util.ArrayList;
public class Student extends Person implements
GradesInterface{
/**
* fileds
*/
private String major;
private ArrayList<Double> grades = new
ArrayList<>();
private String advisor;
/**
*
* @param firstName
* @param lastName
* @param idNumber
* @param phoneNumber
* @param streetAddress
* @param city
* @param state
* @param zip
* @param major
* @param advisor
*/
public Student(String firstName, String lastName,
String idNumber, String phoneNumber, String streetAddress,
String city,
String state, String zip, String major, String advisor) {
super(firstName, lastName,
idNumber, phoneNumber, streetAddress, city, state, zip);
this.major = major;
this.advisor = advisor;
}
//getter and setter
public String getMajor() {
return major;
}
public ArrayList<Double> getGrades() {
return grades;
}
public String getAdvisor() {
return advisor;
}
public void setGrades(ArrayList<Double> grades)
{
this.grades = grades;
}
@Override
public String toString() {
return
this.getClass().getSimpleName()+" "+ getFirstName()+ " "+
getLastName() + " "+ getIdNumber() + " has "+calculateGPA();
}
@Override
public void AddNumericalGrade(double grade) {
grades.add(grade);
}
@Override
public double calculateGPA() {
double gpa = 0;
for(int i=0;i<grades.size();i++)
{
gpa = gpa+
grades.get(i).doubleValue();
}
gpa = gpa/grades.size();
return gpa;
}
}
/**********************************Employee.java*******************************/
package P03;
import java.util.ArrayList;
public class Employee extends Person implements PayrollInterface {
//fields
private String department;
private String supervisor;
private ArrayList<Double> paychecks = new
ArrayList<>();
/**
*
* @param firstName
* @param lastName
* @param idNumber
* @param phoneNumber
* @param streetAddress
* @param city
* @param state
* @param zip
* @param department
* @param supervisor
*/
public Employee(String firstName, String lastName,
String idNumber, String phoneNumber, String streetAddress,
String city,
String state, String zip, String department, String supervisor)
{
super(firstName, lastName,
idNumber, phoneNumber, streetAddress, city, state, zip);
this.department = department;
this.supervisor = supervisor;
}
//getter and setter
public String getDepartment() {
return department;
}
public String getSupervisor() {
return supervisor;
}
public ArrayList<Double> getPaychecks()
{
return paychecks;
}
@Override
public String toString() {
return
this.getClass().getSimpleName()+" "+ getFirstName()+ " "+
getLastName() + " "+ getIdNumber() + " has "+ GetPayTotal();
}
@Override
public void AddCheckAmount(double check) {
paychecks.add(check);
}
@Override
public double GetPayTotal() {
double payTotal = 0;
for (int i = 0; i <
paychecks.size(); i++) {
payTotal =
payTotal + paychecks.get(i);
}
return payTotal;
}
@Override
public double GetPayAverage() {
return GetPayTotal() / paychecks.size();
}
}
/***********************************PayrollInterface.java*************************8/
package P03;
public interface PayrollInterface {
public void AddCheckAmount(double check);
public double GetPayTotal();
public double GetPayAverage();
}
/************************GradesInterface.java****************************/
package P03;
public interface GradesInterface {
public void AddNumericalGrade(double grade);
public double calculateGPA();
}
/*******************************EntrySystem.java******************************/
package P03;
import java.util.ArrayList;
import java.util.Scanner;
public class EntrySystem {
public static void main(String[] args) {
ArrayList<Student>
students = new ArrayList<>();
ArrayList<Employee> employees
= new ArrayList<>();
Scanner scan = new
Scanner(System.in);
Student student = null;
Employee employee = null;
int menu;
do {
System.out.println("MENU: \n" + "\t1) Add a Student\r\n" +
" 2) Add a Student Grade\r\n"
+ " 3) View All
Students\r\n" + " 4) Clear all Students\r\n" +
" 5) Add an Employee\r\n"
+ " 6) Add an
Employee Pay Amount\r\n" + " 7) View All
Employees\r\n"
+ " 8) Clear All
Employees\r\n" + " 9) Exit");
menu =
scan.nextInt();
switch (menu)
{
case 1:
System.out.println("Enter the first name of the
student: ");
String firstName = scan.next();
System.out.println("Enter the last name of the
student: ");
String lastName = scan.next();
System.out.println("Enter the id number of the
student: ");
String idNumber = scan.next();
System.out.println("Enter the phone number of
the student: ");
String phoneNumber = scan.next();
System.out.println("Enter the street Address of
the student: ");
String streetAddress = scan.next();
System.out.println("Enter the city of the
student: ");
String city = scan.next();
System.out.println("Enter the state of the
student: ");
String state = scan.next();
System.out.println("Enter the zip code
:");
String zip = scan.next();
System.out.println("Enter the major of the
student: ");
String major = scan.next();
System.out.println("Enter the advisor of the
student: ");
String advisor = scan.next();
student = new Student(firstName, lastName,
idNumber, phoneNumber, streetAddress, city, state, zip,
major,
advisor);
students.add(student);
break;
case 2:
System.out.println("Enter the student grades:
");
double grade = scan.nextDouble();
student.AddNumericalGrade(grade);
break;
case 3:
for (int i = 0; i < students.size(); i++)
{
System.out.println(students.get(i).toString());
}
break;
case 4:
students.clear();
break;
case 5:
System.out.println("Enter the first name of the
Employee: ");
String firstNameEmployee = scan.next();
System.out.println("Enter the last name of the
Employee: ");
String lastNameEmployee = scan.next();
System.out.println("Enter the id number of the
Employee: ");
String idNumberEmployee = scan.next();
System.out.println("Enter the phone number of
the Employee: ");
String phoneNumberEmployee = scan.next();
System.out.println("Enter the street Address of
the Employee: ");
String streetAddressEmployee =
scan.next();
System.out.println("Enter the city of the
Employee: ");
String cityEmployee = scan.next();
System.out.println("Enter the state of the
Employee: ");
String stateEmployee = scan.next();
System.out.println("Enter the zip code
:");
String zipEmployee = scan.next();
System.out.println("Enter the deparment of the
Employee: ");
String deparmentEmployee = scan.next();
System.out.println("Enter the supervisor of the
Employee: ");
String supervisorEmployee = scan.next();
employee = new Employee(firstNameEmployee,
lastNameEmployee, idNumberEmployee, phoneNumberEmployee,
streetAddressEmployee, cityEmployee, stateEmployee, zipEmployee,
deparmentEmployee,
supervisorEmployee);
employees.add(employee);
break;
case 6:
System.out.println("Enter the Employee's pay
check: ");
double check = scan.nextDouble();
employee.AddCheckAmount(check);
break;
case 7:
for (int i = 0; i < employees.size(); i++)
{
System.out.println(employees.get(i).toString());
}
break;
case 8:
employees.clear();
break;
case 9:
System.exit(0);
break;
default:
System.out.println("Invalid choice!!!!");
break;
}
} while (menu != 9);
}
}
/****************************output*********************************/
MENU:
1) Add a Student
2) Add a Student Grade
3) View All Students
4) Clear all Students
5) Add an Employee
6) Add an Employee Pay Amount
7) View All Employees
8) Clear All Employees
9) Exit
1
Enter the first name of the student:
jugal
Enter the last name of the student:
kishor
Enter the id number of the student:
abc2334
Enter the phone number of the student:
989784789
Enter the street Address of the student:
abcd
Enter the city of the student:
jaipur
Enter the state of the student:
raj
Enter the zip code :
787878
Enter the major of the student:
cse
Enter the advisor of the student:
ms
MENU:
1) Add a Student
2) Add a Student Grade
3) View All Students
4) Clear all Students
5) Add an Employee
6) Add an Employee Pay Amount
7) View All Employees
8) Clear All Employees
9) Exit
2
Enter the student grades:
89
MENU:
1) Add a Student
2) Add a Student Grade
3) View All Students
4) Clear all Students
5) Add an Employee
6) Add an Employee Pay Amount
7) View All Employees
8) Clear All Employees
9) Exit
3
Student jugal kishor abc2334 has 89.0
MENU:
1) Add a Student
2) Add a Student Grade
3) View All Students
4) Clear all Students
5) Add an Employee
6) Add an Employee Pay Amount
7) View All Employees
8) Clear All Employees
9) Exit
4
MENU:
1) Add a Student
2) Add a Student Grade
3) View All Students
4) Clear all Students
5) Add an Employee
6) Add an Employee Pay Amount
7) View All Employees
8) Clear All Employees
9) Exit
3
MENU:
1) Add a Student
2) Add a Student Grade
3) View All Students
4) Clear all Students
5) Add an Employee
6) Add an Employee Pay Amount
7) View All Employees
8) Clear All Employees
9) Exit
5
Enter the first name of the Employee:
jks
Enter the last name of the Employee:
kish
Enter the id number of the Employee:
er8807
Enter the phone number of the Employee:
9837498
Enter the street Address of the Employee:
efgdg
Enter the city of the Employee:
delhi
Enter the state of the Employee:
delhi
Enter the zip code :
398789
Enter the deparment of the Employee:
IT
Enter the supervisor of the Employee:
jks
MENU:
1) Add a Student
2) Add a Student Grade
3) View All Students
4) Clear all Students
5) Add an Employee
6) Add an Employee Pay Amount
7) View All Employees
8) Clear All Employees
9) Exit
6
Enter the Employee's pay check:
73647
MENU:
1) Add a Student
2) Add a Student Grade
3) View All Students
4) Clear all Students
5) Add an Employee
6) Add an Employee Pay Amount
7) View All Employees
8) Clear All Employees
9) Exit
6
Enter the Employee's pay check:
8478
MENU:
1) Add a Student
2) Add a Student Grade
3) View All Students
4) Clear all Students
5) Add an Employee
6) Add an Employee Pay Amount
7) View All Employees
8) Clear All Employees
9) Exit
7
Employee jks kish er8807 has 82125.0
MENU:
1) Add a Student
2) Add a Student Grade
3) View All Students
4) Clear all Students
5) Add an Employee
6) Add an Employee Pay Amount
7) View All Employees
8) Clear All Employees
9) Exit
8
MENU:
1) Add a Student
2) Add a Student Grade
3) View All Students
4) Clear all Students
5) Add an Employee
6) Add an Employee Pay Amount
7) View All Employees
8) Clear All Employees
9) Exit
7
MENU:
1) Add a Student
2) Add a Student Grade
3) View All Students
4) Clear all Students
5) Add an Employee
6) Add an Employee Pay Amount
7) View All Employees
8) Clear All Employees
9) Exit
9
Thanks a lot, Please let me know if you have any problem...........