Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Modify Your Source Code From Exercise 4 To Handle Exceptions 1. Handle Exceptions When Opening File (I.E. File Not Found). Keep Asking User For A

Modify Your Source Code From Exercise 4 To Handle Exceptions 1. Handle Exceptions When Opening File (I.E. File Not Found). Keep Asking User For A Valid File Name 2. Put The Code That Reads & Splits Each Line Of Data In Try-Catch. If A Runtime Exception Occurs, Print Exception Message And Line That Causes The Exception. Then Skip That Line And Read The Next

Write this program in Java

Expected output

c River Django Unchained 10 5 4 4 4 8 8 1995 2011 1965 1986 1988 2001 2007 2010 1981 4 8 4 8 4 8 4 7 8 1993 6 6 3 3 3 3 3 2 2 3 6 2005 2005 1993 2015 2003 2012 6 2 5 BUILD SUCCESS 1. Copy class Film to your source file. Complete this class to make it concrete, but do not change the visibility of each member class Film implements Comparable

9 java.lang. ArithmeticException: My Exception for invalid flag \"2\" Whiplash, 2014, 2, 3, 5 Our own exception (invalid input) embedded Java's ArithmeticException java.lang. ArithmeticException: My Exception for negative value \"-7\" Argo, 2012, 1, 3, -7 Film Wins Nominations Year 11 14 11 12 10 11 8 12 11 8 8 1997 1959 1961 1964 1982 2009 2009 1964 1998 2011 6 5 5 5 10 9 9 13 11 11 5 10 1965 5 10 5 10 Titanic (best film) Ben-Hur (best film) West Side Story (best film) My Fair Lady (best film) Gandhi (best film) Slumdog Millionaire (best film) The Hurt Locker (best film) Mary Poppins Saving Private Ryan Hugo The Sound of Music (best film) Braveheart (best film) The Artist (best film) Doctor Zhivago Platoon (best film) Rain Man (best film) A Beautiful Mind (best film) ) No Country for Old Men (best film) Incepti

Question from Exercise 4 and source code from exercise 4

0, 2016, 0, 2015, 1, 20.14, 1, 2014, 2, 2012, 1, 4, 6 6, 14 3, 2, 6 2; 6 2, 6, 6 4, 3, 5 3, -7 1 instead of one O instead of zero Missing last column Missing comma after name Semi-colon instead of comma Exceeding last column Double instead of int Invalid flag Negative number 9 Note : Some conditions such as invalid values (in Whiplash & Argo) will not cause runtime exception. You have to check these conditions by yourself and throw your own or Java's exception if (value

import java.io.File;

import java.io.FileNotFoundException;

import java.util.ArrayList;

import java.util.Collections;

import java.util.Scanner;

public class Exercise4 {

class Statistic{

public void main(String[] args) {

ArrayList filmList = new ArrayList();

File file = new File(\"Oscars.txt\");

try {

Scanner sc = new Scanner(file);

while (sc.hasNextLine()) {

Scanner sc2 = new Scanner(sc.nextLine());

sc2.useDelimiter(\",\");

String name = sc2.next();

int year = Integer.parseInt(sc2.next().trim());

int best = Integer.parseInt(sc2.next().trim());

int wins = Integer.parseInt(sc2.next().trim());

int nominations = Integer.parseInt(sc2.next().trim());

sc2.close();

Film film = new Film(name, year, best, wins, nominations);

filmList.add(film);

}

sc.close();

Collections.sort(filmList);

System.out.println(String.format(\"%-50s %-20s %-10s %10s\", \"Film\", \"Wins\", \"Nominations\", \"Year\"));

System.out.println(\"==================================================================================================\");

for(int i=0; i();>

filmList.get(i).print();

}

} catch (FileNotFoundException e) {

e.printStackTrace();

}

}

}

class Film implements Comparable {

private String name;

private int year, best, wins, nominations;

public Film(String name, int year, int best, int wins, int nominations) {

this.name = name;

this.year = year;

this.best = best;

this.wins = wins;

this.nominations = nominations;

}

public void print() {

System.out.print(String.format(\"%-30s\",this.name));

if (this.best == 1) {

System.out.print(\"(best film)\");

}

else {

System.out.print(\" \");

}

System.out.print(String.format(\"%13d\",this.wins));

System.out.print(String.format(\"%20d\",this.nominations));

System.out.println(String.format(\"%20d\",this.year));

}

public int compareTo(Film film) {

if (this.wins > film.wins) {

return -1;

}

else if (this.wins

return 1;

}

else {

if (this.nominations > film.nominations) {

return -1;

}

else if (this.nominations

return 1;

}

else {

if (this.best > film.best) {

return -1;

}

else if(this.best

return 1;

}

else {

if (this.year

return -1;

}

else if (this.year > film.year) {

return 1;

}

else {

return this.name.compareTo(film.name);

}

}

}

}

}

}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Income Tax Fundamentals 2013

Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill

31st Edition

1111972516, 978-1285586618, 1285586611, 978-1285613109, 978-1111972516

More Books

Students also viewed these Programming questions