Question

In: Computer Science

                                          &nb

                                                       Checker

+DisplayCount(int [], int):void


The code below is a partial implementation of the class diagram above. Note the similarities between
the class diagram and its implementation.

class Checker
{
   /*
    * Method DisplayCount
    * This method should display the numbers of times
    * a given number (x) is found in a given array (numbers)
    *
    * Provide the implementation (method body) for DisplayCount
    */
   public void DisplayCount(int[] numbers, int x)
   {

   }
}

I need to complete the implementation of method DisplayCount as described in the comments above, and I need to write a test class that uses class Checker and its DisplayCount method.

Assuming an array like this:

7 5 9 0 1 2 3 2 7 9

If the value of x is 10, the output should be:
10 is in the array 0 times
If the value of x is 7, the output should be:
7 is in the array 2 times

Solutions

Expert Solution

//Java code

class Checker
{
   
    public void DisplayCount(int[] numbers, int x)
    {
        int count =0;
        for (int i = 0; i <numbers.length ; i++) {
            if(x==numbers[i])
                count++;
        }
        System.out.println(x+" is in the array "+count+" times");
    }
}

// Test Class

public class Main {
    public static void main(String[] args)
    {
        int[] array = {7,5,9,0,1,2,3,2,7,9};
        Checker checker= new Checker();
        checker.DisplayCount(array,7);
    }
}

//Output

//This code in c#

using System;


class Checker
{

public void DisplayCount(int[] numbers, int x)
{
int count = 0;
for (int i = 0; i < numbers.Length; i++)
{
if (x == numbers[i])
count++;
}
Console.WriteLine(x + " is in the array " + count + " times");
}
}
class Program
{
static void Main(string[] args)
{
int[] array = { 7, 5, 9, 0, 1, 2, 3, 2, 7, 9 };
Checker checker = new Checker();
checker.DisplayCount(array, 7);
//pause
Console.ReadLine();
}
}


//Output

//If you need any help regarding this solution ........... please leave a comment ........ thanks

"C:\Program Files\Java\jdk1.8.0_221\bin\java.exe" ... 7 is in the array 2 times Process finished with exit code 0


Related Solutions

                                          &nb
                                                               $ Sales 10,000,000 Cost of sales                                   (6,000,000) Gross profit 4,000,000 Expenses                                        (3,000,000) Net profit 1,000,000 It had been budgeted to produce 200,000 units and these should have taken 10 hours each. In fact, 120,000 units were produced in 580,000 hours. The capital employed by the division is $4,000,000 and the interest rate is 7%. Calculate: (a) Efficiency, capacity utilisation and production volume ratios or percentages (b) ROCE (Return on Capital Employed) (c) RI (Residual Income)
                                          &nb
                                                                                                Assembly                    Customizing Total machine hours                                                               19,000                         15,000 Direct labor hours                                                                   4,000                           6,000 Fixed manufacturing overhead                                               $100,700                     $63,000 Variable manufacturing overhead per machine hour             $2.00                           - Variable manufacturing overhead per labor hour                   -                                   $3.90 Overhead rate based on:                                                         Machine hour              Labor hour 18. What is the predetermined overhead rate for the Assembly department? 19. What is the predetermined overhead rate for the Customizing department?
                                          &nb
                                                       The marketing manager of a national brand of flavored milk is considering her micro and macro environment in order to complete the situation analysis for this years marketing plan. She notes some key points. Small traders are not consistently affording appropriate fridge space to flavored milks. Energy drinks are continuing to hold favour in the teen market. Young adults aged 18-25 are more conservative than their slightly older cohort 25-35. UHT or long life milk has processed to the...
                                          &nb
                                                          Balance Sheet 2019 2020 2021 Asset Current Asset Cash ? ? ? Accounts Receivable 120000 100000 150000 Prepaid Expenses 8000 5000 2000 Future Tax Asset ? ? ? Long-term Asset ? Total Assets Liabilities Current Liabilities Accounts Payable 100000 80000 90000 Unearned Revenue 10000 8000 12000 Future Tax Liabilities ? ? ? Long-term Liabilities ? Total Liability Shareholders' Equity Retained Earnings ? ? ? Common Equity 200000 200000 200000 Total Shareholders' Equity Total Liability and Equity Company A started...
                                          &nb
                                                Units Cost per unit Total Beginning inventory 60 $10                Puirchase 3/31 40 $11                  Purchase 4/30 40 $12                  Purchase 5/31 60 $13                   Total 200                                           There are a total of 200 units. 80 units were left in ending inventory. Calculate the following under the periodic method for costing inventory: Compute ending inventory using FIFO. Compute cost of merchandise sold using FIFO. Compute ending inventory using LIFO.                  Compute cost of merchandise sold using FIFO. Compute ending inventory using weighted average cost.   Compute...
                                          &nb
                                                            1st Quarter        2nd Quarter       3rd Quarter       4th Quarter Total Cash Receipts                              $150,000         175,000           100,000           450,000 Total Cash Disbursements                     $170,000         250,000           100,000           320,000 The company’s beginning cash balance for the upcoming fiscal year will be $40,000. The company requires a minimum cash balance of $15,000 and may borrow any amount needed from a local bank at a quarterly interest rate of 3%. The company may borrow any amount at the beginning of any quarter and may repay its loans, or any part of its loans, at the end of any quarter. Interest...
                                          &nb
                                                           Question Two Faulu College has a total of 52 students undertaking three courses namely; Business Mathematics, Economics and Law. During recently conducted examinations, 13 students excelled in Business Mathematics and Law, 16 students excelled in Business Mathematics and Economics and 12 students excelled in Law and Economics. The number of students that excelled in Economics was 24 while 2 students excelled in none of the three courses. The number of students who excelled in Business Mathematics only was...
                                          &nb
                                                                                          To build the chairs and tables, a machine was purchased and workers were hired. Part of the manufacturing process for both products is automated, and part of the manufacturing process for both products is done by hand.                                                                                                      The number of each product to be produced is as follows:                                                                                                                                                   Yearly Number Of Chairs To Be Produced              104,000                                                            Yearly Number Of Tables To Be Produced              80,000                                                                                                                           It is determined that to produce...
                                          &nb
                                                            Continuous Probability Distributions You must draw diagram for each question and show all workings. Answers without clearly labelled diagrams and workings will not score full marks. Before we can use the Z tables, we have to standardise the normal variable (X) first, i.e. converting X into Z score. THA 4 will assess you on your ability of applying the standardisation formula and using the Z and inverse Z tables. Question 1 Stock Returns Stock returns are often assumed to...
                                          &nb
                                                           (4 points) Production Possibility Frontiers: apples and wheat Table 1. Production of apples and wheat Apples Wheat 0            500 1            499 2            495 3            489 4            476 5            453 6            415 7            358 8            275 9            160 10                 5 (1 point) Draw a production possibilities curve for your two-acre farm between growing apples and wheat. Is there a tradeoff between these two? How is a tradeoff shown in...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT