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
Nadya [2.5K]
3 years ago
5

Write a method that finds the cheapest name of apples, and returns back a String stating what the apple name is and how much it

costs. The method should take two arrays as two parameters (you do not need to make a two dimensional array out of these arrays).
Computers and Technology
1 answer:
Korolek [52]3 years ago
7 0

The question is incomplete! Complete question along with answer and step by step explanation is provided below.

Question:

Two arrays are given:  

String apples[] = {"HoneyCrisp", "DeliciousRed", "Gala", "McIntosh",  "GrannySmith"};

double prices[] = {4.50, 3.10, 2.45, 1.50, 1.20};

Write a method that finds the cheapest name of apples, and returns back a String stating what the apple name is and how much it costs. The method should take two arrays as two parameters (you do not need to make a two dimensional array out of these arrays).

Answer:

The complete java code along with the output is prrovided below.

Java Code:

public class ApplesCheap

{

   public static String Cheapest(String apples[], double prices[])

 {

       int temp = 0;

       for (int i = 0; i < apples.length; i++)

    {

         if (prices[i] < prices[temp])

          {

               temp = i;

           }

       }

       return apples[temp];

   }

public static void main(String[] args)

{

// define the array of apple names and their prices

  String apples[] = {"HoneyCrisp", "DeliciousRed", "Gala", "McIntosh", "GrannySmith"};

  double prices[] = {4.50, 3.10, 2.45, 1.50, 1.20};

// print the cheapest apple by calling the function Cheapest

  System.out.println("The cheapest apple is: " + Cheapest(apples, prices));

   }

}

Output:

The cheapest apple is: GrannySmith

You might be interested in
* what is an electronic mail ?
Vikki [24]

Answer:

Electronic mail is a method of exchanging messages between people using electronic devices. Email entered limited use in the 1960s, but users could only send to users of the same computer, and some early email systems required the author and the recipient to both be online simultaneously, similar to instant messaging.

6 0
3 years ago
Match the characteristics to the mobile operating system that it describes.
uranmaximum [27]
I think it’s Apple ios
It’s definitely not Microsoft but my guess is Apple
3 0
3 years ago
Write a short-essay discussing your own stand on social media usage for students.​
hjlf

Answer:

More than half of the world’s population uses the internet. This is highlighted by social media users increasing by 21% since 2015, with 2.8 billion users reported globally in 2017.

Humans are social animals. We always like to remain in some group or another, and we prefer to follow what this group does. All of our traditions and cultures are the product of <em><u>this</u></em> group-oriented facet of human nature.Everyone is connected to one another in this vast network generated by the Internet.It illuminates the lives of thousands of people by spreading knowledge internationally, thereby making us global citizens. 

<h2><em><u>NOT</u></em><em><u> </u></em><em><u>COPIED</u></em><em><u> </u></em><em><u>ANSWER</u></em><em><u> </u></em></h2>
3 0
2 years ago
He smallest network is a ______________________, which is a network of personal devices, such as the network you use when you sy
scoray [572]
<span>The smallest network is a </span>personal area network,<span> which is a network of personal devices, such as the network you use when you sync your cell phone and your computer. </span>personal area network
8 0
2 years ago
Consider the following general code for allowing access to a resource:
Margaret [11]

Answer:

a) The code allows access even when  IsAccessAllowed(...) method fails.

b) Either use If

(dwRet = ACCESS_ALLOWED)

or use

if (dwRet == NO_ERROR)

to avoid flaw

Explanation:

Lets first see what the code chunk does:

DWORD dwRet = IsAccessAllowed(...);

if (dwRet == ERROR_ACCESS_DENIED) {

// Security check failed.

// Inform user that access is denied.

} else {

// Security check OK.

}

In the given code, DWORD is basically a data type for double word type integers and this is defined in windows.h

So there is DWORD type variable dwRet that is assigned a method calls.

The method is IsAccessAllowed() which checks if the access is allowed to user.

if (dwRet == ERROR_ACCESS_DENIED) condition basically checks if the value of DWORD type variable dwRet is equal to ERROR_ACCESS_DENIED

If this condition evaluates to true then the security checks fails and user is informed via some message or action that the access is denied.  But when the if condition evaluates to false then the else part executes which allows access.

So basically this chunk of code checks if the error ERROR_ACCESS_DENIED is returned.

Now the flaw in this program is what if the method IsAccessAllowed() by any reason. The reasons can be system failure or the memory failure. In memory failure case for example, the system returns out of memory error. So this means that the error is not  ERROR_ACCESS_DENIED. Instead it is out of memory error. So in such a case the user is allowed access as the if condition evaluates to false and else part executes. So if any other error is produced due to some reason like mentioned above, then user has unrestricted access.

This shows that the doe should not check for the failure or rely on checking ERROR_ACCESS_DENIED to allow access but instead it should check for success. Code should only give access privilege if access is allowed successfully or no error is produced.

So to avoid this flaw the code is altered as:

DWORD dwRet = IsAccessAllowed(...);

If (dwRet = ACCESS_ALLOWED) {

//Security check OK.

} else {

//Security check failed.

//Inform user that access is denied.

}

This will only allow access if ACCESS_ALLOWED evaluates to true and success is checked instead of failure here

You can also alter the if condition as:

If (dwRet = No_Error)

or

If (dwRet = 0)

The above if conditions checks if the access is allowed or if no error is produced. Only then it will allowed access otherwise not. So the access check is a success is checked first and failure (for any reason). The user is allowed access only if there is no error otherwise user is not allowed access.

6 0
3 years ago
Other questions:
  • 25. Becca is learning how to brush her teeth independently and her therapist/RBT has created an activity schedule to help teach
    6·1 answer
  • What component has the job of managing data as it flows into and out of the places it needs to go?
    11·2 answers
  • Storing a value in a variable<br> Exponent<br> Variable<br> Assignment<br> Operator
    13·1 answer
  • Which of the following is not an example of technological progress? A: new scientific knowledge that has practical applications
    12·2 answers
  • What is the maximum upload speed you can get on an isdl internet connection?
    9·1 answer
  • You may nest while and do-while loops, but you may not nest for loops<br><br><br><br> True False
    10·1 answer
  • What is the output of the following program?
    11·1 answer
  • What is the missing line of code?
    7·2 answers
  • If you want to join all of the rows in the first table of a SELECT statement with just the matched rows in a second table, you u
    10·1 answer
  • What is software?
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!