Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java Problem your program must produce identical output to sample output Please do not change or remove the provided code but you can add. Here

Java Problem

your program must produce identical output to sample output Please do not change or remove the provided code but you can add.

Here is the sample:

image text in transcribed

image text in transcribed

=============================GIVEN=========================

============================Card.java========================

package asmt01;

public class Card {

private Student student; private String cardRecipient; private String cardMessage;

public String toString() { String returnString; returnString = "From: " + this.student + " \t Recipient: " + this.cardRecipient + " \t Message: " + this.cardMessage; return returnString; } }

===========================ChatSession.java=================================

package asmt01;

import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.util.Scanner; import java.util.concurrent.TimeUnit; import java.util.logging.Level; import java.util.logging.Logger;

public class ChatSession {

// Text and Background Colors public static final String ANSI_RESET = "\u001B[0m"; public static final String ANSI_YELLOW = "\u001B[33m"; public static final String ANSI_PURPLE_BACKGROUND = "\u001B[45m";

// Chat private final DateTimeFormatter dateTimeFormatter; private final String[] messages;

// Club - Player - Student private final Club club; private final String clubPrompt; private final Player player; private final String playerPrompt; private final Student student; private String studentPrompt;

// Quiz

// Constructor public ChatSession(Club club, Player player) { }

// Session Initialization private void startChatSession() { // Set Messages this.messages[0] = " Chat session started."; this.messages[1] = " " + this.clubPrompt + "Welcome to " + club.getCurrentOfficialName().toUpperCase() + "!"; this.messages[2] = " " + this.clubPrompt + "Your first and last name, please: "; this.messages[3] = this.clubPrompt + "Your school email address, please: "; this.messages[4] = this.clubPrompt + "Thank you. Connecting with a SF Giants player"; this.messages[5] = " Chat session ended.";

// Get Student Info System.out.print(this.messages[1]); System.out.println(this.club.toString()); System.out.print(this.messages[2]); System.out.print(this.messages[3]);

// Set Messages this.messages[6] = "Hello " + this.student.getFirstName() + "! C-O-N-G-R-A-T-U-L-A-T-I-O-N-S! "; this.messages[7] = ChatSession.ANSI_PURPLE_BACKGROUND + ChatSession.ANSI_YELLOW + Student.SCHOOL_NAME.toUpperCase() + ANSI_RESET + ". Way to go!"; this.messages[8] = "Likewise, " + this.student.getFirstName() + ". Very nice chatting w/ you."; this.messages[9] = "How many SF Giants Thank You cards are you getting?"; this.messages[10] = "In 2 lines, Name and Message for "; this.messages[11] = "Thanks, " + this.student.getFirstName() + ". Your order: "; this.messages[12] = "Thanks again, " + this.student.getFirstName() + ". See you at your graduation ceremony!"; this.messages[13] = " FREE tickets to SF Giants games this summer! Ace this quiz:"; this.messages[14] = "See you at the summer games!!!"; this.messages[15] = " ***FREE tickets to summer games!***"; this.messages[16] = "Thank you!"; }

// Connect Student w/ Player private void connectStudentPlayer() {

// Connecting... System.out.print(this.messages[4]); int numDots = 10; for (int i = 1; i

// Chat: Student & Player private void chatStudentPlayer() {

// Congrats System.out.println(this.playerPrompt + this.messages[6]); System.out.println(this.playerPrompt + this.messages[7]); System.out.print(this.studentPrompt);

// Ask # of Cards System.out.println(this.playerPrompt + this.messages[8]); System.out.println(this.playerPrompt + this.messages[9]); System.out.print(this.studentPrompt);

// Recipient and Message for each card this.tmpString = this.messages[10]; for (int i = 1; i

this.tmpString = this.tmpString + "the Card #" + i + ", please:"; System.out.println(this.playerPrompt + this.tmpString);

// Recipient System.out.print(this.studentPrompt);

// Message System.out.print(this.studentPrompt);

}

// Order Summary System.out.println(this.playerPrompt + this.messages[11]); this.student.listCards();

// Student confirms System.out.print(this.studentPrompt);

// Player leaves System.out.println(this.playerPrompt + this.messages[12]); }

// Perfect = Free tickets to Log // No Perfect = No Log private void runQuiz() { System.out.println(this.messages[13]); // Set quiz

