answer.
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
hjlf
1 year ago
11

. Write a statement that throws an IllgalArgumentException with the error message Argument cannot be negative.

Computers and Technology
1 answer:
dybincka [34]1 year ago
8 0

Answer:

public class PostAccount

{

  public void withdraw(float savings)

  {

     if (savings >=0 )

     {

        IllegalArgumentException exception

              = new IllegalArgumentException("Savings cannot be negative");

        throw exception;

     }

     balance = savings - withdraw;

  }

 }

Explanation:

IllgalArgumentException is a type of NumberFormatException  of runtime exception. Here in the program we have created an object of IllgalArgumentException class and after that we have thrown the error to show the condition if it does not satisfy the if condition.

You might be interested in
Digital cellphones use __________ to reduce the size of the channels that are required by scattering the digital fragments of co
Yuri [45]

Digital cellphones use Digital Compression to reduce the size of the channels that are required, by scattering the digital fragments of conversations over many channels

7 0
1 year ago
Rebooting a system in an attempt to fix a problem is an example of the ____ problem-solving strategy.
expeople1 [14]
Software trouble shooting
4 0
2 years ago
Write a program FindDuplicate.java that reads n integer arguments from the command line into an integer array of length n, where
kozerog [31]

Answer:

  1. public class FindDuplicate{
  2.    public static void main(String[] args) {
  3.        Scanner input = new Scanner(System.in);
  4.        int n = 5;
  5.        int arr[] = new int[n];
  6.        for(int i=0; i < arr.length; i++){
  7.            int inputNum = input.nextInt();
  8.            if(inputNum >=1 && inputNum <=n) {
  9.                arr[i] = inputNum;
  10.            }
  11.        }
  12.        for(int j =0; j < arr.length; j++){
  13.            for(int k = 0; k < arr.length; k++){
  14.                if(j == k){
  15.                    continue;
  16.                }else{
  17.                    if(arr[j] == arr[k]){
  18.                        System.out.println("True");
  19.                        return;
  20.                    }
  21.                }
  22.            }
  23.        }
  24.        System.out.println("False");
  25.    }
  26. }

Explanation:

Firstly, create a Scanner object to get user input (Line 4).

Next, create an array with n-size (Line 7) and then create a for-loop to get user repeatedly enter an integer and assign the input value to the array (Line 9 - 14).

Next, create a double layer for-loop to check the each element in the array against the other elements to see if there is any duplication detected and display "True" (Line 21 - 22). If duplication is found the program will display True and terminate the whole program using return (Line 23). The condition set in Line 18 is to ensure the comparison is not between the same element.

If all the elements in the array are unique the if block (Line 21 - 23) won't run and it will proceed to Line 28 to display message "False".

7 0
1 year ago
Instead of sending an entire file in one big chunk across the​ Internet, __________ is used which dices the file up into little
azamat

Answer:

TCP/IP

Explanation:

TCP/IP which stands for Transmission Control Protocol and Internet Protocol are network protocols which divide your message into smaller chunks or fragments known as network packets and sends them out onto the Internet. When the chunks arrive at the intended destination, TCP/IP on the receiving end reassembles the network packets into the original message.

TCP/IP are the main protocols used for sending data over the internet.

7 0
1 year ago
. Create a text file that contains your expenses for last month in the following categories: • Rent • Gas • Food • Clothing • Ca
Whitepunk [10]

Answer:

  1. from matplotlib import pyplot as plt
  2. with open("text.txt") as file:
  3.    data = file.readlines()
  4.    category = []
  5.    amount = []
  6.    for row in data:
  7.        values = row.split(" ")
  8.        category.append(values[0])
  9.        amount.append(float(values[1]))
  10.    
  11. figure = plt.figure()
  12. ax = figure.add_axes([0,0,1,1])
  13. ax.axis('equal')
  14. ax.pie(amount, labels = category, autopct='%1.2f%%')
  15. plt.show()

Explanation:

Firstly, we need to import matplotlib library (Line 1).

Next, open a file stream and use readlines method to read the data from the text file (Line 4). Presume the data read from the text files are as follows:

Rent 450

Gas 150

Food 500

Clothing 120

Car 600

Create two lists, category and amount (Line 5-6). Use a for loop to traverse through the read data and use split method to break each row of data into two individual items. The first item is added to category list whereas the second item is added to amount list (Line 7 - 10).

Next, create a plot figure and then add the axes (Line 12 - 13). We can use the pie method to generate a pie chart (Line 15) by setting the amount list as first argument and category list as value of labels attributes. The output pie chart can be found in the attachment.

7 0
2 years ago
Other questions:
  • Convert the following binary number to octal (111000)2​
    12·1 answer
  • In the game of $Mindmaster$, secret codes are created by placing pegs of any of seven different colors into four slots. Colors m
    5·1 answer
  • Which would be the most efficient way to store files on your computer?
    13·2 answers
  • [Assembly Language]Extended Subtraction Procedure.Create a procedure named Extended_Sub --(Receives: ESI and EDI point to the tw
    12·1 answer
  • Consider the following two code segments, which are both intended to determine the longest of the three strings "pea", "pear", a
    7·1 answer
  • Write a MATLAB function named average_of_scores_with_drops The function will have two inputs and two return values. The first in
    11·1 answer
  • Write a loop to populate the list user_guesses with a number of guesses. The variable num_guesses is the number of guesses the u
    13·1 answer
  • Suspicious activity, like IP addresses or ports being scanned sequentially, is a sign of which type of attack?
    7·1 answer
  • The program DebugTwo2.cs has syntax and/or logical errors. Determine the problem(s) and fix the program.// This program greets t
    5·1 answer
  • In a particular field, there are trees in a l single row from left to right. Each tree has a value V You cut trees from left to
    13·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!