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
o-na [289]
3 years ago
8

Fix the code so the program will run correctly for MAXCHEESE values of 0 to 20 (inclusive). Note that the value of MAXCHEESE is

set by changing the value in the code itself. If you are not sure of how it should work then look at the Sample Runs of the next part. This part handles the beginning where it lists all the cheese types available and their prices. Note: it is a very simple fix that needs to be added to all the statements that have an array access.
Engineering
1 answer:
GarryVolchara [31]3 years ago
7 0

Answer:

Code fixed below using Java

Explanation:

<u>Error.java </u>

import java.util.Random;

public class Error {

   public static void main(String[] args) {

       final int MAXCHEESE = 10;

       String[] names = new String[MAXCHEESE];

       double[] prices = new double[MAXCHEESE];

       double[] amounts = new double[MAXCHEESE];

       // Three Special Cheeses

       names[0] = "Humboldt Fog";

       prices[0] = 25.00;

       names[1] = "Red Hawk";

       prices[1] = 40.50;

       names[2] = "Teleme";

       prices[2] = 17.25;

       System.out.println("We sell " + MAXCHEESE + " kind of Cheese:");

       System.out.println(names[0] + ": $" + prices[0] + " per pound");

       System.out.println(names[1] + ": $" + prices[1] + " per pound");

       System.out.println(names[2] + ": $" + prices[2] + " per pound");

       Random ranGen = new Random(100);

       // error at initialising i

       // i should be from 0 to MAXCHEESE value

       for (int i = 0; i < MAXCHEESE; i++) {

           names[i] = "Cheese Type " + (char) ('A' + i);

           prices[i] = ranGen.nextInt(1000) / 100.0;

           amounts[i] = 0;

           System.out.println(names[i] + ": $" + prices[i] + " per pound");

       }        

   }

}

You might be interested in
Fibonacci sequence has many applications in Computer Science. Write a program to generate Fibonacci numbers as many as desired.
VikaD [51]

Answer:

The Python Code for Fibonacci Sequence is :

# Function for nth Fibonacci number  

def Fibonacci(n):  

if n<0:  

 print("Incorrect input")  

# First Fibonacci number is 0  

elif n==0:  

 return 0

# Second Fibonacci number is 1  

elif n==1:  

 return 1

else:  

 return Fibonacci(n-1)+Fibonacci(n-2)  

# Driver Program  

print(Fibonacci(9))  

Explanation:

The Fibonacci numbers are the numbers in the following integer sequence.

0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, ……..

In mathematical terms, the sequence Fn of Fibonacci numbers is defined by the recurrence relation

Fn = Fn-1 + Fn-2

with seed values

F0 = 0 and F1 = 1.

8 0
3 years ago
Read 2 more answers
11. When selecting a route for a long trip, you should
mamaluj [8]

Answer:

b

Explanation:

i think do kill me if im wrong

6 0
3 years ago
Read 2 more answers
Discuss with your neighbor your brain as a computer.
Misha Larkins [42]
Senors are a type of device that produce a amount of change to the output to a known input stimulus.
Input signals are signals that receive data by the system and outputs the ones who are sent from it. Hope this helps ;)
6 0
3 years ago
Many BLANK apply trial and error to develop a product. Please Help! I have one hour to finish. 30 points
Julli [10]

Answer:

Entrepreneurs?

Explanation:

8 0
3 years ago
WHICH ONE DO YOU LIKE *CREDIT 2 sbrianna3606*
RSB [31]

Answer:

first one, rest are okay ig.....

Explanation:

6 0
2 years ago
Other questions:
  • A structural component in the shape of a flat plate 25.0 mm thick is to be fabricated from a metal alloy for which the yield str
    7·2 answers
  • 1. Which of the following will cause a spark knock?
    10·1 answer
  • 3. Air at 1 atm and 20 0 C flows tangentially on both sides of a smooth flat plate of width W=10 ft and length L=10 ft in the di
    8·1 answer
  • How are eras different from decades?
    5·1 answer
  • As the impurity concentration in solid solution of a metal is increased, the tensile strength:________.a) decreasesb) increasesc
    9·1 answer
  • The Ethernet (CSMA/CD) alternates between contention intervals and successful transmissions. Assume a 100 Mbps Ethernet over 1 k
    5·1 answer
  • Name the ferrous metal that most workshop tools are made from??
    12·2 answers
  • ) If the blood viscosity is 2.7x10-3 Pa.s, length of the blood vessel is 1 m, radius of the blood vessel is 1 mm, calculate the
    13·1 answer
  • True or false for the 4 questions?
    8·1 answer
  • What is the objective of phasing out an INDUCTION MOTOR before putting the machine into commission?
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!