Question: 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 x-coordinate of the point
* @param initY the y-coordinate of the point
*/
public Point(int 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 equals(Point other){
return (this.x == 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 (x,y)
*/
@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 (0,0)
*/
public double distanceFromOrigin(){
return Math.sqrt(this.x * 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 setX(int x){
this.x = x;
}
public void setY(int y){
this.y = y;
}
public static void main(String[] args){
// Example usage
Point p1= new Point(3,4);
Point p2= new Point(3,4);
System.out.println("Point p1: "+ p1);
System.out.println("Point p2: "+ p2);
System.out.println("p1 equals p2: "+ p1.equals(p2));
System.out.println("Distance from origin for p1: "+ p1.distanceFromOrigin());
}
}
Hangman.java
import acm.program.*;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class Hangman extends ConsoleProgram {
// dimensions of window
private static final int APPLICATION_WIDTH =1080;
private static final int APPLICATION_HEIGHT =640;
public void run(){
// TODO: write this method
// Example:
displayHangman(0);
}
// TODO: comment this method
private void intro(){
// TODO: write this method
}
// TODO: comment this method
private int playOneGame(String secretWord){
// TODO: write this method
return 0;
}
// TODO: comment this method
private String createHint(String secretWord, String guessedLetters){
// TODO: write this method
return "";
}
// TODO: comment this method
private char readGuess(String guessedLetters){
// TODO: write this method
return '?';
}
// TODO: comment this method
private void displayHangman(int guessCount){
File file = new File("assets/display"+ guessCount +".txt");
Scanner scanner;
try {
scanner = new Scanner(file);
int line_counter =1;
while (scanner.hasNextLine()){
String line = scanner.nextLine();
println(line);
canvas.printText(line);
// canvas.printDisplay(data, line_counter);
line_counter++;
}
scanner.close();
} catch (FileNotFoundException e){
e.printStackTrace();
}
}
// TODO: comment this method
private void stats(int gamesCount, int gamesWon, int best){
// TODO: write this method
}
// TODO: comment this method
private String getRandomWord(String filename){
// TODO: write this method
return "";
}
public void init(){
canvas = new HangmanCanvas();
setSize(APPLICATION_WIDTH, APPLICATION_HEIGHT);
add(canvas);
canvas.reset(); // sample canvas method call
println("Hello LBYCPEI!");
println("This is the next line!");
}
/* Solves NoClassDefFoundError */
public static void main(String[] args){
new Hangman().start(args);
}
// private HangmanCanvas canvas;
private HangmanCanvas canvas;
}
HangmanCanvas.java
import acm.program.*;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class Hangman extends ConsoleProgram {
// dimensions of window
private static final int APPLICATION_WIDTH =1080;
private static final int APPLICATION_HEIGHT =640;
public void run(){
// TODO: write this method
// Example:
displayHangman(0);
}
// TODO: comment this method
private void intro(){
// TODO: write this
 public class Point { // The fields inside every Point object

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!