View the step-by-step solution to:


Hey guys,

Can someone look over my code and tell me what I did wrong?


the assignment:

This component of the final exam will have two data structures. The two data structures will be a stack and the other will be a hashmap. The hashmap object will be added to the stack every time the user picks an answer. The hashmap will have a key and value. The key will be the timestamp (system time when the user selected a choice) and the value will be the choice the user picked. For example, if the question was Buffalo vs. Pittsburgh and the user picked Buffalo at 10pm, then the timestamp (key) will be 10pm and the value would be Buffalo. This hashmap object will then be added to the stack. You will have a hashmap object for every answer to the questions.  

Here what I did (my complier said there some error but I cant seemed to find them):

import java.text.SimpleDateFormat;

import java.util.Map;

import java.util.Iterator;

import java.util.Scanner;

import java.util.Stack;

class userNewChoices{

private Scanner scan = new Scanner(;

private Stack<Map> answers = new Stack<Map>();

public void close() {



public String getChoices(String choice1, String choice2) {


System.out.println("Please choose from the following options: ");

System.out.println("#1" + choice1);

System.out.println("#2" + choice2);

System.out.println("Enter your choice here: ");

String userChoice =;

return userChoice;


public void userStack(String userChoice) {

String timeStamp = new SimpleDateFormat("").format(new Date());

answers.put(timeStamp, userChoice);

((Stack<Map>) answers).push(answers);


public void printAnswerStack(){

Iterator userChoiceMap = answers.iterator();


System.out.println("User stacks are as fellowed ");


while(userChoiceMap.hasNext()) {





public class sportGames {

public static void main(String[] args) {


Top Answer

import java.text.SimpleDateFormat; import java.util.Map; import java.util.Date; import java.util.HashMap; import... View the full answer

Sign up to view the full answer

Why Join Course Hero?

Course Hero has all the homework and study help you need to succeed! We’ve got course-specific notes, study guides, and practice tests along with expert tutors.

  • -

    Study Documents

    Find the best study resources around, tagged to your specific courses. Share your own to gain free Course Hero access.

    Browse Documents
  • -

    Question & Answers

    Get one-on-one homework help from our expert tutors—available online 24/7. Ask your own questions or browse existing Q&A threads. Satisfaction guaranteed!

    Ask a Question