Skip to content
Navigation Menu
Sign in
Products
Platform
GitHub
Repository hosting, code review, and collaboration
Copilot
AI coding agent for tasks, projects, and automated work
Build & Ship
Actions
CI/CD and automation
Code Quality
Quality analysis, fixes, and enforcement
Codespaces
Cloud development environments
Secure
Code Security
Vulnerability detection and remediation
Secret Protection
Secret scanning and leak prevention
All Features
Developers
Learn
Documentation
Training
Certifications
Build
Build with Copilot
Customize Copilot
Integrations
Explore
Trending repos
GitHub Sponsors
Developer articles
Changelog
Changelog
Your source for the latest features, improvements, and fixes across GitHub products, all in one place.
Businesses
By Stage
Enterprises
Team
Startups
Nonprofits
By Industry
Healthcare
Financial services
Manufacturing
Government
See all industries
Evaluate GitHub
Why GitHub
Customer Stories
Business insights
Trust Center
Add-ons
GitHub Advanced Security
Enterprise-grade code security
Copilot for business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Resources
Learn & Connect
Documentation
Resource center
Blog
Events & webinars
Community Forum
Customer Stories
Integrations
Support
Customer support
Training
GitHub Status
Company
About
Partners
Changelog
GitHub Universe
GitHub Universe
The event for developers, by developers — talks, workshops, and what’s next for GitHub.
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
hyebin-dev
java-practice
Repository navigation
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
More
items
Files
Expand file tree
main
Breadcrumbs
java-practice
/
week02
/
advanced
/
Blog.java
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
44 lines (37 loc) · 1.46 KB
main
Breadcrumbs
java-practice
/
week02
/
advanced
/
Blog.java
Copy path
Top
File metadata and controls
Code
Blame
44 lines (37 loc) · 1.46 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
package week02.advanced;
public class Blog {
String blogTitle;
Post [] posts = new Post[100];
int postCount = 0;
Blog(String blogTitle){
this.blogTitle = blogTitle;
System.out.println("<" + blogTitle + ">");
}
void writePost(String title,String content) {
if (postCount == posts.length) {
System.out.println("블로그 최대 포스팅 수는 100개입니다.");
return;
}
posts[postCount] = new Post(title, content);
postCount++;
}
void listPosts() {
if (postCount == 0) {
System.out.println("포스팅 된 글이 없습니다.");
return;
}
for (int i = 0; i < postCount; i++) {
System.out.println(posts[i].title);
}
}
// 26단계 (심화): 블로그와 포스트 관계 모델링
// 문제:
// 1. Post.java: 제목(title), 내용(content)을 멤버로 가집니다.
// 2. Blog.java: 블로그 제목(blogTitle)과 Post 객체 배열(posts, 크기 100),
// 현재 포스트수(postCount)를 멤버로 가집니다. 글을 쓰는 writePost(String title,
// String content)메서드와, 블로그의 모든 포스트 제목을 출력하는 listPosts()
// 메서드를구현하세요.
// 핵심 사고: 일대다(One-to-Many) 관계 (하나의 블로그는 여러 포스트를 가짐)를 클래스와
// 객체 배열을 이용해 모델링하는 방법을 학습합니다.
// 힌트: 일대다 관계 모델링, 객체 배열, 클래스 간의 관계, 메서드
}
You can’t perform that action at this time.