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
dsp73
3 years ago
12

The files provided in the code editor to the right contain syntax and/or logic errors. In each case, determine and fix the probl

em, remove all syntax and coding errors, and run the program to ensure it works properly.
// Displays five random numbers between
// (and including) user-specified values
import java.util.Scanner;
public class DebugSix4
{
public static void main(String[] args)
{
int high, low, count = 0;
final int NUM = 5;
Scanner input = new Scanner(System.in);
System.out.print("This application displays " + NUM +
" random numbers" +
"\nbetween the low and high values you enter" +
"\nEnter low value now... ");
low = input.nextInt()
System.out.print("Enter high value... ");
high = inputnextInt();
while(low < high)
{
System.out.println("The number you entered for a high number, " +
high + ", is not more than " + low);
System.out.print("Enter a number higher than " + low + "... ");
high = input.nextInt();


while(count < NUM)
{
double result = Math.random();
int answer = (int) (result * 10 + low);
if(answer <= higher)
{
System.out.print(answer + " ");
++count;
}
}
System.out.println("End of Application");
}
}
Computers and Technology
1 answer:
Mama L [17]3 years ago
6 0

Answer:

Corrected code is highlighted.

  1. // Displays five random numbers between
  2. // (and including) user-specified values
  3. import java.util.Scanner;
  4. public class DebugSix4
  5. {
  6. public static void main(String[] args)
  7. {
  8.     int high, low, count = 0;
  9.     final int NUM = 5;
  10.     Scanner input = new Scanner(System.in);
  11.     System.out.print("This application displays " + NUM +
  12.     " random numbers" +
  13.     "\nbetween the low and high values you enter" +
  14.     "\nEnter low value now... ");
  15.      low = input.nextInt() ;
  16.      System.out.print("Enter high value... ");
  17.      high = input.nextInt();
  18.      while(low > high)
  19.       {
  20.            System.out.println("The number you entered for a high number, " +
  21.           high + ", is not more than " + low);
  22.             System.out.print("Enter a number higher than " + low + "... ");
  23.            high = input.nextInt();
  24.       while(count < NUM)
  25.       {
  26.          double result = Math.random();
  27.          int answer = (int) (result * 10 + low);
  28.          if(answer <= high)
  29.          {
  30.              System.out.print(answer + " ");
  31.             ++count;
  32.           }
  33.         }
  34.       System.out.println("End of Application");
  35.    }
  36. }

Explanation:

Line 15 misses a semicolon at the end. It is syntax error

Line 17 misses a . between input and nextInt(). Dot syntax is required to invoke method.

Line 18 shows a logical error. it should be low > high so that the program can detect the error where the input value for high variable is lower than the variable low.

Line 30 shows a variable higher which doesn't exist. It should be changed to high.

You might be interested in
Write a program that reads raw data from a file that contains an inventory of items. The items should be sorted by name, and the
Anika [276]

Answer:

//C++ code

#include<iostream>

#include<fstream>

#include<iomanip>

using namespace std;

/*===============================================*/

// a structure called prod

struct prod

{

string name;// – a string, assumed to have no spaces

double price; // –adollaramount

int inStock; // – the number of items currently in stock.

};

//Fucntion Prototypes

void readInventory(prod products[], int& size);

/*===============================================*/

/*returns: a dollar amount, the total value of the inventory*/

double totalValue(prod products[], int size);

/*===============================================*/

// Sorts the given array by name

void sort(prod products[], int size);

/*===============================================*/

/*a report to a file called “report.txt”.

When the file fails to open, print

“Unable to open output file.” and end.*/

void writeReport(prod products[], int size);

/*===============================================*/

//Function definitions

/*===============================================*/

void writeReport(prod products[], int size)

{

ofstream outfile("report.txt");

outfile << fixed << setprecision(2);

if (!outfile)

{

cout << "Unable to open output file.\n";

return;

}

outfile << "+------------------------------+\n | Current Inventory |\n\

\n+------------------------------+\nNAME PRICE #\n\

\n-------------------- ------- ---\n";

for (int i = 0; i < size; i++)

{

outfile << products[i].name << " " << products[i].price << " " << products[i].inStock << endl;

}

outfile << "+------------------------------+\n";

outfile << "Number of products: " << size << endl;

outfile << "Inventory total value: " << totalValue(products, size) << endl;

cout << "Report written to file\n";

//close the output stream

outfile.close();

}

/*===============================================*/

void sort(prod products[], int size)

{

for (int i = 0; i < size; i++)

{

for (int j = i+1; j < size; j++)

{

if (products[i].name > products[j].name)

{

//swapping

prod temp = products[i];

products[i] = products[j];

products[j] = temp;

}

}

}

}

/*===============================================*/

double totalValue(prod products[], int size)

{

double total = 0;

for (int i = 0; i < size; i++)

{

total += products[i].inStock * products[i].price;

}

return total;

}

/*===============================================*/

void readInventory(prod products[], int& size)

{

// Open a file called “inventory.txt”

//and read the data from the file into the partial array

//.If the file fails to open,

//print “Unable to open input file”

//and set the number of products to 0.

size = 0;

ifstream inFile("inventory.txt");

if (!inFile)

{

cout << "Unable to open input file.\n";

return;

}

string name;

double price;

int qunatity;

while (inFile >> price >>qunatity >>name)

{

if (price != -1 && qunatity != -1 && name != "endofdata")

{

products[size].name = name;

products[size].inStock = qunatity;

products[size].price = price;

size++;

}

}

cout << "inventory read\n";

//close the stream

inFile.close();

}

/*===============================================*/

int main()

{

//declares a partial array of products

prod products[100];

int size;

// invokes readInventory()

readInventory(products, size);

// invokes sort()

sort(products, size);

// invokes writeReport()

writeReport(products, size);

// ends with the standard system pause.

system("pause");

return 0;

}

please see attachment for inventory text and output.

4 0
4 years ago
are you in active recovery from a substance use disorder (addiction)? active recovery is defined as being free from an alcohol o
salantis [7]

No, I am not in active recovery from a substance use disorder (addiction). Active recovery is defined as being free from an alcohol or other drug use disorder or no longer using alcohol or other drugs is a true statement.

<h3>What does it mean to be in addiction recovery?</h3>

The statement  implies that a person is working very hard to be  successful in handling their addiction and getting back control of your life.

Note that it is not an easy road but one can overcome. Therefore, my response is No, I am not in active recovery from a substance use disorder (addiction) because i do not drink it. Active recovery is defined as being free from an alcohol or other drug use disorder or no longer using alcohol or other drugs is a true statement.

Learn more about Active recovery from

brainly.com/question/28027699

#SPJ1

4 0
1 year ago
Who is he can anyone help me​
34kurt
This person is Elon Musk, the owner of Tesla :)
5 0
3 years ago
Read 2 more answers
What does the label display when the user clicks the button? void btnSubmit_Click(object sender, EventArgs e) { int num1 = 3; in
erma4kov [3.2K]

Answer:

10

Explanation:

num1=3 and num2=2

num3=myproc(num1)+myproc(num2)

myproc(num1) results 6

myproc(num2) results 4

when we add both e get 10

6 0
3 years ago
6. Which of the following is malware? (1 point)
lubasha [3.4K]
Software to damage computers
5 0
3 years ago
Read 2 more answers
Other questions:
  • David has created a lot of styles and now his Quick Style Gallery contains styles he no longer uses.
    14·2 answers
  • Which one is not the future of wireless technology?
    8·1 answer
  • i got a set of headphones and when i plug them into my speakers the right side only works how do i fix the left side of them
    12·1 answer
  • which of these describe raw data?check all of the boxes that apply A) what a person buys B) where a person lives C) data that ha
    9·1 answer
  • How many bits would be in the memory of a computer with 4kb memory?
    8·1 answer
  • Convert (35.125)10 to binary
    9·1 answer
  • What are the differences in LAN and WAN and how they are used to Increase Cybersecurity
    7·1 answer
  • What is an operating system?<br>​
    11·2 answers
  • Krya needs help deciding which colors she should use on her web page. What can she use to help her decide.
    11·1 answer
  • What is essential for a good study routine? Select four options.
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!