-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProject0 (4).java
More file actions
176 lines (157 loc) · 6.98 KB
/
Project0 (4).java
File metadata and controls
176 lines (157 loc) · 6.98 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package project0;
import java.util.ArrayList;
import java.util.Scanner;
/**
*
* @author George.Pasparakis
*/
public class Project0 {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Scanner user_input = new Scanner(System.in);
// String name = question1("What is your name?", user_input);
makeTheQuestionsAndPrint(user_input);
}
// question template
public static String makeAQuestion(String message, Scanner uinput) {
System.out.println(message);
String rinput = uinput.next();
return(rinput);
}
// What is your name?
public static String question1(String message, Scanner uinput) {
String rinput = makeAQuestion(message,uinput);
return(rinput);
}
// What year you were born?
public static Integer question2(String message, Scanner uinput) {
String answer = makeAQuestion(message,uinput);
Integer rinput = Integer.parseInt(answer);
return(rinput);
}
// What is the name of the city you were born?
public static String question3(String message, Scanner uinput) {
String rinput = makeAQuestion(message,uinput);
return(rinput);
}
// Are you married?
public static boolean question4(String message, Scanner uinput) {
String answer = makeAQuestion(message,uinput);
boolean rinput;
if(answer.equals("yes") || answer.equals("Yes") || answer.equals("YES"))
rinput = true;
else
rinput = false;
return(rinput);
}
// How many years have you been married?
public static int question4a(String message, Scanner uinput) {
String answer = makeAQuestion(message,uinput);
int rinput = Integer.parseInt(answer);
return(rinput);
}
// What year did you get married?
public static int question4b(String message, Scanner uinput) {
String answer = makeAQuestion(message,uinput);
int rinput = Integer.parseInt(answer);
return(rinput);
}
// Do you have any children?
public static boolean question4c(String message, Scanner uinput) {
String answer = makeAQuestion(message,uinput);
boolean rinput;
if(answer.equals("yes") || answer.equals("Yes") || answer.equals("YES"))
rinput = true;
else
rinput = false;
return(rinput);
}
// How many children do you have?
public static int question4d(String message, Scanner uinput) {
String answer = makeAQuestion(message,uinput);
int rinput = Integer.parseInt(answer);
return(rinput);
}
// What is the name of your i child?
public static String question4e(String message, Scanner uinput) {
String rinput = makeAQuestion(message,uinput);
return(rinput);
}
// What is the age of your i child?
public static int question4f(String message, Scanner uinput) {
String answer = makeAQuestion(message,uinput);
int rinput = Integer.parseInt(answer);
return(rinput);
}
// What is your favourite color?
public static String question5(String message, Scanner uinput) {
String rinput = makeAQuestion(message,uinput);
return(rinput);
}
// group all questions together
public static void makeTheQuestionsAndPrint(Scanner uinput) {
int q4aa = 0;
int q4ba = 0;
boolean q4ca = false;
int q4da = 0;
ArrayList<String> names_of_children = new ArrayList<String>();
ArrayList<Integer> ages_of_children = new ArrayList<Integer>();
String q1a = question1("What is your name? ", uinput);
Integer q2a = question2("What year you were born? ", uinput);
String q3a = question3("What is the name of the city you were born? ", uinput);
boolean q4a = question4("Are you married? ", uinput);
if(q4a == true) {
q4aa = question4a("How many years have you been married? ", uinput);
q4ba = question4b("What year did you get married? ", uinput);
q4ca = question4c("Do you have any children? ", uinput);
if(q4ca) {
q4da = question4d("How many children do you have? ", uinput);
if(q4da > 0) {
for (int i = 0; i < q4da; i++) {
String name = question4e("What is the name of your " + (i + 1) + " child? ", uinput);
Integer age = question4f("What is the age of your " + (i + 1) + " child? ", uinput);
names_of_children.add(name);
ages_of_children.add(age);
}
}
}
}
String q5a = question5("What is your favourite color? ", uinput);
printTheOutput(q1a, q2a, q3a, q4a, q4aa, q4ba, q4ca, q4da, names_of_children, ages_of_children, q5a);
}
// Dear {name}, your were born in {year} so you are {age} and born in the city of {city}.
// You are not married and your favourite color is {color}.
// and you don't have any children.
// and you have X children.
// The name of your i child is {nameOfChild_i} and was born in the year of {bornYearChild_i}.
// Your favourite color is {color}.
public static void printTheOutput(String name, Integer year, String city, boolean married, int years_married, int year_of_marriage, boolean have_children, int no_of_children, ArrayList<String> names_of_children, ArrayList<Integer> ages_of_children, String color) {
System.out.println("Dear " + name + ", your were born in " +
year + " so you are " +
(2020 - year) + " and born in the city of " +
city + ".");
if(married == true) {
System.out.print("You have been married for " + years_married + " years and you got married in " + year_of_marriage);
if(!have_children)
System.out.println(" and you don't have any children.");
else {
System.out.println(" and you have " + no_of_children + " children.");
// print the details of all the children
for (int i = 0; i < names_of_children.size(); i++) {
System.out.println("Name of child: " + names_of_children.get(i));
System.out.println("Age of child: " + ages_of_children.get(i));
}
}
System.out.println("Your favourite color is " + color + ".");
} else {
System.out.println("You are not married and your favourite color is " + color + ".");
}
}
}