-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlotWord 2.java
More file actions
67 lines (62 loc) · 2.28 KB
/
PlotWord 2.java
File metadata and controls
67 lines (62 loc) · 2.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/*Sudipti Dantuluri
* 1.7.2022
* PlotWord.java
* The program plots the word on the coordinate grid with the given points.*/
import java.util.Scanner;
import java.util.Formatter;
public class PlotWord {
Scanner sc = new Scanner(System.in);
public static void main (String[]args) {
PlotWord pw = new PlotWord();
pw.pwMethod();
}
public void pwMethod() {
System.out.println("\n\n\n");
System.out.print("Please enter a coordinate: ");
int coordinateX = sc.nextInt();
int coordinateY = sc.nextInt();
System.out.print("What word would you like to plot? ");
String word = sc.next();
int depth = 6;
System.out.println("Hello"+ String.format("%"+depth+"s"," ") + "world" + "\n");
System.out.println(String.format("%"+depth+"s","aaa"));
//coordinateX += 19;
coordinateY *= -1;
coordinateY += 10;
System.out.println("X:" + coordinateX);
System.out.println("Y:" + coordinateY);
String vbar = "|";
for (int y = 0; y<= 20; y++) {
if (y == coordinateY) {
//System.out.println(String.format("%"+coordinateX+"s"," ") + word);
if (coordinateX > 0) {
System.out.print(String.format("%"+19+"s"," ") + vbar);
System.out.println(String.format("%"+coordinateX+"s"," ") + word);
//System.out.printf("%21s\n", vbar);
//coordinateX -= 18;
//System.out.println(String.format("%"+coordinateX+"s"," ") + word);
} else if (coordinateX < 0) {
System.out.println(String.format("%"+(19+coordinateX)+"s"," ") + word);
//System.out.println(String.format("%"+(19-coordinateX-word.length())+"s"," ") + vbar);
} else { // x-axis
for (int x=0;x<=19+coordinateX;x++) {
System.out.print("-");
}
System.out.print(word);
for (int x=0;x<=41-(19+coordinateX+(word.length()));x++) {
System.out.print("-");
}
System.out.println("");
//System.out.println(String.format("%"+(19-coordinateX-word.length())+"s"," ") + vbar);
}
} else {
if (y==10) {
for (int x=0;x<=41;x++) {
System.out.print("-");
}
System.out.println("");
} else System.out.printf("%20s\n", vbar);
}
}
} // end of pwMethod()
} // end of PlotWord()