// Run Quiz }

private void endChatSession() {

// Write Log }

// A Chat Session public void runChatSession() { this.startChatSession(); this.connectStudentPlayer(); this.chatStudentPlayer(); this.runQuiz(); this.endChatSession(); } }

===========================Club.java====================

package asmt01;

import java.util.ArrayList; import java.util.Arrays;

public class Club {

public Club() { }

public void listPlayers() { System.out.println("Players:"); this.players.forEach((player) -> { System.out.println(player + " "); }); }

public String toString() { String returnString; returnString = " ---" + " Club: \t\t\t" + this.currentOfficialName + " Short Name: \t\t" + this.shortName + " President: \t\t" + this.presidentOfBaseballOperations + " General Manager: \t" + this.generalManager + " Manager: \t\t" + this.manager; return returnString; } }

=================================FrontOffice.java===================================

package asmt01;

/*

**************************** PLEASE DO NOT CHANGE THIS FILE ***********

*/

public abstract class FrontOffice extends Person {

private Club baseballClub;

protected FrontOffice() { }

protected FrontOffice(String firstName, String lastName, Club baseballClub) { super(firstName, lastName); this.baseballClub = baseballClub; }

public abstract String toStringAboutInfo (); }

=======================GeneralManager.java==============================

package asmt01;

public class GeneralManager extends FrontOffice {

private final String POSITION = "General Manager";

private Club baseballClub;

public GeneralManager() {

}

public GeneralManager(String firstName, String lastName, Club baseballClub) { super(firstName, lastName, baseballClub); }

public String toStringAboutInfo() { return " --- I controls player transactions and bears the primary responsibility " + "on behalf of the ballclub during contract discussions with players."; } }

=============================Greeting.java===============================

package asmt01;

/** * **************************** PLEASE DO NOT CHANGE THIS FILE *********** */ public interface Greeting {

public static final String HELLO = "Hello there!"; public static final String SFSU_ENGLISH_HELLO = "Hello Gators!"; public static final String SFSU_SPANISH_HELLO = "Hola Caimanes!"; public static final String SFGIANTS_ENGLISH_HELLO = "Hello Giants!"; public static final String SFGIANTS_SPANISH_HELLO = "Hello Gigantes!";

public default void sayHello() { System.out.println(Greeting.HELLO); }

public abstract void sayHello(String name); }

===========================Log.java================================

package asmt01;

import java.io.BufferedWriter; import java.io.FileWriter; import java.io.IOException; import java.util.ArrayList;

public class Log {

private final String LOG_FILE_RELATIVE_PATH; private String startTime; private String endTime; private Player player; private Student student; private final ArrayList logData; private String logFileAbsolutePath; private final String logFileRelativePath; private String logFileName;

public Log() { this.logData = new ArrayList(); /** * ************* Please match your file path *********************** */ this.LOG_FILE_RELATIVE_PATH = "src/asmt01/"; this.logFileRelativePath = this.LOG_FILE_RELATIVE_PATH; }

public Log(String startTime, String endTime, Player player, Student student, ArrayList logData, String logFileAbsolutePath, String logFileRelativePath, String logFileName) { /** * ************* Please match your file path *********************** */ this.LOG_FILE_RELATIVE_PATH = "src/asmt01/"; this.startTime = startTime; this.endTime = endTime; this.player = player; this.student = student; this.logData = logData; this.logFileAbsolutePath = logFileAbsolutePath; this.logFileRelativePath = this.LOG_FILE_RELATIVE_PATH; this.logFileName = logFileName; }

public void setStartTime(String startTime) { this.startTime = startTime; }

public void setEndTime(String endTime) { this.endTime = endTime; }

public void setPlayer(Player player) { this.player = player; }

public void setStudent(Student student) { this.student = student; }

public ArrayList getLogData() { return logData; }

public String getLogFileRelativePath() { return logFileRelativePath; }

public String getLogFileName() { return logFileName; }

public void setLogFileName(String logFileName) { this.logFileName = logFileName; }

public void addLog(String logLine) { this.logData.add(logLine); }

public void addLogPrint(String logLine) { this.addLog(logLine); System.out.println(logLine); }

public void writeLogToFile(String relativePath, String fileName, ArrayList log) {

String filePath = relativePath + fileName;

try (BufferedWriter bufferWriter = new BufferedWriter(new FileWriter(filePath))) { for (String line : log) { bufferWriter.write(line + " "); }

bufferWriter.close();

} catch (IOException e) { System.err.println("ERROR: " + e.toString()); }

} }

================================Manager.java===============================

package asmt01;

public class Manager extends FrontOffice {

private final String POSITION = "Manager"; private Club baseballClub;

public Manager() {

}

public Manager(String firstName, String lastName, Club baseballClub) { super(firstName, lastName, baseballClub); }

public String toStringAboutInfo() { return " --- I am the a head coach who is responsible for overseeing and " + "making final decisions on all aspects of " + "on-field team strategy, lineup selection, " + "training and instruction."; } }

===============================Messenger.java=====================

package asmt01;

/** * **************************** PLEASE DO NOT CHANGE THIS FILE *********** */ public class Messenger {

public static void main(String[] args) {

/* SF Giants */ int yearEstablished = 1883; String[] owners = {"San Francisco Baseball Associates LLC"}; String[] colors = {"Orange", "Black", "Gold", "Cream"}; String currentOfficialName = "San Francisco Giants"; String shortName = "SF Giants"; String currentBallpark = "AT&T"; int numWorldSeriesTitles = 8; int numNLPennants = 23; int numDivisionTitles = 8; int numWildCardBerths = 3; Club sfGiants = new Club();

/* SF Giants Front Office */ // President of Baseball Operations President presidentOfBaseballOperations = new President("Brian", "Sabean", sfGiants); // General Manager GeneralManager generalManager = new GeneralManager("Bobby", "Evans", sfGiants); // General Manager manager = new Manager("Bruce", "Bochy", sfGiants);

/* SF Giants Club */ sfGiants = new Club(yearEstablished, owners, colors, currentOfficialName, shortName, currentBallpark, numWorldSeriesTitles, numNLPennants, numDivisionTitles, numWildCardBerths, manager, generalManager, presidentOfBaseballOperations);

/* SF Giants Players */ // Buster Posey, Madison Bumgarner Player[] players = { new Player("Buster", "Posey", "Catcher", "Right", "Right", 2009, sfGiants, 28), new Player("Madison", "Bumgarner", "Starting Pitcher", "Right", "Left", 2009, sfGiants, 40) };

// Add players to club sfGiants.addPlayers(players);

/* Chat Sessions */ Player sfGiantsPlayer = sfGiants.getPlayers().get(0); ChatSession chatBox = new ChatSession(sfGiants, sfGiantsPlayer); chatBox.runChatSession();

/* A few tests: */ System.out.println(""); System.out.println("---test INTERFACE"); sfGiantsPlayer.sayHello(); sfGiantsPlayer.sayHello(manager.getFirstName());

System.out.println("---test ABSTRACT CLASS"); System.out.println(presidentOfBaseballOperations.toStringAboutInfo()); System.out.println(generalManager.toStringAboutInfo()); System.out.println(manager.toStringAboutInfo());

System.out.println("---test CLASS ASSOCIATION"); if (sfGiantsPlayer instanceof Person) { System.out.println("YES!"); } if (presidentOfBaseballOperations instanceof Person) { System.out.println("YES!"); } if (generalManager instanceof Person) { System.out.println("YES!"); } if (manager instanceof Person) { System.out.println("YES!"); }

System.out.println("---test QUIZ"); chatBox.getQuiz().printQuiz();

System.out.println("---test LOG FILE"); System.out.println(chatBox.getLog().getLogFileRelativePath()); System.out.println(chatBox.getLog().getLogFileName());

System.out.println("---test LOG"); chatBox.getLog().getLogData().forEach((line) -> { System.out.println(line); });

} }

============================Person.java=============================

package asmt01;

public class Person implements Greeting {

private String firstName; private String lastName;

public Person() { }

public Person(String firstName, String lastName) { this.firstName = firstName; this.lastName = lastName; }

public String toString() { return this.firstName + " " + this.lastName; }

public void sayHello(String name) { System.out.println("Hello " + name + "!"); } }

=====================Player.java===============================

package asmt01;

* **************************** PLEASE DO NOT CHANGE THIS FILE ***********

public class Player extends Person {

private String position; private String bats; private String throwz; private int yearMLBDebut; private Club club; private int number;

public Player() { }

public Player(String firstName, String lastName, String position, String bats, String throwz, int yearMLBDebut, Club club, int number) {

super(firstName, lastName); this.position = position; this.bats = bats; this.throwz = throwz; this.yearMLBDebut = yearMLBDebut; this.club = club; this.number = number; }

@Override public String toString() { return super.getFirstName() + " " + super.getLastName() + ", " + this.number + ""; }

public String toStringPlayerInfo() { String returnString; returnString = " ---" + " Player: \t" + super.toString() + " Club: \t\t" + this.club.getCurrentOfficialName() + " Position: \t" + this.position + " Number: \t" + this.number + " Bats: \t\t" + this.bats + " Throws: \t" + this.throwz + " MLB Debut: \t" + this.yearMLBDebut; return returnString; } }

=======================President.java===============================

package asmt01;

public class President extends FrontOffice {

private final String POSITION = "President of Baseball Operations";

public President() { }

public President(String firstName, String lastName, Club baseballClub) { super(firstName, lastName, baseballClub); }

public String toStringAboutInfo() { return " --- I oversee and control all club things."; } }

==============================QuestionAnswer.java=========================

package asmt01;

* **************************** PLEASE DO NOT CHANGE THIS FILE ***********

class QuestionAnswer {

private String question; private String answer;

public QuestionAnswer() {

}

public QuestionAnswer(String question, String answer) { this.question = question; this.answer = answer; }

public String getQuestion() { return question; }

public void setQuestion(String question) { this.question = question; }

public String getAnswer() { return answer; }

public void setAnswer(String answer) { this.answer = answer; }

@Override public String toString() { return this.question + " " + this.answer; } }

================================Quiz.java================================

package asmt01;

import java.util.ArrayList; import java.util.Scanner;

public class Quiz {

private String teacher; private String student; private final String topic; private final ArrayList questionAnswer;

public Quiz() { this.questionAnswer = new ArrayList(); this.topic = "OOP & SF Giants"; this.makeDefaultQuiz(); }

public String getTeacher() { return teacher; }

public void setTeacher(String teacher) { this.teacher = teacher; }

public String getStudent() { return student; }

public void setStudent(String student) { this.student = student; }

public void printQuiz() { }

// Return true when all answers are correct. public boolean runQuiz() { } }

============================Student.java================================

package asmt01;

import java.util.ArrayList;

public class Student extends Person {

public static final String SCHOOL_NAME = "San Francisco State University"; private String schoolEmailAddress; private int numCards; private final ArrayList cards;

public Student() { }

public Student(String firstName, String lastName, String schoolEmail) { super(firstName, lastName); this.schoolEmailAddress = schoolEmail; }

}

zun: Del 2018/02/04 02:42:21 Chat session started SF G iants: Welcome to SAN FRANCISCO GIANTS! Club: Short Name: Established in: Colors: Ballpark: World Series Titles: NL Fennants: Division Titles: Wild Card Berths: Owners: President: General Manager: Manager: San Francisco Giants SF Giants 1803 Orange, Black, Gold, Cream AT&T e 23 San Francisco Basebal1 Associates LLC Brian Sabean Bobby Evans Bruce Bochy SE Giants: Your first and last name, please: Duc Ta SF Giants: Your school email address, please: dta@sfsu.edu SF Giants: Thank you. Connecting with a SF Giants player . . . Flayer: Club: Position: Number: Buster Posey San Francisco Giants Catcher 28 Right Right 2009 Bats: Throws: MLB Debut: Buster Posey, 28: Hello Duc! C-0-N-G-R-A-T-U-L-A-T-I-O-N-S Buster Posey, 28: en Na-cm. Kay to go ! : Thank you! Nice to e-meet you, Posey Buster Fosey, 28: Likewise, Duc. Very nice chatting / you. Buster Posey, 28: How many SF Giants Thank You cards are you getting? Posey, 28: In 2 lines, Name and Message for the Card #1, please : Buster uc I Mom : Thank you, mom

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

C++ Database Development

Authors: Al Stevens

1st Edition

1558283579, 978-1558283572

More Books

Students also viewed these Databases questions