Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 6

COS315a - Java Programming Homework #1

Kirl Hadzhiyski 200146294

Photo above shows: First Screenshot with name string


parameter my name – Kiril Hadzhiyski!

Photo above shows us: Second screenshot with Landing


page, when you click on “here” link you are redirected
Photo above shows: Generating 6 details ( random
numbers ) between 0 and 6

Code from greeting.html


<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<title>Greeting</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
/>
<style>
.text {
font-size: 150%;
}
</style>
</head>
<body>
<p class="text" th:text="${greeting[0]} + ' ,' + ${greeting[1]} +
' ,' + ${greeting[2]} + ' ,' +
${greeting[3]} + ' ,' + ${greeting[4]} +' ,' + ${greeting[5]} "/>

</body>
</html>
Code from Greeting Controller.java

package edu.aubg.basic;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

@Controller
public class GreetingController {
@GetMapping("/greeting")
public String greeting(Model model) {
int min = 0;
int max = 6;

int randomNumber =0;


int[] detail = new int[6];
for(int i=0;i<6;i++) {
randomNumber = (int)Math.floor(Math.random()*(max-
min+1)+min);
detail[i] = randomNumber;
}
// name may be an empty string or a query string
// Assign name to “name”
model.addAttribute("greeting", detail);
// Return view greeting.html to browser
return "greeting";
}
}

Next Screenshots show to us the extending of the MVC


greeting app to display a greeting selected at random
while the app is run multiple times.
Photo above shows: the first run of the app

Photo above shows: second run of the app

The photo above shows: third run of the app


The photo above shows the fourth run of the app

Code from GreetingController.java


package edu.aubg.basic;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

@Controller
public class GreetingController {
@GetMapping("/greeting")
public String greeting(Model model) {
int min = 0;
int max = 5;
int random1 = (int)Math.floor(Math.random()*(max-min+1)+min);
int random2 = (int)Math.floor(Math.random()*(max-min+1)+min);
String[] greetingMessage= {"My name is ", "My Birthday is", "My street
adress is ", "My town is ","My father's name is ", "My mother's name is "};
String[] names= {"Kiril Hadzhiyski", "2 june 2001", "101 Ivan Rilski", "
Hristo"," Stanka", "Blagoevgrad"};
String details = greetingMessage[random1] + ", " + names[random2] + "!";
// name may be an empty string or a query string
// Assign name to “name”
model.addAttribute("greeting", details);
// Return view greeting.html to browser
return "greeting";

}
}

Code from greeting.html


<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<title>Greeting</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<style>
.text {
font-size: 150%;
}
</style>
</head>
<body>
<p class="text" th:text="${greeting}"/>
</body>
</html>

You might also like