subject

Assume that the classes listed in the Java Quick Reference have been imported where appropriate. Unless otherwise noted in the question, assume that parameters in method calls are not null and that methods are called only when their preconditions are satisfied. In writing solutions for each question, you may use any of the accessible methods that are listed in classes defined in that question. Writing significant amounts of code that can be replaced by a call to one of these methods will not receive full credit. This question involves the implementation of the AdditionPattern class, which generates a number pattern. AdditionalPattern object is constructed with two positive integer parameters, as described below.

The first positive integer parameter indicates the starting number in the pattern. The second positive integer parameter indicates the value that is to be added to obtain each subsequent number in the pattern.

The AdditionPattern class also supports the following methods

currentNumber, which returns the current number in the pattern

next, which moves to the next number in the pattern

prev, which moves to the previous number in the pattern or takes no action if there is no previous number

The following table illustrates the behavior of an AdditionPattern object that is instantiated by the following statement.

Additionpattern plus3 = new Additionpattern (2, 3);

Method Call Value Returned Explanation

(blank if no value)

Plus3.currentNumber(); 2 The current number is initially

the starting number in the

pattern.

plus3.next(); The pattern adds 3 each time, so

move to the next number in the

pattern.

plus3.currentNumber(); 5 The current number is 5.

plus3.next(); The pattern adds 3 each time, so

move to the next number in the

pattern(8).

plus3.next(); The pattern adds 3 each time, so

move to the next number in the

pattern(11).

plus3.currentNumber(); 11 The current number is 11.

plus3.prev(); Move to the previous number in

the pattern(8).

plus3.prev(); Move to the previous number in the

pattern(5).

plus3.prev(); Move to the previous number in the

pattern(2).

plus3.currentNumber(); 2 The current number is 2.

plus3.prev(); There is no previous number in the

pattern prior to 2, so no action is

taken.

plus3.currentNumber(); 2 The current number is 2.

Write the complete AdditionPattern class. Your implementation must meet all specifications and confirm to all examples.

ansver
Answers: 2

Another question on Computers and Technology

question
Computers and Technology, 21.06.2019 17:20
When developing a stakeholder matrix, the portfolio manager must look at the portfolio governance in order to complete the stakeholder analysis. in your own words, what is the role, interest and expectations of the governance?
Answers: 3
question
Computers and Technology, 22.06.2019 17:40
Write a modular program (no classes yet, just from what you learned last year), that allows two players to play a game of tic-tac-toe. use a two-dimensional char array with 3 rows and 3 columns as the game board. each element of the array should be initialized with an asterisk (*). the program should display the initial board configuration and then start a loop that does the following: allow player 1 to select a location on the board for an x by entering a row and column number. then redisplay the board with an x replacing the * in the chosen location. if there is no winner yet and the board is not yet full, allow player 2 to select a location on the board for an o by entering a row and column number. then redisplay the board with an o replacing the * in the chosen location. the loop should continue until a player has won or a tie has occurred, then display a message indicating who won, or reporting that a tie occurred. player 1 wins when there are three xs in a row, a column, or a diagonal on the game board. player 2 wins when there are three ox in a row, a column, or a diagonal on the game board. a tie occurs when all of the locations on the board are full, but there is no winner. input validation: only allow legal moves to be entered. the row must be 1, 2, or 3. the column must be 1, 2 3. the (row, column) position entered must currently be empty (i.e., still have an asterisk in it).
Answers: 1
question
Computers and Technology, 22.06.2019 22:30
Who needs to approve a change before it is initiated? (select two.) -change board -client or end user -ceo -personnel manager -project manager
Answers: 1
question
Computers and Technology, 22.06.2019 23:30
Which text format is this, "the text is transcribed exactly as it sounds and includes all the utterances of the speakers. "?
Answers: 2
You know the right answer?
Assume that the classes listed in the Java Quick Reference have been imported where appropriate. Unl...
Questions
question
Chemistry, 01.07.2020 15:01
Questions on the website: 13722360