Answered step by step
Verified Expert Solution
Question
1 Approved Answer
public class Point { / / The fields inside every Point object private int x; private int y; / * * * Constructor that takes
public class Point The fields inside every Point object private int x; private int y; Constructor that takes values for both coordinates @param initX the xcoordinate of the point @param initY the ycoordinate of the point public Pointint initX, int initY this.x initX; this.y initY; Equals method to determine if two Point objects are equal @param other the other Point object to compare with @return true if the two points are equal, false otherwise public boolean equalsPoint other return thisx other.x && this.y other.y; ToString method to return a String representation of a Point object @return a String representation of the point in the format xy @Override public String toString return this.x this.y ; DistanceFromOrigin method to calculate the distance of this Point from the origin @return the distance of the point from the origin public double distanceFromOrigin return Math.sqrtthisx this.x this.y this.y; Getter methods for x and y public int getX return x; public int getY return y; Setter methods for x and y public void setXint x this.x x; public void setYint y this.y y; public static void mainString args Example usage Point p new Point; Point p new Point; System.out.printlnPoint p: p; System.out.printlnPoint p: p; System.out.printlnp equals p: pequalsp; System.out.printlnDistance from origin for p: pdistanceFromOrigin; Hangman.java import acm.program.; import java.ioFile; import java.ioFileNotFoundException; import java.util.Scanner; public class Hangman extends ConsoleProgram dimensions of window private static final int APPLICATIONWIDTH ; private static final int APPLICATIONHEIGHT ; public void run TODO: write this method Example: displayHangman; TODO: comment this method private void intro TODO: write this method TODO: comment this method private int playOneGameString secretWord TODO: write this method return ; TODO: comment this method private String createHintString secretWord String guessedLetters TODO: write this method return ; TODO: comment this method private char readGuessString guessedLetters TODO: write this method return ; TODO: comment this method private void displayHangmanint guessCount File file new Fileassetsdisplay guessCount txt; Scanner scanner; try scanner new Scannerfile; int linecounter ; while scannerhasNextLine String line scanner.nextLine; printlnline; canvas.printTextline; canvas.printDisplaydata linecounter; linecounter; scanner.close; catch FileNotFoundException e eprintStackTrace; TODO: comment this method private void statsint gamesCount, int gamesWon, int best TODO: write this method TODO: comment this method private String getRandomWordString filename TODO: write this method return ; public void init canvas new HangmanCanvas; setSizeAPPLICATIONWIDTH, APPLICATIONHEIGHT; addcanvas; canvas.reset; sample canvas method call printlnHello LBYCPEI!"; printlnThis is the next line!"; Solves NoClassDefFoundError public static void mainString args new Hangmanstartargs; private HangmanCanvas canvas; private HangmanCanvas canvas; HangmanCanvas.java import acm.program.; import java.ioFile; import java.ioFileNotFoundException; import java.util.Scanner; public class Hangman extends ConsoleProgram dimensions of window private static final int APPLICATIONWIDTH ; private static final int APPLICATIONHEIGHT ; public void run TODO: write this method Example: displayHangman; TODO: comment this method private void intro TODO: write this
public class Point
The fields inside every Point object
private int x;
private int y;
Constructor that takes values for both coordinates
@param initX the xcoordinate of the point
@param initY the ycoordinate of the point
public Pointint initX, int initY
this.x initX;
this.y initY;
Equals method to determine if two Point objects are equal
@param other the other Point object to compare with
@return true if the two points are equal, false otherwise
public boolean equalsPoint other
return thisx other.x && this.y other.y;
ToString method to return a String representation of a Point object
@return a String representation of the point in the format xy
@Override
public String toString
return this.x this.y ;
DistanceFromOrigin method to calculate the distance of this Point from the origin
@return the distance of the point from the origin
public double distanceFromOrigin
return Math.sqrtthisx this.x this.y this.y;
Getter methods for x and y
public int getX
return x;
public int getY
return y;
Setter methods for x and y
public void setXint x
this.x x;
public void setYint y
this.y y;
public static void mainString args
Example usage
Point p new Point;
Point p new Point;
System.out.printlnPoint p: p;
System.out.printlnPoint p: p;
System.out.printlnp equals p: pequalsp;
System.out.printlnDistance from origin for p: pdistanceFromOrigin;
Hangman.java
import acm.program.;
import java.ioFile;
import java.ioFileNotFoundException;
import java.util.Scanner;
public class Hangman extends ConsoleProgram
dimensions of window
private static final int APPLICATIONWIDTH ;
private static final int APPLICATIONHEIGHT ;
public void run
TODO: write this method
Example:
displayHangman;
TODO: comment this method
private void intro
TODO: write this method
TODO: comment this method
private int playOneGameString secretWord
TODO: write this method
return ;
TODO: comment this method
private String createHintString secretWord String guessedLetters
TODO: write this method
return ;
TODO: comment this method
private char readGuessString guessedLetters
TODO: write this method
return ;
TODO: comment this method
private void displayHangmanint guessCount
File file new Fileassetsdisplay guessCount txt;
Scanner scanner;
try
scanner new Scannerfile;
int linecounter ;
while scannerhasNextLine
String line scanner.nextLine;
printlnline;
canvas.printTextline;
canvas.printDisplaydata linecounter;
linecounter;
scanner.close;
catch FileNotFoundException e
eprintStackTrace;
TODO: comment this method
private void statsint gamesCount, int gamesWon, int best
TODO: write this method
TODO: comment this method
private String getRandomWordString filename
TODO: write this method
return ;
public void init
canvas new HangmanCanvas;
setSizeAPPLICATIONWIDTH, APPLICATIONHEIGHT;
addcanvas;
canvas.reset; sample canvas method call
printlnHello LBYCPEI!";
printlnThis is the next line!";
Solves NoClassDefFoundError
public static void mainString args
new Hangmanstartargs;
private HangmanCanvas canvas;
private HangmanCanvas canvas;
HangmanCanvas.java
import acm.program.;
import java.ioFile;
import java.ioFileNotFoundException;
import java.util.Scanner;
public class Hangman extends ConsoleProgram
dimensions of window
private static final int APPLICATIONWIDTH ;
private static final int APPLICATIONHEIGHT ;
public void run
TODO: write this method
Example:
displayHangman;
TODO: comment this method
private void intro
TODO: write this
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started