Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

Java Community Theater Program

View Actor.java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301
package newcommunitytheatertest;
 
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.Scanner;
/**
*
* @author
* This is a subclass of TheaterPerson, it implements the interface CalculatePay
*/
public class Actor extends TheaterPerson implements CalculatePay {
private String play;
private float payHourly;
private boolean equity;
private String roleName;
private int hoursWorked;
private Scanner fileIn;
public Actor()
{ //constructor that takes keyboard inputs
super();
readInKeyboard();
}
//file input constructor that calls readInFile method, takes in scanner object fileIn
public Actor(Scanner fileIn) throws FileNotFoundException
{
//getting info from file
super();
readInFile(fileIn);
}
//takes in Scanner fileIn to check string input from file with try and catch statements
public String getString(Scanner fileIn)
{
 
String temp = new String();
 
try
{
//Scanner sscan = new Scanner(inFile);
temp = fileIn.nextLine();
 
}
catch (Exception e)
{
System.out.printf("Exception reading string");
return "";
}
return temp;
}
//not in use, method for getting a string from keyboard
public String getString()
{
String temp = new String(); //create new temp
Scanner input = new Scanner(System.in);
try
{
temp = input.nextLine();
}
catch(NumberFormatException e)
{
System.out.printf("Exception reading string");
return "";
}
return temp;
}
//same as getString that takes in Scanner fileIn, for ints from file
public int getInt(Scanner fileIn)
{
int temp;
try
{
//Scanner sscan = new Scanner(inFile);
if (fileIn.hasNextInt())
{
temp = fileIn.nextInt();
}
else
{
fileIn.nextLine();
temp = fileIn.nextInt();
}
fileIn.nextLine();
}
catch (NumberFormatException e)
{
System.out.printf("Exception reading int");
return 0;
}
 
return temp;
}
//same as getString for keyboard, reads ints
public int getInt()
{
int temp; //create new temp
Scanner input = new Scanner(System.in);
try
{
temp = input.nextInt();
}
catch(Exception e)
{
System.out.printf("Exception reading integer");
return 0;
}
return temp;
}
//file input for floats
public float getFloat(Scanner fileIn)
{
float temp;
try
{
//Scanner sscan = new Scanner(inFile);
if (fileIn.hasNextFloat())
{
temp = fileIn.nextFloat();
}
else
{
fileIn.nextLine();
temp = fileIn.nextFloat();
}
fileIn.nextLine();
}
catch (NumberFormatException e)
{
System.out.printf("Exception reading float");
return 0;
}
 
return temp;
}
public String getPlay() {
return play;
}
 
public void setPlay(String play) {
this.play = play;
}
 
public float getPayHourly() {
return payHourly;
}
//set method error checks hourly pay
public void setPayHourly(float payHourly) {
if((payHourly <= 0) || (payHourly > 101))
{
System.out.printf("The pay entered is invalid. Default pay set");
payHourly= 35;
}
else{
this.payHourly = payHourly;
}
}
 
public boolean isEquity() {
return equity;
}
//sets boolean variable equity by taking in string and converting to bool
public void setEquity(String equityStr) {
if(equityStr.equalsIgnoreCase("true"))
this.equity = true;
else if(equityStr.equalsIgnoreCase("false"))
this.equity = false;
}
 
public String getRoleName() {
return roleName;
}
 
public void setRoleName(String roleName) {
this.roleName = roleName;
}
 
public int getHoursWorked() {
return hoursWorked;
}
//error checks hours worked
public void setHoursWorked(int hoursWorked) {
if((hoursWorked <=0) ||(hoursWorked > 100))
{
System.out.print("\nHours worked is invalid. Default hours per week set.");
}
else{
this.hoursWorked = hoursWorked;
}
}
//method to read files, takes in scanner fileIn
private void readInFile(Scanner fileIn) throws FileNotFoundException
{
System.out.println("Reading input from file...");
//perhaps unecessary temp variables for setting dates for birth & hire
int tempDay=0;
int tempMonth=0;
int tempYear=0;
int tempHDay = 0;
int tempHMonth = 0;
int tempHYear = 0;
this.setLastName(getString(fileIn));
this.setFirstName(getString(fileIn));
this.setIdNum(getInt(fileIn));
this.setPersonAddress(getString(fileIn));
tempDay = getInt(fileIn);
tempMonth = getInt(fileIn);
tempYear = getInt(fileIn);
this.setDateOfBirth(tempDay, tempMonth, tempYear);//setting date of birth
tempHDay = getInt(fileIn);
tempHMonth = getInt(fileIn);
tempHYear = getInt(fileIn);
this.setHireDate( tempHDay, tempHMonth, tempHYear);
this.setPersonAccount(getInt(fileIn));
this.setPlay(getString(fileIn));
this.setPayHourly(getFloat(fileIn));
this.setEquity(getString(fileIn));
this.roleName = getString(fileIn);
this.setHoursWorked(getInt(fileIn));
 
//return? to let the method from main know that info is done and to move to next?
}
//this method reads from keyboard
private void readInKeyboard()
{
Scanner keyInput = new Scanner(System.in);
System.out.println("\nReading input from keyboard...");
//ask individual questions read in
}
@Override
//interface for Actor's pay
public double getCalculatedPay()
{ double actorPay=0;
if(equity==false)
{
actorPay = payHourly * hoursWorked;
System.out.printf("The actor's pay is"+ actorPay);
}
if(equity==true)
{ double calc = 0;
calc = (hoursWorked -40) * payHourly;
if(calc > 0)
{
actorPay = payHourly * hoursWorked + calc;
System.out.printf("\nEquity is true. calc > 0 \nThe actor's pay is" + actorPay);
}
else
{
actorPay = payHourly * hoursWorked;
System.out.printf("\nEquity is true. calc < 0 \nThe actor's pay is" + actorPay);
}
}
return actorPay;
}
public String toString()
{
return String.format("%s \nis in the role of %s in the play %s. \nHours worked: %d \nPay: %f\nThis Actor %s", super.toString(), roleName, play, hoursWorked, payHourly,((equity==true) ? "has equity": "does not have equity"));
}
}
View Actor.java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
/**
Data in file is for an Actor. Items are one per line and are in the following order:
 
LastName
FirstName
IDNumber
Address
DayOfBirth
MonthOfBirth
YearOfBirth
DayOfHire
MonthOfHire
YearOfHire
BankAccountNumber
PlayName
PayPerHour
MemberOfActorsEquity // boolean
Role
HoursWorkedPerWeek
 
You may remove this commented header from the test file when you use it with your program.
*/
Cruise
Tom
8763345
123 Semantic St, NY, NY 10001
04
07
1962
09
06
1965
11110998
Cabaret
80.00
true
The Emcee
75
Roberts
Julia
3373663
883 Suter Dr., Nashville, IN, 54308
09
09
1980
02
04
2012
111163553
Gravity
85.00
true
Dr. Ellen Stone
88
Rooney
Mickey
56475
90 S. Ventura Blvd., Hollywood, CA 21454
02
02
1925
30
04
1993
111137254
Let's Have a Show
40.00
true
Andy Hardy
45
Michelle
Nichols
784564
845 Star Way, Bethesda, MD 34528
23
09
1938
17
05
1984
111183765
Undiscovered Country
45.00
false
Lt. Uhuru
50
View Actor.java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
 
 
package newcommunitytheatertest;
import java.io.*;
import java.text.SimpleDateFormat;
import java.util.Scanner;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
/**
*
* @author
*
* Lab 4 Main Class
*/
public class NewCommunityTheaterTest {
 
public static void main(String[] args) {
//Scanner theaterInfo = new Scanner(System.in);
Scanner choice = new Scanner(System.in);//variable for user to choose
System.out.printf("\nFile input (F) or keyboard input (K): ");
String choiceInput = choice.next();
CommunityTheater theaterObj;//object of community theater not in use at the moment
theaterObj = new CommunityTheater();
ArrayList<Actor> actorList = new ArrayList();//ArrayList of instances of Actors, will be moved to theaterObj
//user chooses keyboard or file input
if(choiceInput.equalsIgnoreCase("k"))
{ //not in use at the moment
System.out.println("\nYou've chosen keyboard input...");
}
else if(choiceInput.equalsIgnoreCase("f"))
{ //call method to read in the actor file
readActorFile(actorList);
}
}
//method for reading the actor file, taking in actor ArrayList- unsure of this
public static void readActorFile(ArrayList<Actor> actorList)
{
 
Scanner fileIn;
try
{
fileIn = new Scanner( new File("ActorsIn3.txt"));
while(fileIn.hasNext())
{
//loop for multiple actors may go here?
//adds one actor at the moment
Actor actor1 = new Actor(fileIn);
//adds actor1 to Actor ArrayList
actorList.add(actor1);
}
}
catch(FileNotFoundException fileNotFoundException)
{
System.err.println("Error opening file.");
System.exit(1);
}
//print actor ArrayList
System.out.print(actorList);
}
}
View Actor.java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151
 
