Define a class called counter

Assignment Help Software Engineering
Reference no: EM13313221

Problem1:

The Fibonacci numbers are defined by the sequence:
f1 = 1
f2 = 1
fn = fn-1 + fn-2.
Reformulate that as
Fold1 = 1;
Fold2=1;
Fnew=fold1+fold2;

After that, discard fold2, which is no longer needed, and set fold2 to fold1, and fold1 to fnew. Repeat an appropriate number of times.
Implement a program that prompts the user for an integer n and prints the nth Fibonacci number, using the above algorithm.

Problem 2:

Write a program that prints a multiplication table, like this:
1 2 3 4 5 6 7 8 9 10
2 4 6 8 10 12 14 16 18 20
3 6 9 12 15 18 21 24 27 30
...
10 20 30 40 50 60 70 80 90 100

Problem 3:

The Drunkard's Walk. A drunkard in a grid of streets randomly picks one of four directions and stumbles to the next intersection, then again randomly picks one of the four directions, and so on. You might think that on average the drunkard doesn't move very far because the choices cancel each other out, but that is actually not the case.

Represent locations as integer pairs(x,y). Implement the drunkard's walk over 100 intersections, starting at (0,0) and print the ending location.

Problem 4:

Define a class called Counter. An object of this class is used to count things so it records a count that is a non-negative whole number. Include methods to set the counter to 0, to increase the counter by 1, and to decrease the counter by 1. Be sure that no method allows the value of the counter to become negative. Also include an accessor method that returns the current count value, as well as a method that displays the count on the screen. Do not define an input method. The only method that can set the counter is the one that sets it to zero. Write a program to test your class definition. (Hint: you need only one instance variable).

Problem 5:

Consider a class that could be used to play a game of hangman. The class has the following attributes:
• The secret word
• The disguised word, in which each unknown letter in the secret word is replaced with a question mark (?). For example, if the secret word is abracadabra, and the letters a , and b have been guessed, the disguised word would be ab?a?a?ab?a
• The number of guesses made
• The number of incorrect guesses

It will have the following methods:
• MakeGuess(c) guesses that character c is in the word
• getDisguisedWord returns a string containing correctly guessed letters in their correct positions and unknown letters replaced with ?
• getSecretWord returns the secret word
• getGuessCount returns the number of guesses made
• isFound returns true if the hidden word has been discovered.

Perform the following actions:
• Write a method heading for each method.
• Write preconditions and postconditions for each method.
• Write some Java statements that test the class.
• Implement the class.
• List any additional methods and attributes needed in the implementation that were not listed in the original design. List any other changes made to the original design.
• Write a program that implements the game of handgman, using the class you wrote for part d.

Problem 6:

Consider a class Movie that contains information about a movie. The class has the following attributes:
• The movie name
• The MPAA rating (e.g. G, PG, PG-13, R)
• The number of people that have rated this movie as a 1 (Terrible)
• The number of people that have rated this movie as a 2 (Bad)
• The number of people that have rated this movie as a 3 (OK)
• The number of people that have rated this movie as a 4 (Good)
• The number of people that have rated this movie as a 5 (Great)

Reference no: EM13313221

Questions Cloud

Find the net work done on the box : A box of mass 5.4 kg is accelerated from rest by a force across a floor at a rate of 2.0 m/s2 for 9.0 s. Find the net work done on the box
Period expense, direct cost or indirect cost : Period expense, direct cost or indirect cost.
What is the undrained shear strength of the clat in kpa : A saturated clay deposit is vane-tested in-situ. A torque of 30Nm is required to shear the clat. The vane is 40mm wide by 100mm long. What is the undrained shear strength of the clat in kPa
Find its resulting charge : A soot particle, originally neutral, gets charged in a process that removes 27 electrons. Find its resulting charge
Define a class called counter : Define a class called Counter. An object of this class is used to count things so it records a count that is a non-negative whole number. Include methods to set the counter to 0, to increase the counter by 1, and to decrease the counter by 1.
Determine what is the pore water pressure at that level : A river is 6m deep. The riverbed material has a saturated unit weight of 19.5kN/m3. What is the effective vertical stress 12m below the water surface. Assume the water is static and assume a datum at the water surface.
Explain sodium bromide plus sodium sulfide : What is the name of the compound when you say Sodium Bromide plus Sodium Sulfide. Also, please write the formulas for each.
At what angle upstream should the driver head the boat : The driver of a motorboat that can move at 10 m/s wishes to travel directly across a narrow strait in which the current flows at 5 m/s. At what angle upstream should the driver head the boat
Plot the process on a p-v diagram and a p-t diagram : A frictionless piston-cylinder contains 2kg of nitrogen at 100 kPa absolute and 300 deg K. The system is compressed polyprotically at a 1.4 exponent (n) until the nitrogen reaches a final temperature of 360 deg K.

Reviews

Write a Review

Software Engineering Questions & Answers

  Explain elicitation of unb course registration system

As a system analyst to do requirement elicitation of UNB course registration system, use an example to tell how you can apply this technique to your elicitation task.

  Software management

SOFT337 – Software Management, Demonstrate the  ability to investigate, gather appropriate sources, analyse, evaluate key challenges and discuss future trends within the chosen area of your choice .

  Object oriented system design with uml

Provid with initial needs collected at the first interview with the owner of a video rental store, who is ordering an data system to improve efficiency of his business.

  Question about c programming

Construct a conditional that assigns 10,000 to the variable bonus if the value of the variable goodsSold is greater than 500,000.

  Data flow diagram for new customer support system

A context diagram, also called a Data Flow Diagram (DFD), documents the scope of the new customer support system. It focuses primarily on output from the system.

  Standard tricks of cryptic crossword

Cryptic crosswords you have to decipher the clue to determine the word. One of the standard tricks of cryptic crossword creators is to use anagrams.

  Draw e-r diagram when doctor prescribe drugs for patients

Draw the E/R diagram for following situation: Doctors prescribe drugs for patients. A given doctor can prescribe many drugs for a certain patient.

  Recognize different phases of the sdlc

The systems development life cycle (SDLC) is a framework which consists of distinct sequential processes.  Recognize different phases of the SDLC?

  Highlights of project development activities

Assume you have just been asked to take over an existing assignment and asked to make a few changes for new features.

  What is the normal value assumed for k

A paging company operates a paging transmitter on a frequency of 740Mhz. What is the reachable range if the transmit antenna is located at 450' and we assume the receivers are located 3' above the ground (belt level?)

  Draw an erd for initial entity list

Draw an ERD for initial entity list. Recognize a primary key for each entity and establish relationships as appropriate. Entity list for this purpose is as follows.

  Discuss the limitations of software testing

Discuss the limitations of software testing. How do we say that complete testing is impossible?  What is Software Quality Assurance? What are the objective and goals of SQA?

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