Question

I need that in Java
CSCI 24000- Fall 2017 Assignment #3-Class-v Players Due: 10/9/2017 This third assignment will allow you to explore (by comparing and contrasting through construction and implementation) two different object-oncnted programman罨languages (C++ and Javal You will be creating tme scparate programs-onc written in C++ and on written in Java For this assignment, we are going to explore how we can use objects to build more expressive and cleaner programs. In honor of football season we are going to be creating Players for our IUPUI football team Undefeated since 1969). We will need to create and stoee these Players in memory and allow the user to view an entire roster of Players. We will make the following assumpcions No two Players will have the same name (eg.,鲟Test Testerson. 2 Test Teserson). No two Players can have the same number (eg.. #, Jane Testrson·#2 Jame Testerson). Each Player MUST have at-least a first name, last name, and jersey Bumber * ◆ *In the basic submission there will only be, at maximum, eleven(11) Players on our icam Your goal is to create a peogram that will allow for creation and viewing of Players from our Team. Development Process: For this assignment, all development must take place on the master branch in a private GitHub repository. You must add me and all four (4) TAs as collaborators to your repository, It is stronglhy recommended that you commit and push often! We will be chocking to make sure that you are actively pushing changes to your repository-failure to do so will result in a deduction of points We will also be checking that you are providing useful comments with your commits-failure to do so will result in a deduction of ports. You are also required to include the Honor Ple ge and Digital Signature each one of your files (any file that you have writtien code in-you nood to include the Honor Pledge and Digital Signature). You are required to implement the following items as part of this assignment: .Your C++program mast contain three files (2.qpp and 1 h file). These files should be mamed as such: Driver.cpp, Player.cpp, Player.h .Your Java program must contain the following two files: Driverjava and Player.java * Array on the Heap Your Driver class must store any and all created Players in This Amay must make use of dynamic memory allocation. to manage our memory accordingly-nommory o You can use Valgrind to check our program for memory leaks- any leaks in memory will result in a deduction of points. When you start the program, you should provide the user with a menu choice to do one of the * . Add New Player 2 View Players 3. Exit Program Upon completion of Options #1 or #2 the menu should once again be displayed to the user . thus allowing them to make another selection. This process should continue to loop unil the user selections Option 3. Oncelf eleven (11) Players have been entered the program should print the roster and terminate * Below is example output of what your prog this exactly when executed-your format must match 1 of 3

media%2F4bc%2F4bce98bd-8a1c-4466-b299-f7

0 0
Add a comment Improve this question Transcribed image text
Answer #1

import java.util.Scanner;

class Player {
// to store array
private char a[] = new char[5];
private int index = 0;
private final char horse[] = { 'H', 'O', 'R', 'S', 'E' };

public char[] getA() {
return a;
}

public void setA(char[] a) {
this.a = a;
}

public int nextShot() {
return (int) (Math.random() * 10);
}

public boolean hasLost() {
return "HORSE".equals(String.valueOf(this.a));
}

public char add() {
if (index < a.length) {
a[index] = horse[index];
index++;
}
  
return a[index-1];
}
}

// --------------- Class Game ---------------------------

class Game {

public void startGame() {
Scanner sc = new Scanner(System.in);
System.out.println("Starting Game");
while (true) {

System.out.println("Player1 created");
Player player1 = new Player();
System.out.println("Player2 created");
Player player2 = new Player();
  
while(true) {
  
if(player1.hasLost()) {
System.out.println("\n\nPlayer 2 Wins :: Player 1 = HORSE\n");
break;
}
  
if(player2.hasLost()) {
System.out.println("\n\nPlayer 1 Wins :: Player 2 = HORSE\n");
break;
}
  
// player2 hit when nextShot is even   
boolean hit1 = player1.nextShot()%2==0;
// player2 hit when nextShot is Odd
boolean hit2 = player2.nextShot()%2==1;
  
if(hit1) {
System.out.println("Player #1: Hit Shot");
}else {
System.out.println("Player #1: Missed Shot");
}
  
if(hit2) {
System.out.println("Player #2: Hit Shot");
}else {
System.out.println("Player #2: Missed Shot");
}
  
if(!hit1 && !hit2) {
continue;
}
  
if(!hit1) {
System.out.println("\t\tPlayer #1: Added an "+player1.add());
}
  
if(!hit2) {
System.out.println("\t\tPlayer #2: Added an "+player2.add());
}
}

System.out.println("Would you like to play again (Y/N) ");
char c = sc.next().toLowerCase().charAt(0);
if (c == 'n') {
break;
}
}
  
System.out.println("Game Ends --- Thank you for playing");
}
}

//------------------------- Tester Class-------------------

