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]
2 years ago
8

Consider the following method:

Computers and Technology
2 answers:
Katen [24]2 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]2 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
What is the answer ????​
gtnhenbr [62]

Answer:

<h2>iv. NINGUNO DE LOS ANTERIORES</h2>

Explanation:

<h2>Hola</h2>
8 0
2 years ago
Research shows that a passive close to a cover letter leads to more interviews. Please select the best answer from the choices p
Alchen [17]
The answer is False.

According to research, a passive close doesn't lead your cover letter to have more interviews. In writing the closing part of your cover letter, it is easy to have a passive sentence but it sounds like less confidence to the employer. The last part of the cover letter should contain strong content to give an impression to the person who reads.
6 0
2 years ago
Read 2 more answers
1. How are computers helpful
d1i1m1o1n [39]

Answer:

Brainliest

Explanation:

It’s hard to imagine banks without technology. In fact, computers have been in use in banking since the 1950s, when Bank of America introduced a computer designed specifically for processing checks. Each new decade has brought innovations that change the way banks manage daily operations and serve customers. Today, you may not even leave your house to do your banking. As much as technology has changed the use of the computer in the banking sector, banks continue to adjust the way they do things.

8 0
3 years ago
You are applying for a secretary position. You have many skills but which of the following would not be one to include on the ap
zepelin [54]

A. How many marathons you have run, because it doesn't relate to the job you're applying for.

6 0
3 years ago
Read 2 more answers
Have a great day!
valina [46]

Answer:

thank you so much!

Explanation:

you seem like such a nice person! have a great weekend!

5 0
2 years ago
Read 2 more answers
Other questions:
  • Plz tell me a storage device that should be used for this and why
    11·1 answer
  • Convert to binary140
    5·1 answer
  • After which stage in the information processing cycle can data be referred for future use?
    7·1 answer
  • A large IPv4 datagram is fragmented into 4 fragments at router 1 to pass over a network with an MTU of 1500 bytes. Assume each f
    15·1 answer
  • A computer with a frequency 2 GHZ and its average cycle per instruction is 2. what is the MIPS of the computer?
    6·1 answer
  • When you're working with a word processing document and you press the del key, what happens?
    6·2 answers
  • (PYTHON) Write a program that uses this technique to read a CSV file such as the one given above. Display the IDs and names of t
    14·1 answer
  • Which formula is used to measure accuracy?
    11·1 answer
  • What can you find the under the privacy policy section of a shopping website?
    12·1 answer
  • State 4 basic operation performed by a computer​
    11·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!