Here's a fun little exercise that will randomly assign a number to each of the elements in an array and then run through the elements making any odd numbers even.

1. Create a class called EvenMaker
2. In EvenMaker, create fields to hold an array of ints (call it numbers) and a Random number generator.
3. In EvenMaker, create a constructor that requires a parameter (refer back to 4.10 if needed). The parameter will be an int named size. In the constructor, use size to initialize the numbers array to the size parameter. Also initialize the random number generator.
4. In EvenMaker, create a method called Fill. This will loop through the numbers array. For each element location, the method should generate a random number (between 1 and 50) and assign the element to the random number.
5. In EvenMaker, create a method called MakeEven. In this method, you should loop through the numbers array. For each element, if the value is odd, add one to the value.
6. In EvenMaker, create a method called Show, which simply loops through the array and writes out the value of each element in the array with spaces in between each (e.g., 5 3 4 7 10 12).
7. In Program, your Main method should ask for a size, create an EvenMaker object (passing the user supplied size), call Fill, call Show, call MakeEven, and then call Show again. The results might look something like this:

How many elements? 10
12 41 23 44 9 27 36 15 49 4
12 42 24 44 10 28 36 16 50 4

Solution PreviewSolution Preview

This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Ch8_EvenMaker
    class EvenMaker
       private int[] numbers;
       private Random rand;

       public EvenMaker(int size)
            numbers = new int[size];
            rand = new Random();

       public void Fill()
            for (int i = 0; i < numbers.Length; i++)
$30.00 for this solution

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Visual Basic Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Upload a file
Continue without uploading

We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats