-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTester.java
More file actions
90 lines (81 loc) · 3.82 KB
/
Tester.java
File metadata and controls
90 lines (81 loc) · 3.82 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package Test;
import java.util.Scanner;
/**
*
* @author asraf
*/
public class Tester { //Submit Connfession Post
static Load data = new Load();
public static void main(String[] args) {
intro();
}
public static void intro(){
Scanner in = new Scanner(System.in);
System.out.println("===============================================================");
System.out.println(">> Please enter the confession poast ID you want to reply.");
System.out.println(">> Leave it blank if you don't want to reply a confession post.");
System.out.println("---------------------------------------------------------------");
System.out.print("Reply confession post ID: ");
String input = in.nextLine();
// String str = "UM04";
System.out.println("---------------------------------------------------------------");
searchPublishedPost(data.tree,input);
String newID = preEnterConfession(input);
postDetail(data.tree, newID);
showAllReplies(data.tree);
}
public static void searchPublishedPost(ReplyNode<ConfessionPost> tree, String input){
Boolean postFound = false;
for (ReplyNode<ConfessionPost> node : tree){
if(node.data.toString().contains(input)){
System.out.println(">> Confession post ID exists!");
System.out.println("===============================================================");
postFound = true;
}
}
if(!postFound){
System.out.println(">> Confession post ID doesn't exists!");
System.out.println("===============================================================");
}
}
public static String enterConfession(String input){
Scanner in = new Scanner(System.in);
ConfessionPost newPost = new ConfessionPost();
System.out.println("===============================================================");
System.out.println(">> Please enter your confession content.");
System.out.println(">> Insert \"-1\" to submit your confession.");
System.out.println("---------------------------------------------------------------");
System.out.println("Confession content:");
String str="", content="";
while(!str.equals("-1")){
content += str;
str = in.nextLine();
}
String newID = newPost.addPost(content);
data.insertData(input,newPost);
System.out.println("===============================================================");
return newID;
}
public static String preEnterConfession(String input){
String newID;
newID = enterConfession(input);
return newID;
}
public static void postDetail(ReplyNode<ConfessionPost> tree,String id){
System.out.println("===============================================================");
System.out.println(">> Submitted at " + data.searchData(id).data.getTime());
System.out.println(">> Confession post ID " + data.searchData(id).data.getID());
System.out.println(">> Your confession will be published soon.");
System.out.println("===============================================================");
}
public static void showAllReplies(ReplyNode<ConfessionPost> tree){
for (ReplyNode<ConfessionPost> node : tree){
System.out.println(node.data);
System.out.println(node.getLevel());
}
}
}