Sunteți pe pagina 1din 1

Lab Assignment # 4

1 The first player enters a three letter word. The second player should not see what word is entered. Now the second player has three trys to guess the word. If the second player does not guess the word, the first player wins. The game consists of a ten rounds. After the 10 rounds, the program prints out how many of the 10 rounds were won and how many were lost. Player who wins 7 or fewer rounds is rated as amateurs. Player who wins 8 rounds is rated as advanced. Player who wins 9 rounds is rated as professionals. Player who wins all 10 rounds is rated as hackers. Define an abstract base class Shape that includes protected data members for the (x, y) position of a shape, a public method to move a shape, and a public abstract method show() to output a shape. Derive subclasses for lines, circles and rectangles. You can represent: a line as two points a circle as a center and radius and a rectangle as two points on diagonally opposite corners. Test the classes by selecting ten random objects of the derived classes, then invoking the show() method for each. Define a class Shapelist that can store an arbitrary collection of any objects of subclasses of the shape class. Implement the classes for shapes using an interface for common methods, rather than inheritance from the superclass, while still keeping Shape as a base class. Write a Java method int [] mix(int [ ] a, int [] b) { ... } which returns an array which contains all the elements of a and all the elements of b, and mixed together in the following way. First take an element from a, then an element from b, and continue in this manner, alternating with elements from a and b. If you run out of elements in one of the arrays, then simply copy the remaining elements from the other array. For example: a = (1 2 3 5 6 7) b = (11 12 13) mix(a, b) = (1 11 2 12 3 13 5 6 7) a = (1 2 3) b = (11 12 13 15 16 17) mix(a, b) = (1 11 2 12 3 13 15 16 17) Write a program to produce a histogram of data input values. Assume that the input to the program is a long list of numbers between 0 and 100 inclusive. Your program should count the number of values that are in the range 0-9, 10-19,.., 90-100, and then output a series of lines of * characters, with the length of the line corresponding to the number of values in that range. For example, if the input data was 27, 15, 34, 22, 11, 11, 19 (each on its own line, of course) then the output would be **** ** * Define a class, mcmlength, to represent a length measured in meters, centimeters, and millimeters, each stored as integers. Include methods for length conversion and calculate area. Define another class, tkgweight, to represent a weight in tons, Kilograms, and grams, and include methods for weight conversion and to calculate total weight. Put both the previous classes in a package called measures. Import this package into a program that will calculate and display the total weight of the following: 1) 200 carpets - size: 4 meters by 2 meters 9 centimeters, that weight 1.25 kilograms per square meter 2) 60 carpets- size: 3 meters 57 centimeters, that weight 1.05 kilograms per square meter.

S-ar putea să vă placă și