C application using array Considering two types of cars Niss

C# application using array.

Considering two types of cars: Nissan and Toyota; There are 4 available Nissan cars and 4 available Toyota cars. Use array to create C# application that prompt the user for car type (Nissan, Toyota) then reserves an order of that type. First 4 array orders are Nissan, and the second 4 array orders are Toyota. When there is no car of that type available, show a message letting the user know that there is no car available.

Test cases:

1 Nissan

2 Toyota

3 Toyota

4 Toyota

5 Toyota

6 Nissan

Solution

program

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

namespace ConsoleApplication5
{
class Program
{
static void Main(string[] args)
{

String[] nissancars = { \"Nissan\", \"Nissan\", \"Nissan\", \"Nissan\" };
String[] toyotocars = { \"Toyota\", \"Toyota\", \"Toyota\", \"Toyota\" };

Console.WriteLine(\"do you want cars on not if type y/n\");

String choice = Console.ReadLine();
int nlength = nissancars.Length;
int tlength = toyotocars.Length;

if (choice.Equals(\"y\"))
{
while (choice.Equals(\"y\"))
{
Console.WriteLine(\"enter your favorite car nissan or toyota\");
String carchoice = Console.ReadLine();
if (carchoice.Equals(\"Nissan\".Trim ())||carchoice .Equals (\"nissan\".Trim ()))
{
if (nlength == 0)
{
Console.WriteLine(\"no cars are available for this model\");
break;
}
else
{

nlength = nlength - 1;
Console.WriteLine(\"success\");
}

}
else if (carchoice.Equals(\"Toyota\".Trim ())||carchoice .Equals (\"toyota\".Trim ()))
{
if (tlength == 0)
{
Console.WriteLine(\"no toyota cars available \");
break;
}
else
{
tlength = tlength - 1;
Console.WriteLine(\"toyota booking is success\");
}

}

Console.WriteLine(\"do you want cars or not if type y/n\");
choice = Console.ReadLine();

}
}else
{
Console.WriteLine(\"you didn\'t choose any car..........thank u for visiting\");
}

Console.WriteLine(\"the nissan available cars are {0}\", nlength );
Console.WriteLine(\"the toyota available cars are {0}\", tlength);
Console.ReadKey();
}
}
}

output

do you want cars on not if type y/n
y
enter your favorite car nissan or toyota
nissan
success
do you want cars or not if type y/n
y
enter your favorite car nissan or toyota
nissan
success
do you want cars or not if type y/n
y
enter your favorite car nissan or toyota
toyota
toyota booking is success
do you want cars or not if type y/n
y
enter your favorite car nissan or toyota
toyota
toyota booking is success
do you want cars or not if type y/n
y
enter your favorite car nissan or toyota
toyota
toyota booking is success
do you want cars or not if type y/n
y
enter your favorite car nissan or toyota
toyota
toyota booking is success
do you want cars or not if type y/n
y
enter your favorite car nissan or toyota
toyota
no toyota cars available
the nissan available cars are 2
the toyota available cars are 0

C# application using array. Considering two types of cars: Nissan and Toyota; There are 4 available Nissan cars and 4 available Toyota cars. Use array to create
C# application using array. Considering two types of cars: Nissan and Toyota; There are 4 available Nissan cars and 4 available Toyota cars. Use array to create
C# application using array. Considering two types of cars: Nissan and Toyota; There are 4 available Nissan cars and 4 available Toyota cars. Use array to create

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site