public class TesterClass{

public static void main(String[] args) {

Game g = new Game();
g.startGame();
}
}

Add a comment
Know the answer?
Add Answer to:
I need that in Java CSCI 24000- Fall 2017 Assignment #3-Class-v Players Due: 10/9/2017 This third...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Written in Java Your job is to produce a program that sorts a list of numbers...

    Written in Java Your job is to produce a program that sorts a list of numbers in ascending order. Your program will need to read-in, from a file, a list of integers – at which point you should allow the user an option to choose to sort the numbers in ascending order via one of the three Sorting algorithms that we have explored. Your program should use the concept of Polymorphism to provide this sorting feature. As output, you will...

  • We have studied the following topics: How to interact with users via dialog boxes. Super class...

    We have studied the following topics: How to interact with users via dialog boxes. Super class and sub class. One- and two-dimensional arrays in Java. In this SLP assignment, we will make changes to our previous programs based on what we have learned. Write a Java application program to calculate property tax. Your program should have the following functions: Prompt users for the number of properties. Prompt users for property tax. Prompt users to input the value for each property...

  • need help with this assignment, please. Part 1 - Java program named MemoryCalculator In your Ubuntu...

    need help with this assignment, please. Part 1 - Java program named MemoryCalculator In your Ubuntu VM (virtual machine), using terminal mode ONLY, do the following: Create the folder program2 In this folder place the text file located on my faculty website in Module 2 called RAMerrors (Do not rename this file, it has no extension.) It is down below. Ths is the file RAMErrors 3CDAEFFAD ABCDEFABC 7A0EDF301 1A00D0000 Each record in this file represents the location of an error...

  • For this assignment, you will use your knowledge of arrays and ArrayLists to write a Java...

    For this assignment, you will use your knowledge of arrays and ArrayLists to write a Java program that will input a file of sentences and output a report showing the tokens and shingles (defined below) for each sentence. Templates are provided below for implementing the program as two separate files: a test driver class containing the main() method, and a sentence utilities class that computes the tokens and shingles, and reports their values. The test driver template already implements accepting...

  • Project 3 Instructions 1. Due Date & Time: 09-26-2020 at 11:59 PM WHAT TO SUBMIT Submit...

    Project 3 Instructions 1. Due Date & Time: 09-26-2020 at 11:59 PM WHAT TO SUBMIT Submit 1 zip file containing 4 files below to iLearn by the deadline. [30 points] ● 3 JAVA Files: TableBmiPro.java, MyOwnIdea.java. DiceRoll.java [24 points] ● 1 File: Make a document that shows the screen captures of execution of your programs and learning points in Word or PDF. Please make sure you capture at least 2 executions for 1 program, so 6 screen captures and one...

  • CS0007 Good day, I am in an entry-level Java class and need assistance completing an assignment....

    CS0007 Good day, I am in an entry-level Java class and need assistance completing an assignment. Below is the assignment criteria and the source code from the previous assignment to build from.  Any help would be appreciated, thank you in advance. Source Code from the previous assignment to build from shown below: Here we go! Let's start with me giving you some startup code: import java.io.*; import java.util.*; public class Project1 { // Random number generator. We will be using this...

  • In JAVA While out on a standard run we stop in at our ‘local’ fence and...

    In JAVA While out on a standard run we stop in at our ‘local’ fence and try to sell some of our items. When we board his ship we notice that we are the only people on board, so we instantly start grabbing things and loading them on our ship and get ready to run. While grabbing things we realize that we are going to run out of space extremely quickly and we should prioritize what we grab to maximize...

  • This is a quick little assignment I have to do, but I missed alot of class...

    This is a quick little assignment I have to do, but I missed alot of class due to the Hurricane and no one here knows what theyre doing. please help! this is Java with intelli-J Overview In this project students will build a four-function one-run calculator on the command line. The program will first prompt the user for two numbers, then display a menu with five operations. It will allow the user to select an option by reading input using...

  • This java assignment will give you practice with classes, methods, and arrays. Part 1: Player Class...

    This java assignment will give you practice with classes, methods, and arrays. Part 1: Player Class Write a class named Player that stores a player’s name and the player’s high score. A player is described by:  player’s name  player’s high score In your class, include:  instance data variables  two constructors  getters and setters  include appropriate value checks when applicable  a toString method Part 2: PlayersList Class Write a class that manages a list...

  • Could I get some help with this assignment In this assignment, you'll write a program which...

    Could I get some help with this assignment In this assignment, you'll write a program which reads a text file, and prints a histogram of its word sizes. So, for example, the historgram should show the number of words of length 1, of length 2, etc., up to the number of words of length n, where n is some constant defined in your program. To obtain text files that are suitably long, you could try Project Gutenberg, a site containing...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT