Debug the following java code so that it will have given out put at the bottom. Make sure to fix all syntax and logical errors.
import java.util.Scanner;
public class Graphs
{
// draws 5 histograms
public void drawHistograms()
Scanner input = new Scanner( System.in );
int number1 = 0; // first number
int number2 = 0; // second number
int number3 = 0; // third number
int number4 = 0; // fourth number
int number5 = 0; // fifth number
int inputNumber; // number entered by user
int value = 0; // number of stars to print
counter = 1; // counter for current number
while ( int counter <= 5 )
{
System.out.print( "Enter number: " );
inputNumber = input.nextInt();
// define appropriate num if input is between 1-30
if ( inputNumber >= 1 && inputNumber <= 30 )
{
switch ( inputNumber )
{
case 1:
number1 = inputNumber;
break; // done processing case
case 2:
number2 = inputNumber;
break; // done processing case
case 3:
number3 = inputNumber;
4:
number4 = inputNumber;
break; // done processing case
case 5:
number5 = inputNumber;
break; // done processing case
counter++
} // end if
else
System.out.println(
"Invalid Input\nNumber should be between 1 and 30" );
} // end while
// print histograms
for ( counter = 1, counter >= 5, counter++ )
{
switch ( counter == 1 )
{
case 1:
value = number1;
break; // done processing case
case 2:
value = number2;
break; // done processing case
case 3:
value = number3;
break; // done processing case
case 4:
value = number4;
break; // done processing case
case 5:
value = number5;
break; // done processing case
}
for ( int j = 1; int j <= value; int j++ )
System.out.print( "*" );
System.out.println();
} // end for loop
} // end method drawHistograms
} // end class Graphs
Sample output
--------------------Configuration:
<Default>--------------------
Enter number: 5
Enter number: 2
Enter number: 8
Enter number: 4
Enter number: 6
*****
**
********
****
******
Process completed.
//Program is well tested and producing the same output as above. The above code is buggy and not feasible. So i wrote the //code from scratch to fulfill the need.
class Main
{
public static void drawHistograms(){
//Defining Scanner class to take input
Scanner sc = new Scanner(System.in);
//Defining Variables
int array[]=new int[10]; //increase the array size according to
need
int i,j,k,number,counter=0;
char c ='*';
//Loop to recurcively take 5 inputs for making histogram. Change
the value in loop to increase number of inputs
while(counter<5){
System.out.print("Enter Number: ");
number = sc.nextInt();
array[counter] = number;
counter = counter+1;
}
//making histogram
for(i =0; i<array.length; i++){
for(j=0;j<array[i];j++){
System.out.print(c);
}
System.out.println("");
}
}
//main Function
public static void main (String[] args) {
//calling method
drawHistograms();
}
}
Debug the following java code so that it will have given out put at the bottom....
LANGUAGE IS JAVA CALCULATOR USING SCIENTIFIC/STANDARD MODE ERRORS: ADDITION AND DIVISION NOT WORKING FOR EITHER CALCULATOR CODE: import java.util.Scanner; public class CalculatorProject { public static void main (String[] args) { Scanner yurr = new Scanner(System.in); String mode; double i; String choice; String answer = "Y"; while (answer.equals("Y")) { System.out.println("Enter the calculator mode: Standard/Scientific?"); mode = yurr.next(); if(mode.equals("Scientific")) { System.out.print("Enter '+' for addition, '-' for subtractions, '*' for multiplication, '/' for division, 'sin' for sin x, 'cos' for cos x,...
IN JAVA: Write a program that displays a menu as shown in the sample run. You can enter 1, 2, 3, or 4 for choosing an addition, subtraction, multiplication, or division test. After a test is finished, the menu is redisplayed. You may choose another test or enter 5 to exit the system. Each test generates two random single-digit numbers to form a question for addition, subtraction, multiplication, or division. For a subtraction such as number1 – number2, number1 is...
In the following code, it gets hung up at cout << "Number1 * Number2 = " << number1 * number2 << endl; giving an error of "no math for operator<<" what am i doing wrong? Thank you #include <iostream> #include <cctype> #include <cstdlib> using namespace std; class Rational //class for rational numbers (1/2, 5/9, ect..) { public: Rational(int numerator, int denominator); Rational(int numberator); Rational(); //default friend istream& operator >>(istream& ins,...
what is the output of the below programs Set Number1 = 1 2. Set Number2 = 2 3. Set Number3 = 3 4. Set value of Sum = Number1+Number2+Number3 5. while (sum <= 39) Number1 = Number2 Number2 = Number3 Number3 = Sum Sum = Number1+Number2+Number3 output “*” 6. end of while loop 7. output “Number1 is :”, output Number1 8. output “Number2 is:”, output Number2 9. output “Number3 is:”, output Number3 10. output “Sum is:”, output Sum what is...
1. What is the output of each of the following code segments if the inputs are as follows: 5 0 15 -5 2 Scanner input = new Scanner(System.in); int sum = 0; for(int i = 0; i < 5; i++){ System.out.print( “Enter a number”); int number = input.nextInt(); if(number <= 0) break; sum += number; } System.out.println(sum); Second Segment: Scanner input = new Scanner(System.in); int sum = 0; for(int i = 0; i < 5; i++){ System.out.print( “Enter a number”);...
Java Im doing a binary search on an array and need to allow as many queries as possible and cannot figure out how to. The output should read something like this. Enter a number. 3 3 is a prime number. Enter another number. 4 4 is not a prime number. Enter another number. 8 Current file not large enough for 8. Enter another number. -1 Bye. My code so far looks like this. public static void main(String[] args) {...
Could you help me pleas , this is my code I want change it to insert student by user , and i have problem when i want append name it just one time i can't append or present more one. >>>>>>>>>>>>>>>>>>>. import java.util.Iterator; import java.util.Scanner; public class studentDLLTest { static int getChoice() { Scanner in = new Scanner(System.in); int choice; do { System.out.print("\nYour choice? : "); choice = in.nextInt(); } while (choice < 1 || choice > 9); return choice;...
Hi. This is a prototype of Java. The following Java program was developed for prototyping a mini calculator. Run the program and provide your feedback as the user/project sponsor. (Save the code as MiniCalculator.java; compile the file: javac MiniCalculator.java; and then run the program: java MiniCalculator). HINTs: May give feedback to the data type and operations handled by the program, the way the program to get numbers and operators, the way the calculation results are output, the termination of the...
I need the following java code commented import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner input = new Scanner (System.in); int productNo=0; double product1; double product2; double product3; double product4; double product5; int quantity; double totalsales=0; while(productNo !=0) System.out.println("Enter Product Number 1-5"); productNo=input.nextInt(); System.out.println("Enter Quantity Sold"); quantity=input.nextInt(); switch (productNo) { case 1: product1=1.00; totalsales+=(1.00*quantity); break; case 2: product2=2.00; totalsales+=(2.00*quantity); break; case 3: product3=6.00; totalsales+=(6.00*quantity); break; case 4: product4=23.00; totalsales+=(23.00*quantity); break; case 5: product5=17.00; totalsales+=(17.00*quantity); break;...
Could someone re-write this code so that it first prompts the user to choose an option from the calculator (and catches if they enter a string), then prompts user to enter the values, and then shows the answer. Also, could the method for the division be rewritten to catch if the denominator is zero. I have the bulk of the code. I am just having trouble rearranging things. ------ import java.util.*; abstract class CalculatorNumVals { int num1,num2; CalculatorNumVals(int value1,int value2)...