Prepare a scenario diagram for problem

Assignment Help Programming Languages
Reference no: EM13324916

Prepare a scenario diagram for Problem 1, Brief discussion for Problem 2, and Ruby source code for Problem 3.

 

Problem 1:

Here is an interaction in a tic-tac-toe game, with user input in bold:
>> gm = Game.new('andy', 'mike')

=> #<Game:0x2e91d78 @players=[Andy, Mike]>

>> gm.play_game('mike')

Mike, enter your next O move (1-9): 1
O - -
- - -
- - -

Andy, enter your next X move (1-9): 3
O - X
- - -
- - -

Mike, enter your next O move (1-9): 5
O - X
- O -
- - -

Andy, enter your next X move (1-9): 3

Bad move dude! You go again.
O - X
- O -
- - -

Andy, enter your next X move (1-9): 6
O - X
- O X
- - -

Mike, enter your next O move (1-9): 9
O - X
- O X
- - O

Mike, you won!
=> nil
>> gm.play_game('karen')

I don't know that player. Please try again. => nil

>> gm.play_game('andy')
Andy, enter your next O move (1-9): 5
- - -
- O -
- - -
When a new game is created, two players register with it by name (the arguments to Game.new). The play_game message is called with one of the player's names and starts a new game where that player plays first using the O marker. (A game can be sent repeated play_game messages so the same pair of players can play multiple games). In each iteration, the current player is prompted for the position of her move and then she enters the move number, where the nine squares are numbered in row-major order from 1 through 9. If a move is illegal (i.e., already occupied), the current player is scolded and prompted again for a move. After each move, the board is redrawn. A game ends when either one of the players forms a horizontal, vertical, or diagonal row of her three markers (in the usual way), or the board is full indicating a tie.

The assignment is not to implement this game in Ruby. Rather, the assignment is to use scenario diagrams to discover the objects, their responsibilities, and the messages they respond to. Specifically, focus on the scenario of a typical iteration: If the current game is not over, the current player is prompted for a legal move which she supplies and then the move is made and the current game board is displayed. Hand in a single scenario diagram that you believe represents your best design.

Problem 2

Here is a class definition in Ruby:
class C
attr_accessor :f

def g(x)
self.f=(x)
end

def h(x)
f = x
end

def i(x)
self.f = x
end
end

What does the following transcript teach us?

>> c = C.new
=> #<C:0x2afabd8>
>> c.g(2)
=> 2
>> c.f
=> 2
>> c.h(5)
=> 5
>> c.f
=> 2
>> c.i(7)
=> 7
>> c.f
=> 7

Problem 3

Write a PhoneContact class that gets initialized with a phone number and a label. The phone number should follow one of the formats of the Phone class from the previous assignment (and you should use the Phone class in this assignment). A label is either a symbol or a string. A phone contact responds to the label, phone_number, and to_s messages. Note that phone_number returns a Phone object:

>> contact1 = PhoneContact.new('(954) 555-1212', :work)
=> (954) 555-1212 (work)
>> contact1.label
=> "work"
>> contact1.phone_number
=> "(954) 555-1212"
>> contact1.to_s
=> "(954) 555-1212 (work)"
>> contact2 = PhoneContact.new(' 955-555-1212', "cell")
=> (955) 555-1212 (cell)
>> contact2.phone_number.area_code
=> 955 

Reference no: EM13324916

Questions Cloud

How to calculate the ph of sodium formate solution : Given 217 mL of a buffer solution that is 0.46 M formic acid and 0.27 M sodium formate, calculate the pH of this solution after the addition of 2.8 mL of 6.3 M hydrochloric acid. The Ka of formic acid is 1.8x10-4
With what temperature does the air emerge : The rear end of an air conditioner dumps 1.2 * 10^7 J/hr of waste heat into the air outside a building. A fan assists in the removal of this heat. With what temperature does the air emerge
Generate a database diagram : For each of these statements, include a screenshot of the SQL. Make sure to include the statement execution, including the resulting data. Display all columns and all rows from the Employees table.
Explain what is the path these electrons use : What is the path these electrons use in the Electron Transport Chain? Answer A. Complex I, Complex II, Complex III, Complex IV, O2 to H2O B. Complex II, Complex III, Complex IV, O2to H2O C.
Prepare a scenario diagram for problem : Write a PhoneContact class that gets initialized with a phone number and a label. The phone number should follow one of the formats of the Phone class from the previous assignment - Prepare a scenario diagram for Problem 1, Brief discussion for Pro..
Compute the ph of a solution made by dissolving of sodium : Calculate the pH of a solution made by dissolving 2.89 g of sodium fluoride and 17.1 mL of 0.309 M hydrofluoric acid in enough water to make 177 mL of solution.
Most influential architecture is michaelangelo : In my opinion, the most influential architecture is Michaelangelo, the work titled "the Creation of Adam." Explain why. The most influential architecture in Nashville is the state capitol building? Explain why. Who was the architect.
Explain daily energy requirement for an active adult human : The daily energy requirement for an active adult human is around 2500 calories per day. A nutritional calorie is equal to 4.2 kJ of energy. If each ATP contains -30 kJ/mol under standard conditions, how many molecules of ATP does the body require ..
Developments in communications technology : Do you think that developments in communications technology would lower the costs of trade? If so what particular costs of trade are likely to be reduced?

Reviews

Write a Review

Programming Languages Questions & Answers

  Can explain procedural language in clearly and simply?

Can explain procedural language in clearly and simply? And compare other object-oriented programming, functional programming, logic programming and imperative programming.

  Write program which reads data into type integer

Write down the program which reads data into type int. Valid values are from 0 to 10. The program must find out how many values were inputted.

  Explaining variable in an arrays of ints

Assume that variable A is an arrays of ints. Consider the following code segment.

  Create a class uses a 25-element array of digits

Create a class HugeInteger which uses a 25-element array of didgits to store integers as large as 25 digits. Provide services inputHugeInteger, otputHugeInteger.

  Give value of mytop and contents of the array

Assume that stack is the class described in this section with stacktype set to int and stack_capacity or mycapacity set to 5. Give the value of mytop and the contents of the array.

  Design the logic for application for company

Design logic for an application for company which wants a report containing a breakdown of payroll by department. Input includes each employee's last name, first name, department number.

  Program a robot to run mile-long steeplechase

Program a robot to run mile-long steeplechase where steeples are made from beepers instead of wall segmesnts. the robot must jumb the steeples in this race by picking the beepers that make up the steeples.

  Write a class for two instance variables

Write a class named ParkingMeter containing: Two instance variables named timeLeft and maxTime of type int. The value of timeLeft should be initialized to 0.

  Write class to represent temperatures in degree and celsius

Write a Temperature class that represents temperatures in degrees in Celsius, Fahrenheit and Kelvin. Use a floating-point number for the temperature and a character (type char) for the scale.

  Program to read sales amount-calculate sales commissions

Write down the program to read the sales amount and calculates sales commissions using following scheme.

  Explain the process to develop a web page locally

Explain the process to develop a Web page locally

  Display policy data after revisions have made

The day is not correct for the month (that is, between 1 and 31 for January, 1 and 29 for February, and so on), then set the month, day, and year to 0. Display the policy data after any revisions have been made.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd