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
Communication protocols, sets of rules agreed to by all parties, are designed in order to:
mote1985 [20]

Group of answer choices.

A. Ensure that cell phones and laptops cannot communicate.

B. Give each country its own internet language.

C. Ensure that new technologies and devices that haven't been invented yet can all use the same methods of communication.

D. Assure that computers and other devices don't pollute the environment.

Answer:

C. Ensure that new technologies and devices that haven't been invented yet can all use the same methods of communication.

Explanation:

OSI model stands for Open Systems Interconnection. The seven layers of OSI model architecture starts from the Hardware Layers (Layers in Hardware Systems) to Software Layers (Layers in Software Systems) and includes the following;

1. Physical Layer

2. Data link Layer

3. Network Layer

4. Transport Layer

5. Session Layer

6. Presentation Layer

7. Application Layer

Each layer has its unique functionality which is responsible for the proper functioning of the communication services.

Additionally, a standard framework for the transmission of informations on the internet, it is known as the internet protocol suite or Transmission Control Protocol and Internet Protocol (TCP/IP) model. One of the very basic rule of the TCP/IP protocol for the transmission of information is that, informations are subdivided or broken down at the transport layer, into small chunks called packets rather than as a whole.

Hence, communication protocols, sets of rules agreed to by all parties, are designed in order to ensure that new technologies and devices that haven't been invented yet can all use the same methods of communication.

This ultimately implies, there exist standard frameworks and protocols that are designed and developed to serve pre-existing technologies and devices, as well as those that would be invented in the future.

For example, SMTP is an acronym for Simple Mail Transfer Protocol and it uses the standard port number of 25 to provide clients with requested services on an internet-enabled device.

3 0
3 years ago
What types of actions exist in activity diagrams?<br>​
iragen [17]

Answer:

Activity Diagrams

Activity. An activity diagram illustrates one individual activity. ...

Action. ...

Calling an Activity (Action) ...

Accepting an Event (Action) ...

Accepting a Time Event (Action) ...

Sending Signals (Action) ...

Edge (Control Flow) ...

Decision Node.

Explanation:

8 0
3 years ago
Is USA TestPrep a test-taking site that won't let you access other windows without kicking you off?
olga_2 [115]

Answer:

usatestprep literally just does what the name says; it prepares you for tests in america. it doesn't kick you off if you access other windows

Explanation:

3 0
4 years ago
Which term describes the process of training a machine to do simple, repetitive tasks, and adapt or correct its performance base
yKpoI14uk [10]
Automation. ... It involves taking a machine or software that was taught to do simple repetitive tasks (traditional automation) and teaching it to intuitively adapt or correct its performance based on changing conditions, at speed and scale.
8 0
3 years ago
State the difference between IBM PC and apple machintosh computers
azamat

Answer:

a Mac is a PC because PC stands for personal computer. However, in everyday use, the term PC typically refers to a computer running the Windows operating system, not the operating system made by Apple.

7 0
3 years ago
Other questions:
  • Fibre channel switched networks rely on the concept of a ___________________which is a fundamental concept in how the network wo
    10·1 answer
  • The drone intercepts at 1256 hour. what time do they plane to take control of the drone
    11·1 answer
  • What is the purpose of a Program Epic?
    7·2 answers
  • Examples of language translator
    12·2 answers
  • 25 points!!!!!!!!!!!!!!!!!!!!!
    9·2 answers
  • Data from RAM may be placed where to free up space?
    7·1 answer
  • Design by contract considers the software system to be a setof:
    10·1 answer
  • &gt;What is the output of the following code:
    5·1 answer
  • Inserting merge fields in the letter<br>steps required <br>plz ​
    11·2 answers
  • What electronic devices do you use more frequently? And how much time do you use them?
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!