Answered step by step
Verified Expert Solution
Link Copied!

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 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
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database In Depth Relational Theory For Practitioners

Authors: C.J. Date

1st Edition

0596100124, 978-0596100124

Students also viewed these Databases questions

Question

5. How do economic situations affect intergroup relations?

Answered: 1 week ago

Question

a. When did your ancestors come to the United States?

Answered: 1 week ago

Question

d. What language(s) did they speak?

Answered: 1 week ago