Java程序辅导

C C++ Java Python Processing编程在线培训 程序编写 软件开发 视频讲解

客服在线QQ:2653320439 微信:ittutor Email:itutor@qq.com
wx: cjtutor
QQ: 2653320439

The self-test quiz for week 10 is here.

These exercises are taken from Chapter 5 of the text book. You should also use this week to catch up with previous labs.

Exercise 5.14 Write some code (in BlueJ) to test the generation of random numbers. To do this, create a new class called RandomTester. You can create this class in a new project. In class RandomTester, implement two methods: printOneRandom (which prints out one random number) and printMultiRandom(int howMany) (which has a parameter to specify how many numbers you want, and then prints out the appropriate number of random numbers).

Exercise 5.15 Find the nextInt method in class Random that allows the target range of random numbers to be specified. What are the possible random numbers that are generated when you call this method with 100 as its parameter?

Exercise 5.16 Write a method in your RandomTester class called throwDice that returns a random number between 1 and 6 (inclusive).

Exercise 5.17 Write a method called getResponse that randomly returns one if the strings “yes”, “no”, or “maybe”.

Exercise 5.18 Extend your getResponse method so that it uses an ArrayList to store an arbitrary number of responses and randomly returns one of them. to Store

Exercise 5.19 Add a method to your RandomTester class that takes a parameter max and generates a random number in the range 1 to max (inclusive).

Exercise 5.20 Add a method to your RandomTester class that takes two parameters, min and max, and generates a random number in the range min to max (inclusive). Rewrite the body of the method you wrote for the previous exercise so that it now calls this new method to generate its result. Note that it should not be necessary to use a loop in this method.

 

No Comments so far ↓

There are no comments yet...Kick things off by filling out the form below.

You must to post a comment.