Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create a java program that keeps track of Employees, Students and visitors. The

ID: 3603068 • Letter: C

Question

Create a java program that keeps track
of Employees, Students and visitors. The address for all employees and students must be
recorded by the system. For an address to be valid it must have the following attributes, street,
city and parish. Employee attributes that the user must enter into the system is First name, last name, gender and address. The students attributes must be First name , last name, gender, Date of birth. The visitors attributes must be first name, last name date of visit and time of visit. There are two types of employees Regular and Teachers, express this information in an enumerated class. Regular employees are paid a gross of $100,000.00 monthly and teachers are paid at a rate of $2,100.00 Per hour. Teachers work a maximum 25 paid hours per week and deliver no more than 4 subjects per academic year. If a teacher is delivering more than 3
subjects they will receive an additionally $3,000.00 weekly. If the employee is a teacher the
system must calculate and display the gross weekly amount earned, otherwise just display the gross as stated.
Create an abstract super class called Individual so that employees, students and visitors can
derived the common attributes. students and visitors cannot be inherited by any other entity.

Use an interface to declare the following methods printDetails() and printDetails(Individual per).
The contact details (name, telephone number and email address) for the school must also be
incorporated in the interface. Use another interface to declare a method called
calculateGrossSalary(). This method must be implemented by the employees entity. Not all the students pursue the same number of subjects. Some may pursue 1, 2, 3, 4 or more
subjects, Use regular arrays to implement this functionality.
All printed output must include the institution's name and contact details.
Crete a driver class (a class with a main method) to test the logics of your program.

Explanation / Answer

import javax.swing.JOptionPane;

public class AssignmentTen
{
public static void main (String[] args)
{
System.out.println();

int input1 = getInt ("Enter Employee Number:");
Employee e1 = new Employee(input1);
System.out.println("#" + e1.number);

String input2 = getString ("Enter Employee First Name:");
String input3 = getString ("Enter Employee Last Name:");
Name n1 = new Name(input2, input3);
System.out.println(n1.firstName + " " + n1.lastName);

String input4 = getString ("Enter Employee Street:");
String input5 = getString ("Enter Employee City:");
String input6 = getString ("Enter Employee State (Initials):");
int input7 = getInt ("Enter Employee Zip Code (5 Digits):");
Address a1 = new Address (input4, input5, input6, input7);
System.out.println(a1.eStreet + " " + a1.eCity + " " + a1.eState + " " + a1.eZipCode);

int input8 = getInt ("Enter Employee Hire Month (MM):");
int input9 = getInt ("Enter Employee Hire Day (DD):");
int input10 = getInt ("Enter Employee Hire Year(YYYY):");
Date d1 = new Date (input8, input9, input10);
System.out.println("Hire Date: " + d1.month + "/" + d1.day + "/" + d1.year);
}

public static int getInt(String paramString)
{
String str = JOptionPane.showInputDialog(paramString);
return Integer.parseInt(str);
}

public static String getString(String paramString)
{
String str = JOptionPane.showInputDialog(paramString);
return str;
}
}

class Employee
{
int number;

Employee(int newNumber)
{
number = newNumber;
}
}

class Name
{
String firstName;
String lastName;

Name(String first, String last)
{
firstName = first;
lastName = last;
}
}

class Address
{
String eStreet;
String eCity;
String eState;
int eZipCode;

Address(String street, String city, String state, int zipCode)
{
eStreet = street;
eCity = city;
eState = state;
eZipCode = zipCode;
}
}

class Date
{
int month;
int day;
int year;

Date(int eMonth, int eDay, int eYear)
{
month = eMonth;
day = eDay;
year = eYear;
}
}

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define size 200

struct emp
{
int id;
char *name;
}*emp1, *emp3;

void display();
void create();
void update();

FILE *fp, *fp1;
int count = 0;

