-
Notifications
You must be signed in to change notification settings - Fork 0
/
PersonalWebPageGenerator.java
74 lines (62 loc) · 2.25 KB
/
PersonalWebPageGenerator.java
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
/**
* The program asks the user for their name and a
* description of themselves. It then generates an
* HTML file that displays this information.
*/
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Scanner;
public class PersonalWebPageGenerator {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
// Ask for user's name
System.out.print("Enter your name: ");
String name = scanner.nextLine();
// Ask for user's description
System.out.print("Describe yourself: ");
String description = scanner.nextLine();
// Create an HTML file
try {
PrintWriter writer = new PrintWriter(new FileWriter("personal_webpage.html"));
// Write HTML content to the file
writer.println("<html>");
writer.println("<head>");
writer.println("<title>" + name + "'s Personal Web Page</title>");
writer.println("</head>");
writer.println("<body>");
writer.println("<center><h1>" + name + "</h1></center>");
writer.println("<hr />");
writer.println("<p>" + description + "</p>");
writer.println("<hr />");
writer.println("</body>");
writer.println("</html>");
writer.close();
System.out.println("Web page created successfully: personal_webpage.html");
} catch (IOException e) {
System.out.println("An error occurred while creating the web page.");
e.printStackTrace();
}
scanner.close();
}
}
/**
* Explanation:
The program asks the user for their name and a description.
It generates an HTML file called personal_webpage.html that
contains this information in a simple HTML structure.
The user's name is displayed as a heading (<h1>), and the
description is displayed as a paragraph (<p>).
Example Output in HTML:
<html>
<head>
<title>Julie Taylor's Personal Web Page</title>
</head>
<body>
<center><h1>Julie Taylor</h1></center>
<hr />
<p>I am a computer science major, a member of the Jazz club, and I hope to work as a mobile app developer after I graduate.</p>
<hr />
</body>
</html>
*/