Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

You are a journalist working for a newpaper company with a long history. Out of

ID: 3901949 • Letter: Y

Question

You are a journalist working for a newpaper company with a long history. Out of curiosity, you would like to look up the most recent article that uses the archaic word thou.

Articles are represented as Article Objects.

public class Article {

public string title;

  public string fullText;

  public int publicationYear;

  public int publicationMonth;

  public int publicationDate;

  public string author;

}

Assume fullText contains English letters and usual proper punctuation.

Assume the ArrayList<Article> corpus contains all articles ever published in your paper.

public class Test {

public static void main ( String [] args ) {

ArrayList < Article > corpus ;

// somehow load corpus

...

// start writing code here

...

}

}

Write code that looks through corpus and finds the most recent Article with the word thou in its text or title. Output the search result in any reasonable manner using System.out.

If two or more Article s are the most recent, then you can output any one of them. In other words, you can output any one of the winners. If no article contains the word thou, say so.

You may not use the methods indexOf(...) or lastIndexOf(...) of class String .

Hint: Make sure your code does not think words like thousand or lighthouse are matches for thou .

Explanation / Answer

Implemented Source Code:-
---------------------------------
package com.challenges;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Scanner;
class Article
{
public String title;
public String fullText;
public int publicationYear;
public int publicationMonth;
public int publicationDate;
public String author;
Article(String title,String fullText,int publicationYear,int publicationMonth,int publicationDate,String author)
{
this.title=title;
this.fullText=fullText;
this.publicationYear=publicationYear;
this.publicationMonth=publicationMonth;
this.publicationDate=publicationDate;
this.author=author;
}
@Override
public String toString() {
return "Article [title=" + title + ", fullText=" + fullText
+ ", publicationYear=" + publicationYear
+ ", publicationMonth=" + publicationMonth
+ ", publicationDate=" + publicationDate + ", author=" + author
+ "]";
}
}
public class Test
{
public static void main(String[] args) throws FileNotFoundException
{
ArrayList<Article>list=new ArrayList<Article>();
File Details = new File ("F:\Workspace_Luna\Articles.txt");
Scanner scanner = new Scanner(Details);
String title;
String fullText;
int year,month,day;
String Author;
Article articles = null;
while(scanner.hasNextLine())
{
title = scanner.next();
year=scanner.nextInt();
fullText=scanner.next();
month=scanner.nextInt();
day=scanner.nextInt();
Author=scanner.next();
articles=new Article(title,fullText,year,month,day,Author);
list.add(articles);
}
scanner.close();
int recent_article=list.size();
int k=0;
for(Article arts:list)
{
if(k==recent_article)
{
System.out.println(arts.toString());
}
k++;
}
}
}


Input file:-
----------------
PrathibhaAwards 2011 SRR&CVR 06 02 Vivekananda
Elections 2018 Congress_party 05 12 RajaShekar
Glamorous 2014 MaaMusicAwards 12 12 Mohandas