void main(int argc, char **argv)
{
int i, n, ch;

printf("1] Create a Record ");
printf("2] Display Records ");
printf("3] Update Records ");
printf("4] Exit");
while (1)
{
printf(" Enter your choice : ");
scanf("%d", &ch);
switch (ch)
{
case 1:   
fp = fopen(argv[1], "a");
create();
break;
case 2:   
fp1 = fopen(argv[1],"rb");
display();
break;
case 3:   
fp1 = fopen(argv[1], "r+");
update();
break;
case 4:
exit(0);
}
}
}

/* To create an employee record */
void create()
{
int i;
char *p;

emp1 = (struct emp *)malloc(sizeof(struct emp));
emp1->name = (char *)malloc((size)*(sizeof(char)));
printf("Enter name of employee : ");
scanf(" %[^ ]s", emp1->name);
printf("Enter emp id : ");
scanf(" %d", &emp1->id);
fwrite(&emp1->id, sizeof(emp1->id), 1, fp);
fwrite(emp1->name, size, 1, fp);
count++; // count to number of entries of records
fclose(fp);
}

/* Display the records in the file */
void display()
{   
emp3=(struct emp *)malloc(1*sizeof(struct emp));   
emp3->name=(char *)malloc(size*sizeof(char));
int i = 1;

if (fp1 == NULL)   
printf(" File not opened for reading");
while (i <= count)
{
fread(&emp3->id, sizeof(emp3->id), 1, fp1);
fread(emp3->name, size, 1, fp1);
printf(" %d %s",emp3->id,emp3->name);
i++;
}
fclose(fp1);
free(emp3->name);
free(emp3);
}

void update()
{
int id, flag = 0, i = 1;
char s[size];

if (fp1 == NULL)
{
printf("File cant be opened");
return;
}
printf("Enter employee id to update : ");
scanf("%d", &id);
emp3 = (struct emp *)malloc(1*sizeof(struct emp));
emp3->name=(char *)malloc(size*sizeof(char));
while(i<=count)
{   
fread(&emp3->id, sizeof(emp3->id), 1, fp1);
fread(emp3->name,size,1,fp1);
if (id == emp3->id)
{
printf("Enter new name of emplyee to update : ");   
scanf(" %[^ ]s", s);
fseek(fp1, -204L, SEEK_CUR);
fwrite(&emp3->id, sizeof(emp3->id), 1, fp1);
fwrite(s, size, 1, fp1);
flag = 1;
break;
}
i++;
}
if (flag != 1)
{
printf("No employee record found");
flag = 0;
}
fclose(fp1);
free(emp3->name); /* to free allocated memory */
free(emp3);
}

public static void main(String[] args) {
int x = 0;
int menuChoice = -1;
Student[] students = new Student[30]; //As a note, hard-coding this '30' is a bad idea.
//Probably should be static, final const in class.
Scanner input = new Scanner (System.in);
do{
System.out.println(" Student Record Menu");
System.out.println(" 1. Add Student 2. View Students 3. Search Student 4. Exit");
System.out.println("Enter a choice: ");
menuChoice = input.nextInt();

if (menuChoice==1){
if(x < 30) { //Able to add new student.
System.out.println("Full name:");
String name = input.next(); //This was your error - should be next like the others,
//Not nextLine()
System.out.println("Age:");
int age = input.nextInt();
System.out.println("Course:");
String course = input.next();
System.out.println("Year:");
String year = input.next();
System.out.println("Section:");
String section = input.next();

//Create the new student using the given inputs
Student s = new Student(name, age, course, year, section);

//Place in array
students[x] = s;

//Increment x for next student placement
x++;
} else { //Not able to add new student
System.out.println("Can't add new student, students full");
}
}
else if (menuChoice==2) {
for (int i=0; i<x; i++) {
Student s = students[i];
System.out.println(s.getName() + s.getAge() + s.getCourse()
+ s.getYear() + s.getSection());
}
}
else if(menuChoice < 1 || menuChoice > 4){
System.out.println("Unrecognized menu choice; please re-enter");
}
} while (menuChoice != 4);

//Do close your scanners when you're done with them to avoid a resource leak.
//This is closing System.in (which is bad), but you're code is terminating anyway
//so its ok
input.close();
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote