Java Assignment questions on Eclops (Need screenshots of output)

Apr 23rd, 2015
KateS
Category:
Computer Science
Price: $30 USD

Question description

Q1 Modify the solution below such that it catches and handles the exception if it is thrown. Handle the exception by printing an appropriate message, and then continue processing more strings.


package exception;

public class StringTooLongException extends Exception{

public StringTooLongException(){

super("String too long");

}

}

-----------------------------------------

 Driver class for StringTooLongException

-----------------------------------------

package exception;

import java.util.Scanner;

public class Driver{

public static void main (String[] args)

throws StringTooLongException{

Scanner scan = new Scanner(System.in);

String enterstr;                            //String to be entered

System.out.print("Enter a string (DONE to exit): ");

enterstr = scan.nextLine();

while (!enterstr.equals("DONE")){

if (enterstr.length()>20)

throw new StringTooLongException();

System.out.print("Enter a string (DONE to exit): ");

enterstr = scan.nextLine();

}

}

}


Q2. Modify the DisplayFile program below to add a button labeled Save above the text area. When the button is pushed, write the contents back out to the file. 


import java.util.Scanner; 

import java.io.*; 

import javax.swing.*;

public class DisplayFile {

   //----------------------------------------------------------------   // 

 Opens a file chooser dialog, reads the selected file and   //  loads it into a text area.  

 //----------------------------------------------------------------   

public static void main (String[] args) throws IOException   {   

   JFrame frame = new JFrame ("Display File");    

  frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);

      JTextArea ta = new JTextArea (20, 30);     

 JFileChooser chooser = new JFileChooser();

      int status = chooser.showOpenDialog (null);

      if (status != JFileChooser.APPROVE_OPTION)         

ta.setText ("No File Chosen");     

 else      {         File file = chooser.getSelectedFile();     

           Scanner scan = new Scanner(file);

         String info = "";       

         while (scan.hasNext())           

          info += scan.nextLine() + "\n";

         ta.setText (info);      }

      frame.getContentPane().add (ta);      

frame.pack();      

frame.setVisible(true);

   } 

}


I need the answers to both in 24 hours...Can you get it done..Message me if you have any questions//


Thanks

Tutor Answer

(Top Tutor) Daniel C.
(997)
School: Boston College
PREMIUM TUTOR

Studypool has helped 1,244,100 students

8 Reviews


Summary
Quality
Communication
On Time
Value
Five Star Tutor
Dec 3rd, 2016
" Outstanding Job!!!! "
SjSurvivor143
Nov 17th, 2016
" Thanks for the help. "
Joemoe
Nov 3rd, 2016
" <3 it, thanks for saving me time. "
tinytim47
Oct 25th, 2016
" Wow this is really good.... didn't expect it. Sweet!!!! "
pmallory
Oct 21st, 2016
" Totally impressed with results!! :-) "
mixedballz
Oct 12th, 2016
" excellent work as always thanks for the help "
kiln82
Sep 28th, 2016
" awesome work thanks "
darnay
Sep 19th, 2016
" The best tutor out there!!!! "
Ask your homework questions. Receive quality answers!

Type your question here (or upload an image)

1826 tutors are online

Brown University





1271 Tutors

California Institute of Technology




2131 Tutors

Carnegie Mellon University




982 Tutors

Columbia University





1256 Tutors

Dartmouth University





2113 Tutors

Emory University





2279 Tutors

Harvard University





599 Tutors

Massachusetts Institute of Technology



2319 Tutors

New York University





1645 Tutors

Notre Dam University





1911 Tutors

Oklahoma University





2122 Tutors

Pennsylvania State University





932 Tutors

Princeton University





1211 Tutors

Stanford University





983 Tutors

University of California





1282 Tutors

Oxford University





123 Tutors

Yale University





2325 Tutors