Question
Create a C# console project in JetBrains Rider or Visual Studio Code and name it a2b_9. Create a file called LoneleyNumbers.cs and copy this code
Create a C# console project in JetBrains Rider or Visual Studio Code and name it a2b_9. Create a file called LoneleyNumbers.cs and copy this code into it.
namespace Lonely;
class OneLonelyNumber {
private int a = 0;
public int A {
get => a;
set { if (value > a) a = value;
} } }
class TwoLonelyNumbers : OneLonelyNumber {
private int b = 0;
public int B {
get => b;
set { if (value > b) b = value; } } }
Copy the following code into Program.cs.
using Lonely;
var aray = new OneLonelyNumber[10];
Random random = new Random();
for (int i = 0; i
if (random.Next(2) >= 1) {
aray[i] = new OneLonelyNumber();
aray[i].A = random.Next(10);
} else {
var tln = new TwoLonelyNumbers();
tln.A = random.Next(10);
tln.B = random.Next(20);
aray[i] = tln; } }
Write the code that traverses aray, outputing the values values in A and, if possible, B contained in each element. Place the output for each element on a line by itself.
Example run:
9
1 9
1
5
6
4
0 16
1
9
0
5 18
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started