/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package theaterpeople; import java.util.Scanner; import java.io.File; import java.io.FileNotFoundException; /** * * @author jcmt */ public class Actor extends TheaterPeople implements calculatePay { private String roleName; private int shirtSize; private int clothesGender; // 1 = female, 0= male, -1 = genderless; private double hoursWorked; public Actor(String roleName, int shirtSize, int clothesGender, String lastName, String firstName, dateDMY dateOfBirth) { super(lastName, firstName, dateOfBirth); makeCalculatedPay(); this.roleName = roleName; this.shirtSize = shirtSize; this.clothesGender = clothesGender; } public Actor(String roleName, int shirtSize, int clothesGender, String lastName, String firstName, int day, int month, int year) { super(lastName, firstName, day, month, year); makeCalculatedPay(); this.roleName = roleName; this.shirtSize = shirtSize; this.clothesGender = clothesGender; } public Actor(String inputFile) { super(); System.out.printf("Filename string is %s\n",inputFile); File inFile = new File(inputFile); try { Scanner inputF = new Scanner(inFile); // if (inFile.exists()){ this.setLastName(getString(inputF)); System.out.printf("\nRead the actor's last name from the file: %s ",getLastName()); this.setFirstName(getString(inputF)); System.out.printf("\nRead the actor's first name: %s",getFirstName()); this.setDateOfBirth(getInt(inputF), getInt(inputF), getInt(inputF)); System.out.printf("\nRead the actor's birthdate in the number format\n DD %d MM %d YYYY %d ", this.getDateOfBirth().getDay(), this.getDateOfBirth().getMonth(), this.getDateOfBirth().getYear()); //input.nextLine(); //super(lastname, "Julia", 23, 3, 2014); this.roleName = getString(inputF); System.out.printf("\nRead the actor's role in the play: %s", this.getRoleName()); this.setClothesGender(getInt(inputF)); System.out.printf("\nRead the actor's gender in the play as an int: 1 for female, 0 for male, -1 for genderless: %d",this.getClothesGender()); this.setShirtSize(getInt(inputF)); System.out.printf("\nRead the actor's shirt size: %d\n",this.getShirtSize()); makeCalculatedPay(); } catch(FileNotFoundException f) { System.out.println("File does not exist"); } //} } public Actor() { super(); Scanner input = new Scanner(System.in); System.out.printf("\nPlease enter the actor's last name: "); this.setLastName(getString()); System.out.printf("\nPlease enter the actor's first name: "); this.setFirstName(getString()); System.out.printf("\nPlease enter the actor's birthdate in the number format\n DD MM YYYY : "); this.setDateOfBirth(getInt(), getInt(), getInt()); //input.nextLine(); //super(lastname, "Julia", 23, 3, 2014); System.out.printf("\nPlease enter the actor's role in the play: "); this.roleName = getString(); System.out.printf("\nPlease enter the actor's gender in the play as an int: 1 for female, 0 for male, -1 for genderless: "); this.setClothesGender(getInt()); System.out.printf("\nPlease enter the actor's shirt size: "); this.setShirtSize(getInt()); makeCalculatedPay(); } public String getString(Scanner sscan) { String temp = new String(); try { //Scanner sscan = new Scanner(inFile); temp = sscan.nextLine(); } catch (Exception e) { System.out.printf("Exception reading string"); return ""; } return temp; } public String getString() { String temp = new String(); Scanner sscan = new Scanner(System.in); try { temp = sscan.nextLine(); } catch (Exception e) { System.out.printf("Exception reading string"); return ""; } return temp; } public int getInt(Scanner sscan) { int temp; try { //Scanner sscan = new Scanner(inFile); if (sscan.hasNextInt()) { temp = sscan.nextInt(); } else { sscan.nextLine(); temp = sscan.nextInt(); } sscan.nextLine(); } catch (NumberFormatException e) { System.out.printf("Exception reading int"); return 0; } return temp; } public int getInt() { int temp; Scanner sscan = new Scanner(System.in); try { temp = sscan.nextInt(); } catch (NumberFormatException e) { System.out.printf("Exception reading int"); return 0; } return temp; } public String getRoleName() { return roleName; } public void setRoleName(String roleName) { this.roleName = roleName; } public int getShirtSize() { return shirtSize; } public void setShirtSize(int shirtSize) { this.shirtSize = shirtSize; } public int getClothesGender() { return clothesGender; } public void setClothesGender(int clothesGender) { if ((clothesGender == 0) || (clothesGender == 1) || (clothesGender == -1)) { this.clothesGender = clothesGender; } else { this.clothesGender = -1; } } public double getHoursWorked() { return hoursWorked; } public void setHoursWorked(double hoursWorked) { if (hoursWorked > 0) { this.hoursWorked = hoursWorked; } } public void setCalculatedPay(double cPay) { if (cPay >= 0) { super.setCalculatedPay(cPay); } super.setCalculatedPay(0); } public double getCalculatedPay() { return super.getCalculatedPay(); } @Override public double makeCalculatedPay() { double equityPayPerHour = 8.75; int equityLevel = 2; double payTemp; payTemp = hoursWorked * equityPayPerHour + hoursWorked * (equityPayPerHour / equityLevel); setCalculatedPay(payTemp); return getCalculatedPay(); } public String toString() { return String.format("%s in the role %s wears %s size %d", super.toString(), roleName, ((clothesGender == 1) ? "women's" : "men's"), shirtSize); } }