Need to create a map using Java, is going to be call Tmap.java with the followin
ID: 3565893 • Letter: N
Question
Need to create a map using Java, is going to be call Tmap.java with the following specifications:
1. Prompt the user to enter the half-width and half-height. The half-width is the number of locations on either side of the y axis. The half-height is the number of locations on either side of the x axis.
2. Prompt the user for the x and y coordinates of the treasure.
3. Mark the location of the treasure with a capital "X".
4. Mark the x axis with dashes (-).
5. Mark the y axis with vertical bars (|).
6. Mark the origin with a plus sign (+).
7. Mark the island with equals signs (=). The island will be determined by the boolean expression:
y*y <= (int)(r*r) - x*x
where
double r = Math.min(halfHeight, halfWidth) / 4 * Math.sin(10 * Math.atan((double) y / x) + 5) + 3 * Math.min(halfHeight, halfWidth) / 4;
Thus, inside your nested loops, whenever y*y <= (int)(r*r) - x*x, your program should print an equals sign (=).
8. Wherever there is not treasure, axis, or island, print out a space.
Explanation / Answer
please rate
import java.util.Scanner;
public class TMap {
int halfWidth, halfHeight;
int x,y;
private double getR(){
return Math.min(halfHeight, halfWidth) / 4 * Math.sin(10 * Math.atan((double) y / x) + 5) + 3 * Math.min(halfHeight, halfWidth) / 4;
}
private void getInput(){
Scanner input = new Scanner(System.in);
System.out.println("Enter half width: ");
halfWidth = input.nextInt();
System.out.println("Enter half height: ");
halfHeight = input.nextInt();
System.out.println("Enter x and y co-ord of tressure: ");
x = input.nextInt();
y = input.nextInt();
input.close();
}
private boolean isIsland(int x,int y){
if (y*y==(int)(getR()*getR())-(x*x))
return true;
return false;
}
private void drawMap(){
for(int i=-halfHeight;i<halfHeight;i++){
for(int j=-halfWidth;j<halfWidth;j++){
if(i==y&&j==x){
System.out.print("x");
}else if(isIsland(j, i)){
System.out.print("=");
}else if(i==0&&j==0)
System.out.print("+");
else if(i==0){
System.out.print("-");
}else if(j==0){
System.out.print("|");
}else{
System.out.print(" ");
}
}
System.out.println();
}
}
public TMap(){
getInput();
drawMap();
}
public TMap(int halfHeight, int halfWidth, int x,int y){
this.halfHeight = halfHeight;
this.halfWidth = halfWidth;
this.x = x;
this.y = y;
drawMap();
}
public static void main(String[] args){
new TMap();
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.