1b: tidying
This commit is contained in:
parent
cfeaba3cab
commit
728dd877bd
@ -6,7 +6,7 @@ import model.NewsCollection;
|
|||||||
|
|
||||||
public class Client {
|
public class Client {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main() {
|
||||||
NewsCollection masterCollection = new NewsCollection("Daily news");
|
NewsCollection masterCollection = new NewsCollection("Daily news");
|
||||||
masterCollection.addItem(new NewsCollection("Sports")
|
masterCollection.addItem(new NewsCollection("Sports")
|
||||||
.addItem(new Article("Harder, Better, Faster, Stronger. Doping controls loosened","ups"))
|
.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.
|
* Creates an article with the given title and author.
|
||||||
* @param title
|
* @param title title of article
|
||||||
* @param author
|
* @param author author of article
|
||||||
*/
|
*/
|
||||||
public Article(String title, String author) {
|
public Article(String title, String author) {
|
||||||
this.title = title;
|
this.title = title;
|
||||||
|
@ -22,6 +22,7 @@ public abstract class AuthoredItem extends Item{
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the content of the AuthoredItem.
|
* Get the content of the AuthoredItem.
|
||||||
|
*
|
||||||
* @return content
|
* @return content
|
||||||
*/
|
*/
|
||||||
public String getContent() {
|
public String getContent() {
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
package model;
|
package model;
|
||||||
|
|
||||||
public class Image extends AuthoredItem {
|
public class Image extends AuthoredItem {
|
||||||
private int width;
|
private final int width;
|
||||||
private int height;
|
private final int height;
|
||||||
|
|
||||||
// Fill in dummy content
|
// 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
|
* Creates an image with the given title and author and a resolution
|
||||||
* defined by width and height.
|
* defined by width and height.
|
||||||
*
|
*
|
||||||
* @param title
|
* @param title title of image
|
||||||
* @param width
|
* @param width width of image
|
||||||
* @param height
|
* @param height height of image
|
||||||
* @param author
|
* @param author author of image
|
||||||
*/
|
*/
|
||||||
public Image(String title, int width, int height, String author) {
|
public Image(String title, int width, int height, String author) {
|
||||||
this.title = title;
|
this.title = title;
|
||||||
|
@ -4,9 +4,9 @@ import java.util.LinkedList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class NewsCollection extends Item {
|
public class NewsCollection extends Item {
|
||||||
|
|
||||||
private List<Item> items = new LinkedList<>();
|
private final List<Item> items = new LinkedList<>();
|
||||||
|
|
||||||
public NewsCollection(String title) {
|
public NewsCollection(String title) {
|
||||||
this.title = title;
|
this.title = title;
|
||||||
}
|
}
|
||||||
@ -17,11 +17,13 @@ public class NewsCollection extends Item {
|
|||||||
*/
|
*/
|
||||||
public String getOverview(){
|
public String getOverview(){
|
||||||
StringBuilder builder = new StringBuilder();
|
StringBuilder builder = new StringBuilder();
|
||||||
builder.append("###" + getTitle() + "###");
|
builder
|
||||||
builder.append("\n");
|
.append("###").append(getTitle()).append("###")
|
||||||
|
.append("\n");
|
||||||
for(Item item : getItems()){
|
for(Item item : getItems()){
|
||||||
builder.append(item.getOverview());
|
builder
|
||||||
builder.append("\n");
|
.append(item.getOverview())
|
||||||
|
.append("\n");
|
||||||
}
|
}
|
||||||
return builder.toString();
|
return builder.toString();
|
||||||
}
|
}
|
||||||
@ -32,8 +34,9 @@ public class NewsCollection extends Item {
|
|||||||
*/
|
*/
|
||||||
public String getDetails(){
|
public String getDetails(){
|
||||||
StringBuilder builder = new StringBuilder();
|
StringBuilder builder = new StringBuilder();
|
||||||
builder.append("###" + getTitle() + "###");
|
builder
|
||||||
builder.append("\n");
|
.append("###").append(getTitle()).append("###")
|
||||||
|
.append("\n");
|
||||||
for (Item item : getItems()) {
|
for (Item item : getItems()) {
|
||||||
builder.append(item.getDetails());
|
builder.append(item.getDetails());
|
||||||
}
|
}
|
||||||
@ -52,7 +55,7 @@ public class NewsCollection extends Item {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Store an item directly in this collection.
|
* Store an item directly in this collection.
|
||||||
* @param item
|
* @param item to add
|
||||||
* @return this collection (enables method chaining)
|
* @return this collection (enables method chaining)
|
||||||
*/
|
*/
|
||||||
public NewsCollection addItem(Item item) {
|
public NewsCollection addItem(Item item) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user