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
konstantin123 [22]
1 year ago
6

Given that a method receives three parameters a, b, c, of type double, write some code, to be included as part of the method, th

at determines whether the value of "b squared" – 4ac is negative. If negative, the code prints out the message "no real solutions" and returns from the method
Computers and Technology
2 answers:
Debora [2.8K]1 year ago
6 0

Answer and Explanation:

class Dis

{

public static void main(String args[])

{

Scanner sc=new Scanner(System.in);

System.out.println("Enter values for a,b,c");

double a=sc.nextDouble();

double b=sc.nextDouble();

double c=sc.nextDouble();

String s=discriminant(a,b,c);

System.out.println(s);

}

public String discriminant(double a, double b, double c)

{

double result;

result=(b^2-4ac);

if(result<0)

return "no real solutions"";

else return "";

}

}

Note:This program is written in JAVA

Llana [10]1 year ago
3 0

Answer:

The solution code is written in Java:

  1.   public static boolean check_discriminant(double a, double b, double c)
  2.    {
  3.        double discriminant = b * b - (4 * a * c);
  4.        if(discriminant > 0){
  5.            return true;
  6.        }
  7.        else{
  8.            System.out.println("no real solutions");
  9.            return false;
  10.        }
  11.    }

Explanation:

Firstly, we define a function check_discriminant() that takes three parameters with double type,<em> a, b and c </em>(Line 1).

Next, we calculate the discriminant using the formula b² - 4ac (Line 3). We place the discriminant in if condition (Line 5) to see if it is a negative or positive value. If positive return true (Line 6) and if negative it will print out message "no real solutions" and return false (Line 9 -10).

You might be interested in
. 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
Adrian has decided to create a website to catalog all the books he has in his personal library. He wants to store this informati
Lostsunrise [7]
I think it is XML. Hope that helps.
8 0
2 years ago
Read 2 more answers
Describe a strategy for avoiding nested conditionals. Give your own example of a nested conditional that can be modified to beco
Alex787 [66]

Answer:

One of the strategies to avoid nested conditional is to use logical expressions such as the use of AND & operator.

One strategy is to use an  interface class with a method. That method can be created to be used for a common functionality or purpose. This is also called strategy design pattern. You can move the chunk of conditional statement to that method. Then each class can implement that interface class and use that shared method according to their own required task by creating objects of sub classes and call that common method for any such object. This is called polymorphism.

Explanation:

Nested conditionals refers to the use of if or else if statement inside another if or else if statement or you can simply say a condition inside another condition. For example:

if( condition1) {  

//executes when condition1 evaluates to true

  if(condition2) {

//executes when condition1  and condition2 evaluate to true

  }  else if(condition3) {

 //when condition1 is true and condition3 is true

} else {

 //condition1  is true but neither condition2 nor conditions3 are true

}  }

The deeply nested conditionals make the program difficult to understand or read if the nested conditionals are not indented properly. Also the debugging gets difficult when the program has a lot of nested conditionals.

So in order to avoid nested conditionals some strategies are used such as using a switch statement.

Here i will give an example of the strategies i have mentioned in the answer.

Using Logical Expressions:

A strategy to avoid nested conditionals is to use logical expressions with logical operators such as AND operator. The above described example of nested conditionals can be written as:

if(condition1 && condition2){  //this executes only when both condition1 and condition2 are true

} else if(condition1 && condition3) {

this executes only when both condition1 and condition3 are true

} else if(condition1 ){

//condition1  is true but neither condtion2 nor condtion3 are true  }

This can further be modified to one conditional as:

if(!condition3){

// when  condition1 and condition2 are true

}

else

// condition3 is true

Now lets take a simple example of deciding to go to school or not based on some conditions.

if (temperature< 40)

{

   if (busArrived=="yes")

   {

       if (!sick)

       {

           if (homework=="done")

           {

               printf("Go to school.");

           }

       }                    

   }

}

This uses nested conditionals. This can be changed to a single conditional using AND logical operator.

if ((temperature <40) && (busArrived=="yes") &&

(!sick) && (homework=="done"))

{    cout<<"Eligible for promotion."; }

The second strategy is to use an interface. For example you can

abstract class Shape{

//declare a method common to all sub classes

  abstract public int area();

// same method that varies by formula of area for different shapes

}

class Triangle extends Shape{

  public int area() {

     // version of area code for Triangle

return (width * height / 2);

  }

}

class Rectangle extends Shape{

  public int area() {

     // version of area code for Rectangle

    return (width * height)

  }

}

// Now simply create Rectangle or Triangle objects and call area() for any such object and the relevant version will be executed.

4 0
1 year ago
Analiza las relaciones y diferencias que encuentras entre las actitudes y los
Anarel [89]

Answer:Technology is the sum of techniques, skills, methods, and processes used in the production of goods or services or in the accomplishment of objectives, such as scientific investigation. Technology can be the knowledge of techniques, processes, and the like, or it ... An articulation of this philosophy could be found explicitly in Vannevar Bush's

4 0
1 year ago
Read 2 more answers
A form that dedicates a page for each item retrieved for a case; it allows investigators to add more detail about exactly what w
gregori [183]

Answer:

Single-evidence form​

Explanation:

Single-evidence form​  dedicates a page for each item retrieved for a case; it allows investigators to add more detail about exactly what was done to the evidence each time it was taken from the storage locker.

4 0
2 years ago
Other questions:
  • In three to four sentences, describe why CEOs (the chief executive officers, that is, the leaders of large companies) make very
    9·1 answer
  • PLEASE HELP!! WILL GIVE BRAINLIEST!!
    15·2 answers
  • Graphical elements that precede each item in a list are known as​ __________.
    8·1 answer
  • Write a function named "list_concat" that takes a list of strings as a parameter and returns the concatenation of all the values
    13·1 answer
  • Item = "quesadilla"
    7·1 answer
  • ANSWER AS SOON AS POSSIBLE: When I try to join roblox adopt me it says: "Roblox Datastore servers are currently down. Please rej
    10·2 answers
  • Describe a strategy for avoiding nested conditionals. Give your own example of a nested conditional that can be modified to beco
    15·1 answer
  • 4.17 LAB: Data File A comma separated value (.csv) file has been included to be used for this program. Each line contains two va
    13·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
  • Define function print_popcorn_time() with parameter bag_ounces. If bag_ounces is less than 3, print "Too small". If greater than
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!