1b: tidying
This commit is contained in:
parent
cfeaba3cab
commit
728dd877bd
@ -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"))
|
||||
|
@ -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;
|
||||
|
@ -22,6 +22,7 @@ public abstract class AuthoredItem extends Item{
|
||||
|
||||
/**
|
||||
* Get the content of the AuthoredItem.
|
||||
*
|
||||
* @return content
|
||||
*/
|
||||
public String getContent() {
|
||||
|
@ -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;
|
||||
|
@ -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) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user