package newcommunitytheatertest;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.Random;
/**
*
* @author
* This class is the super class for the people of the theater.
*/
public class TheaterPerson {
private String lastName;
private String firstName;
private int idNum;
private String personAddress;
private Calendar dateOfBirth;
private Calendar hireDate;
private BankAccount personAccount;
private int bankAcctNum;
public TheaterPerson()
{
this.lastName = "";
this.firstName = "";
this.personAddress ="";
this.idNum = 0;
}//setting to null or empty
 
public String getLastName() {
return lastName;
}
 
public void setLastName(String lastName) {
this.lastName = lastName;
}
 
public String getFirstName() {
return firstName;
}
 
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public Calendar getDateOfBirth() {
return dateOfBirth;
}
 
/**
* This method sets the date of birth for a person, uses java calendar class
* @param dayOfBirth
* @param monthOfBirth
* @param yearOfBirth
*/
public void setDateOfBirth(int dayOfBirth, int monthOfBirth, int yearOfBirth) {
dateOfBirth = Calendar.getInstance();
if(((dayOfBirth > 0)&&(dayOfBirth < 32))&&((monthOfBirth >0)&&(monthOfBirth <13)) && ((yearOfBirth > 1900)&& (yearOfBirth < 2013)))
{
this.dateOfBirth.set(yearOfBirth, (monthOfBirth-1), dayOfBirth);
}
else{
System.out.println("\nInvalid date entered. Default set.");
this.dateOfBirth.set(1980, 1, 1);
}
}
public double getIdNum() {
return idNum;
}
//sets ID number, checks for negative
public void setIdNum(int idNum) {
if(idNum > 0)
{//checking for positive ID number
this.idNum = idNum;
}
else
{
int n = 139999;
Random randomId = new Random();
//set random number for ID num
this.idNum = randomId.nextInt(n);
}
}//end method setIdNum
public String getPersonAddress() {
return personAddress;
}
 
public void setPersonAddress(String personAddress) {
this.personAddress = personAddress;
}
 
public Calendar getHireDate() {
return hireDate;
}
 
/**
*
* This method sets the hire date/date of purchase for theater person.
* @param month
* @param day
* @param year
*/
public void setHireDate(int day, int month, int year) {
hireDate = Calendar.getInstance();
if(((day > 0)&&(day < 32))&&((month >0)&&(month <13)) && ((year > 1900)&& (year < 2013)))
{
this.hireDate.set(year, (month-1), day);
}
else{
System.out.println("\nInvalid date entered. Default set.");
this.hireDate.set(2010, 1 , 1);
}
}
public BankAccount getPersonAccount() {
return personAccount;
}
 
public void setPersonAccount(int acctNum) {
this.personAccount = new BankAccount(acctNum);
}
public int getBankAcctNum()
{
return personAccount.getAccountNumber();
}
 
@Override
public String toString()
{
SimpleDateFormat sdf = new SimpleDateFormat("dd/M/yyyy");
return String.format("\n" + firstName +" "+ lastName + "\nDate of Birth: " + sdf.format(dateOfBirth.getTime()) +"\nHire Date: " + sdf.format(hireDate.getTime()) + "\nAddress: " + personAddress + "\nID Number: " + idNum );
}
}//end TheaterPerson class
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.