Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java problem 1. how to initialized dateTimeformatter? 2. how to makeDefaultQuiz() populate the questionAnswer ArrayList with the questions and answers. =============================GIVEN========================================= ==========================Main.java======================================= package asmt01; import

Java problem

1. how to initialized dateTimeformatter?

2. how to makeDefaultQuiz() populate the "questionAnswer" ArrayList with the questions and answers.

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

==========================Main.java=======================================

package asmt01;

import java.time.LocalDate; 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; private String tmpString; // Quiz private Quiz 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 < numDots; i++) { try { TimeUnit.SECONDS.sleep(1); } catch (InterruptedException ex) { Logger.getLogger(ChatSession.class.getName()).log(Level.SEVERE, null, ex); } if (i == 4) { // Connected. Display player info. System.out.println(this.player.toStringPlayerInfo()); } System.out.print(" ."); } System.out.println(""); }

// 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]; int numCards = 0; for (int i = 1; i <= numCards; 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]); }

public String getQuiz() { return this.getQuiz(); } // Perfect = Free tickets to Log // No Perfect = No Log private void runQuiz() { System.out.println(this.messages[13]); } // Set quiz private void setQuiz() { this.quiz = quiz; } // Run Quiz

private void endChatSession() {

// Write Log }

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

=========================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(); }

private void makeDefaultQuiz() { Scanner input = new Scanner(System.in); System.out.println("Which type of class has 'protected' constructors?"); String constructor = input.nextLine(); if (input.equalsIgnoreCase("Abstract")) { System.out.println("Correct!"); } else { System.out.println("Incorrect!"); } System.out.println("What type of method did Java 8 add to Interface?"); String method = input.nextLine(); if (input.equalsIgnoreCase("Default")) { System.out.println("Correct!"); } else { System.out.println("Incorrect!"); } System.out.println("Giants in Spanish?"); String spanish = input.nextLine(); if (input.equalsIgnoreCase("Gigantes")) { //If the input is Lincoln (or any case variant of Lincoln) System.out.println("Correct!"); } else { //If the input is anything else System.out.println("Incorrect!"); } } 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() { System.out.println("Free tickets to SF Giants games this summer! Ace this quiz:"); makeDefaultQuiz(); }

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

}

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

Essentials of Database Management

Authors: Jeffrey A. Hoffer, Heikki Topi, Ramesh Venkataraman

1st edition

133405680, 9780133547702 , 978-0133405682

Students also viewed these Databases questions