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();
}
}
I need that in Java CSCI 24000- Fall 2017 Assignment #3-Class-v Players Due: 10/9/2017 This third...
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 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 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 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 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. 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 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 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 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 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...