1b: tidying

This commit is contained in:
Daniel Langbein 2024-11-24 19:24:32 +01:00
parent cfeaba3cab
commit 728dd877bd
Signed by: langfingaz
GPG Key ID: 6C47C753F0823002
5 changed files with 23 additions and 19 deletions

View File

@ -6,7 +6,7 @@ import model.NewsCollection;
public class Client {
public static void main(String[] args) {
public static void main() {
NewsCollection masterCollection = new NewsCollection("Daily news");
masterCollection.addItem(new NewsCollection("Sports")
.addItem(new Article("Harder, Better, Faster, Stronger. Doping controls loosened","ups"))

View File

@ -11,8 +11,8 @@ public class Article extends AuthoredItem {
/**
* Creates an article with the given title and author.
* @param title
* @param author
* @param title title of article
* @param author author of article
*/
public Article(String title, String author) {
this.title = title;

View File

@ -22,6 +22,7 @@ public abstract class AuthoredItem extends Item{
/**
* Get the content of the AuthoredItem.
*
* @return content
*/
public String getContent() {

View File

@ -1,8 +1,8 @@
package model;
public class Image extends AuthoredItem {
private int width;
private int height;
private final int width;
private final int height;
// Fill in dummy content
{
@ -13,10 +13,10 @@ public class Image extends AuthoredItem {
* Creates an image with the given title and author and a resolution
* defined by width and height.
*
* @param title
* @param width
* @param height
* @param author
* @param title title of image
* @param width width of image
* @param height height of image
* @param author author of image
*/
public Image(String title, int width, int height, String author) {
this.title = title;

View File

@ -4,9 +4,9 @@ import java.util.LinkedList;
import java.util.List;
public class NewsCollection extends Item {
private List<Item> items = new LinkedList<>();
private final List<Item> items = new LinkedList<>();
public NewsCollection(String title) {
this.title = title;
}
@ -17,11 +17,13 @@ public class NewsCollection extends Item {
*/
public String getOverview(){
StringBuilder builder = new StringBuilder();
builder.append("###" + getTitle() + "###");
builder.append("\n");
builder
.append("###").append(getTitle()).append("###")
.append("\n");
for(Item item : getItems()){
builder.append(item.getOverview());
builder.append("\n");
builder
.append(item.getOverview())
.append("\n");
}
return builder.toString();
}
@ -32,8 +34,9 @@ public class NewsCollection extends Item {
*/
public String getDetails(){
StringBuilder builder = new StringBuilder();
builder.append("###" + getTitle() + "###");
builder.append("\n");
builder
.append("###").append(getTitle()).append("###")
.append("\n");
for (Item item : getItems()) {
builder.append(item.getDetails());
}
@ -52,7 +55,7 @@ public class NewsCollection extends Item {
/**
* Store an item directly in this collection.
* @param item
* @param item to add
* @return this collection (enables method chaining)
*/
public NewsCollection addItem(Item item) {