0

First of all i am learning c# and i got a homework assignment. But i didn't figure it out myself. I can't find the random numbers. Shall i write it in an apart class or actually i have no idea where i can start.

what i need to do is:

Create a gambling game where the user can bet on a race between two cars . The winner of the race is determined by the horsepower of the engine of the racing cars . Provide an OO solution wherein the following classes and their properties are used :

car
- number
- Engine
engine
- HP

When a car object is created will automatically Engine object created and are allocated . It is not possible to adjust . The engine of a car Also, the number of PK of the motor is determined by the creation of the engine and can not be changed by a external class . Determining the number of HP in the engine class you can in the following way :

<PkProperty> = New Random ( ) Next ( <min> , <max> ) . ;
Example : Pk = new Random ( ) Next (80 , 500 ) .

<PkProperty> Where the name of your HP property and and denote the minimum and maximum value is between which a random number can be found. The user will first need to enter the race cars. 2 songs After that, the program the listing of both cars to = ratio of the probability of winning the 1st car compared to the 2nd car .

Just as the number of PK can be determined with this listing :

<notering> = new Random ( ) Next ( <min> , <max> ) . ;
Example : int = new listing Random ( ) Next ( 1 , 30 ) .

On the basis of this data, the user must enter the correct number of the car and the amount he wants to bet . Finally, the program is the result of the race , and any announce earnings .

13
  • 3
    Can you share what you have tried so far? Commented Nov 21, 2013 at 17:34
  • 5
    @CoreyOgburn: Bear in mind that English is not the first language of every one !! Commented Nov 21, 2013 at 17:38
  • 7
    @huMptyduMpty that's completely understandable, but there's a difference between incorrect English grammar and completely incomprehensible sentences. The user will first need to enter the race cars. 2 songs After that, the program the listing of both cars to = ratio of the probability of winning the 1st car compared to the 2nd car . What does that even mean?! Commented Nov 21, 2013 at 17:41
  • 3
    Did the code go through the same translator? The syntax of the code is totally wrong. Commented Nov 21, 2013 at 17:43
  • 2
    Google translate made mistakes to make it impossible for us to understand. Please add the original text you put in to Google Translate to the bottom of your question. We still want to help you but we have trouble understanding you. Commented Nov 21, 2013 at 18:03

1 Answer 1

1

As long as I understand the question's language the project is pretty simple. I hope you do not want us to do your homework for you.

  1. Create Engine class. Set number and HP fields, set HP property and accessor as read only (only {get;}),.
  2. Include constructor that will take no arguments but include Random class instantiator to set HP field. Use Next() twice to ensure randomization.
  3. Create Car class, use Engine class as one of its fields, the other car number as int. Set properties for both engine and car number and accessors as get only.
  4. Include constructir that will take int as a car number. Hav constructor for car use constructor for engine to instantiate engine.
  5. In main class instantiate two cars.
  6. Sum the horspower of first and second cars.
  7. Create parallel arrays of car numbers and bets and take bets. Also instantiate new Random that you will use in next method.
  8. Create Race() method that will take car as an argument and return bool. Use random instantiated in step 7 above to find number between 0 and the sum of both cars' HP. Compare current car's HP to the random number. If number is less or equal to car's HP return true. If not return false.
  9. Run method Race() for each car and store result in respective bools. If both bools are true or both are false, it is a draw. If one is true and the other is false - you get a winner.
Sign up to request clarification or add additional context in comments.

1 Comment

thanks. but I didn't get the second one. because we haven't seen that topic yet. I mean the random class.so i did something like public int Pk { get { new Random().Next(number1,number2); return pk; }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.