Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

12,(Bar Chart,complete the problem exactly as described) write a program that as

ID: 3540696 • Letter: 1

Question

12,(Bar Chart,complete the problem exactly as described) write a program that asks the user to enter today's sales for five stores. the program should display a bar chart comparing each store's sales. Create each bar in the chart by displaying a row of asterisks. Each asterisk should represent $100 of sales. Here is an example of the program's output:


   Enter today's sales for store 1: 1000[Enter]

   Enter today's sales for store 2: 1200[Enter]

   Enter today's sales for store 3: 1800[Enter]

   Enter today's sales for store 4: 800[Enter]

   Enter today's sales for store 5: 1900[Enter]



   SALES BAR CHART


   Store 1:**********

   Store 2:************

   Store 3:******************

   Store 4:********

   Store 5:*******************




1, Find the error in the following method definition:

  // This method has an error!

  public static void sayHello()

     System.out.println("Hello");

  }


2, Look at the following method header:

   public static void showValue(int x)

   The following code has a call to the showValue method.Find the error.

   float x = 8.6;

   showValue( x);  // Error!


3, Find the error in the following method definition:

   // This method has a error!

   public static int timesTwo(int num)

   {

      int result = num + num;

   }


4, Find the error in the following method definition:

   // This method has an error!

   public static int half(double num)

   {

      double result = num / 2.0;

      result result;

   }


5, (Algorithm workbench:) A program contains the following method definition:

   public static int square(int num)

   {

         return num * num;

   }

   Write a statement that passes the value 5 to this method and assigns its      return value to a variable named result.


6, A program contains the following method:

   public static void display(int arg1, double arg2, char arg3)

   {

        System.out.println("The values are " + arg1 + ", " +

                           arg2 + ", and " + arg3);

   }

   Write a statement that calls this method and the passes the following    variables as arguments:


   char initial = 'T';

   int age = 25;

   double income = 50000.00;


7, Write a method name timesTen, The method should accept a double argument,    and return a double value that is ten times the value of the argument.


8, Write a method named square that accepts an integer argument and returns    the square of the argument.


9, Write a method named getName that prompt the user to enter his or her    first name, and then returns the user's input.


10,Write a method named quartersToDollars. The method should accept an int argument that is a number of quarters, and return the equivalent  number of dollars as a double. For exaple, if you 4 as an argument , the method shuold return 1.0; and if you pass 7 as an argument, the method should return 1.75.

Explanation / Answer

// PROGRAM 1
import java.util.*;
public class barchart
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
int[] a= new int[5];
for(int i=0; i<5; i++)
{
System.out.println("Enter today's sales for store "+(i+1) + ":");
a[i] = in.nextInt();
}
System.out.println("SALES BAR CHART ");
for(int i=0; i<5; i++)
{
System.out.print("Store " + (i+1)+ ":");
for(int k=0; k<(a[i]/100); k++)
System.out.print("*");
System.out.println();
}
}
}
//

1.Find the error in the following method definition:
// This method has an error!
public static void sayHello() { // missing opening bracket.
     System.out.println("Hello");
}

2.Look at the following method header:
   public static void showValue(int x)
   The following code has a call to the showValue method.Find the error.
   float x = 8.6;
   showValue(x); // Error!
  
   // we need to pass integer as argument not floating point.
    showValue((int)x);

3. Find the error in the following method definition:
   // This method has a error!
   public static int timesTwo(int num)
   {
      int result = num + num;
    return result; // return result here ; return statement is missing.
   }

4.Find the error in the following method definition:
   // This method has an error!
   public static int half(double num)
   {
      double result = num / 2.0;
      result (int)result; // we have to return integer not double convert to integer.
   }

5.(Algorithm workbench:) A program contains the following method definition:
   public static int square(int num)
   {
         return num * num;
   }
   Write a statement that passes the value 5 to this method and assigns its return value to a variable named result.
   int result = square(5);

6.A program contains the following method:
   public static void display(int arg1, double arg2, char arg3)
   {
        System.out.println("The values are " + arg1 + ", " +arg2 + ", and " + arg3);
   }
   Write a statement that calls this method and the passes the following    variables as arguments:
   char initial = 'T';
   int age = 25;
   double income = 50000.00;
  
   display(age,income,initial);

7.Write a method name timesTen, The method should accept a double argument,and return a double value that is ten times the value of the argument.

public static double timesTen(double num)
{
return (10.0*num);
}

8.Write a method named square that accepts an integer argument and returns    the square of the argument.
   public static int square(int num)
   {
         return num * num;
   }

9.Write a method named getName that prompt the user to enter his or her    first name, and then returns the user's input.

public static String getName()
{
Scanner in = new Scanner(System.in);
System.out.println("Enter your Name");
return in.next();
}

10,Write a method named quartersToDollars. The method should accept an int argument that is a number of quarters,
and return the equivalent number of dollars as a double.
For exaple, if you 4 as an argument , the method shuold return 1.0; and if you pass 7 as an argument, the method should return 1.75.

public static double quartersToDollars(int quarters)
{
return (0.25*quarters);
}