In: Computer Science
In Java
Design and implement an application that can compute the weekly pay for different students at a college. Students (all with a name, major, GPA) can be undergraduate or graduate students. Undergraduate students can be volunteers to be tuto rs or teaching assistants. Graduate students can be teaching assistants or research assistants. Volunteer tuto rs are not paid anything. Undergraduate teaching assistants are paid $15 per hour and can work a maximum of 20 hours per week. Graduate teaching assistants are paid $20 per hour and can work a maximum of 20 hours per week. Graduate research assistants are paid $30 per hour and can work 25 works a week. Create a small array (size 4) to hold different students. Then create a driver class to display the different students and their weekly pay.
import java.util.Scanner;
// Enum to hold type of graduate
enum GraduateType
{
GRADUATE,UNDERGRADUATE;
}
// Enum to hold assistant type
enum ASSISTANTTYPE
{
TUTOR,TEACHINGASSISTANT,RESEARCHASSISTANT;
}
class Student
{
// each student will hold following details
String studentName; // Placeholder for student name
double GPA;
String major;
GraduateType gradOrUnderGrad; // boolean to check if studnet is
grad or undergrad
ASSISTANTTYPE assistantTtpe;
double hoursWorked; // the number of hours worked in a week
// parametrised constructor, used to create object with all given
details
Student(String sname,double gpa,String majorhere,GraduateType
gType,ASSISTANTTYPE assType,double hWorked)
{
studentName = sname;
GPA = gpa;
major = majorhere;
gradOrUnderGrad = gType;
assistantTtpe = assType;
hoursWorked = hWorked;
}
// getters
GraduateType getGraduateType()
{
return gradOrUnderGrad;
}
ASSISTANTTYPE getAssistantType()
{
return assistantTtpe;
}
// to check for each graduate type and assistant type what is the
allowed maximum hours
int allowedMaximumWorkHours()
{
int allowedMaxHours = 0;
if(GraduateType.valueOf("UNDERGRADUATE") == gradOrUnderGrad
&& ASSISTANTTYPE.valueOf("TEACHINGASSISTANT") ==
assistantTtpe)
{
allowedMaxHours = 20;
}
else if(GraduateType.valueOf("GRADUATE") == gradOrUnderGrad
&& ASSISTANTTYPE.valueOf("TEACHINGASSISTANT") ==
assistantTtpe)
{
allowedMaxHours = 20;
}
else if(GraduateType.valueOf("GRADUATE") == gradOrUnderGrad
&& ASSISTANTTYPE.valueOf("RESEARCHASSISTANT") ==
assistantTtpe)
{
allowedMaxHours = 25;
}
return allowedMaxHours;
}
// to check for each graduate type and assistant type what is the
allowed pay rate
int getPayRate()
{
int finalPayRate = 0;
if(GraduateType.valueOf("UNDERGRADUATE") == gradOrUnderGrad
&& ASSISTANTTYPE.valueOf("TUTOR") == assistantTtpe)
{
finalPayRate = 0;
}
else if(GraduateType.valueOf("UNDERGRADUATE") == gradOrUnderGrad
&& ASSISTANTTYPE.valueOf("TEACHINGASSISTANT") ==
assistantTtpe)
{
finalPayRate = 15;
}
else if(GraduateType.valueOf("GRADUATE") == gradOrUnderGrad
&& ASSISTANTTYPE.valueOf("TEACHINGASSISTANT") ==
assistantTtpe)
{
finalPayRate = 20;
}
else if(GraduateType.valueOf("GRADUATE") == gradOrUnderGrad
&& ASSISTANTTYPE.valueOf("RESEARCHASSISTANT") ==
assistantTtpe)
{
finalPayRate = 30;
}
return finalPayRate;
}
//// to check for each graduate type the allowed combination of
assistant type
boolean isAllowedCombination()
{
boolean isAllowed = false;
//System.out.println(getGraduateType());
//System.out.println(getAssistantType());
if(getGraduateType() ==
GraduateType.valueOf("UNDERGRADUATE"))
{
if(getAssistantType() == ASSISTANTTYPE.valueOf("TUTOR") ||
getAssistantType() ==
ASSISTANTTYPE.valueOf("TEACHINGASSISTANT"))
{
isAllowed = true;
}
}
else if(getGraduateType() ==
GraduateType.valueOf("GRADUATE"))
{
if(getAssistantType() == ASSISTANTTYPE.valueOf("RESEARCHASSISTANT")
|| getAssistantType() ==
ASSISTANTTYPE.valueOf("TEACHINGASSISTANT"))
{
isAllowed = true;
}
}
return isAllowed;
}
}
public class Main
{
public static void main(String[] args)
{
System.out.println( "Student Weekly Payroll Program\n\n"); // Tells
program to show Welcome Message
Scanner input;
Student[] array = new Student[4];
// creating sample of 4 students
Student s1 = new
Student("Bhavana",9.0,"CSE",GraduateType.valueOf("UNDERGRADUATE"),ASSISTANTTYPE.valueOf("TUTOR"),20);
Student s2 = new
Student("Arpitha",8.0,"ISE",GraduateType.valueOf("UNDERGRADUATE"),ASSISTANTTYPE.valueOf("TEACHINGASSISTANT"),20);
Student s3 = new
Student("Rakesh",7.0,"ECE",GraduateType.valueOf("GRADUATE"),ASSISTANTTYPE.valueOf("TEACHINGASSISTANT"),20);
Student s4 = new
Student("Amruth",6.0,"EEE",GraduateType.valueOf("GRADUATE"),ASSISTANTTYPE.valueOf("RESEARCHASSISTANT"),40);
array[0] = s1;
array[1] = s2;
array[2] = s3;
array[3] = s4;
// iterating over each student and calculating weekly pay.
// if any student has worked beyong allowed limit of working
hours/
// pay is given only for allowed hours.
// if within limit to no of hours worked pay is calulated,
for(int i=0;i<4;i++)
{
if(array[i].isAllowedCombination())
{
int payRate = 0;
double totalWeeklyPay =0.0;
//System.out.println( "Is allowed combination");
System.out.println( "Student Number:"+i);
System.out.println( "Student Name:"+array[i].studentName);
System.out.println( "Graduate
Type:"+array[i].getGraduateType());
System.out.println( "Assistant
Type:"+array[i].getAssistantType());
payRate = array[i].getPayRate();
System.out.println("Pay Rate:"+payRate);
System.out.println("Hours Worked:"+array[i].hoursWorked);
System.out.println("Allowed Maximum
Hours:"+array[i].allowedMaximumWorkHours());
if(array[i].hoursWorked <=
array[i].allowedMaximumWorkHours())
{
System.out.println(" number of hours worked is within
range");
totalWeeklyPay = payRate * array[i].hoursWorked;
}
else if(array[i].hoursWorked >
array[i].allowedMaximumWorkHours())
{
System.out.println(" number of hours worked is outside the range
range");
totalWeeklyPay = payRate *
array[i].allowedMaximumWorkHours();
}
System.out.println("Total Weekly pay:"+ totalWeeklyPay);
System.out.println("-------------------------------");
}
else
{
System.out.println( "Entered Graduate type and assistance type are
not allowed");
}
}
}
}
output: