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 defining an array of class objects, how do you pass arguments to the constructor for each object in the array?
Nuetrik [128]
Basically, the array[ index ] is the name of the object so when you  populate the array you'd have statement[s] like:

array[ index ] = new ClassName( arg0, arg1, arg2 );
8 0
3 years ago
____ variables are variables that are shared by every instantiation of a class. local instance
Colt1911 [192]

These are known as class variables, so called because of the property mentioned.

4 0
3 years ago
What X coordinate does the center of a game begin at?
kotegsom [21]

A. 0

I am not entirely sure, I am not much of a coder(well I am but I don’t code often) so I hope this helps!

5 0
3 years ago
Help me with 3dMODELING art please
Ahat [919]

Answer:

See the answers below.

Explanation:

6. Input

7. Hardware

8. Graphic Tablets

9. An Abacus or Counting Rods

Regards: Your Friendly Study Co-Pilot!

7 0
3 years ago
List the six external parts of the computer system
Elina [12.6K]
1. Monitor
2. Modem
3. system unit
4. Mouse
5. Speaker
<span>6. Printer and also a keyboard I'm not sure which you should take out though lo</span>
6 0
4 years ago
Other questions:
  • Which is the last step in conducting a url research
    11·1 answer
  • The utilization of a subset of the performance equation as a performance metric is a pitfall. To illustrate this, assume the fol
    13·1 answer
  • 1. What does it mean to say that a country’s land area is positively correlated with its population?
    12·2 answers
  • True or False? In C++, the expression (a + b / c) / 2 is implicitly parenthesized as ((a + b) / c) / 2.
    9·1 answer
  • Which type of spreadsheet cell represents the left hand sides (lhs) formulas in an optimization analysis?
    5·1 answer
  • Types of relationships include aggregation, composition, link, generalization, and specialization 9. TRUE FALSE
    9·1 answer
  • The four compass points can be abbreviated by single-letter strings as "N", "E", "S", and "W". Write a function turn_clockwise t
    15·1 answer
  • Jason has decided to use his name on all the images to protect them from misuse. He has also decided to use the logo of his comp
    15·2 answers
  • Anwser the question below plz due in 15 mins.
    12·1 answer
  • Assuming even parity, find the parity bit for each of the following data units. a. 1001011 b. 0001100 c. 1000000 d. 1110111
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!