1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Anna [14]
3 years ago
8

Consider the following method:

Computers and Technology
2 answers:
Katen [24]3 years ago
8 0

Answer:

See explaination

Explanation:

public class Main {

public static void main(String[] args) {

//execution starts from here so initializing the try block for erros

try{

Scanner keyboard = new Scanner(System.in);

System.out.print("Please enter a file name: ");

String name = keyboard.next();

//the line below throws file not found exception if the given file name is not found or unable to open

Scanner file = new Scanner(new File(name));

String line = file.nextLine();

int n = file.nextInt();

//the below print line function call throws ParameterNotAllowedException if n is zero

printLine(line, n);

}//all Exceptions potentially thrown

catch(InputMismatchException e){

System.out.println("User input type mismatch\n"+e);

}catch(FileNotFoundException e){

System.out.println("Given file name is wrong or does not match");

}catch(ParameterNotAllowedException e){

System.out.println("The n given to printLine must be more than zero");

}catch(IOException ex){

System.err.println("An IOException was caught!");

}

}

//method from above goes here.

public static void printLine(String line, int numberOfTimes) throws Exception {

if (numberOfTimes <=0)

throw new ParameterNotAllowedException("Error. invalid parameter.",numberOFTimes);

for( int i=0; i<numberOfTimes; i++)

System.out.println(line);

}

}

For the user written custom Exception ParameterNotAllowedException. We need to add an exceptional class.

Which is missing from the given info:

class ParameterNotAllowedException extends Exception

{

public ParameterNotAllowedException(String s,int n)

{

// Call constructor of parent Exception

super(s);

}

}

belka [17]3 years ago
5 0

Answer:

Check the explanation

Explanation:

public class Main {

public static void main(String[] args) {

//execution starts from here so initializing the try block for errors

try{

Scanner keyboard = new Scanner(System.in);

System.out.print("Please enter a file name: ");

String name = keyboard.next();

//the line below throws file not found exception if the given file name is not found or unable to open

Scanner file = new Scanner(new File(name));

String line = file.nextLine();

int n = file.nextInt();

//the below print line function call throws ParameterNotAllowedException if n is zero

printLine(line, n);

}//all Exceptions potentially thrown

catch(InputMismatchException e){

System.out.println("User input type mismatch\n"+e);

}catch(FileNotFoundException e){

System.out.println("Given file name is wrong or does not match");

}catch(ParameterNotAllowedException e){

System.out.println("The n given to printLine must be more than zero");

}catch(IOException ex){

System.err.println("An IOException was caught!");

}

}

//method from above goes here.

public static void printLine(String line, int numberOfTimes) throws Exception {

if (numberOfTimes <=0)

throw new ParameterNotAllowedException("Error. invalid parameter.",numberOFTimes);

for( int i=0; i<numberOfTimes; i++)

System.out.println(line);

}

}

For the user written custom Exception ParameterNotAllowedException. We need to add an exceptional class.

Which is missing from the given info:

class ParameterNotAllowedException extends Exception

{

public ParameterNotAllowedException(String s,int n)

{

// Call constructor of parent Exception

super(s);

}

}

You might be interested in
When should you use the Reply All function when replying to an email
Dmitrij [34]
When the email was sent as a group email 

5 0
2 years ago
Read 2 more answers
Which type of network attack uses a fake IP address to send data packets from an unauthorized user to a network?
liq [111]
D. DoS. DoS is a way to potentially lag or even crash different types of servers ranging from as small as a simple website to bigger websites and video games servers.
6 0
3 years ago
Read 2 more answers
Need Help!
Aleksandr-060686 [28]

Answer:

A and C are the only <u>legal</u> but unethical options

4 0
3 years ago
Which of the following is not one of the steps a company would take in an attempt to prevent a malfunction or failure of their p
bulgar [2K]

Answer:

A overdesign

Explanation:

7 0
3 years ago
The option to add the date and time to a document is located in the
Tomtit [17]

Answer:

The option to add the date and time to a document is located in the

text grouping on the Insert tab.

Explanation:

8 0
3 years ago
Read 2 more answers
Other questions:
  • How long does it take to wire a house?
    14·2 answers
  • wHAT ARE THE 5 LAYERS in the internet protocol stack andwhat are the principal responsibilities of eack of theselayers.?
    12·1 answer
  • Some IOS commands store passwords as clear text, but you can then encrypt the passwords with the service password-encryption glo
    10·1 answer
  • An organization is trying to decide which type of access control is most appropriate for the network. The current access control
    12·1 answer
  • Integer indexing array: Weekend box office The row array movieBoxOffice stores the amount of money a movie makes (in millions of
    11·1 answer
  • Copy and paste is the only way to move text from one place to another.<br><br>True or <br>False​
    15·2 answers
  • PLS I NEED HELP Question 6<br> 1 pts<br> What is NOT a built-in function in python?
    5·1 answer
  • What is the answer ????​
    9·1 answer
  • I WILL MARK BRAINIEST FOR THIS!!!!!!
    11·2 answers
  • Choosing a per_formatted presentation that already has a design and the slots is called choosing What​
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!