Lab Assignment # 4 1
2
3
4
5
The first first player player enters enters a three three letter letter word. word. The second second player player shoul should d not see what what word word is entered. entered. Now Now the second player has three try’s 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 Define an abst abstrac ractt base base class class Shape Shape that incl include udess protec protected ted data data member memberss for the the (x, y) posit position ion of 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 Write a Java Java method method int int [] mix(i mix(int nt [ ] a, int int [] b) b) { ... } which which retu returns rns an an array array which which cont contain ainss all the 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 Write a program program to produc producee a histog histogram ram of data input input values. values. Assume Assume that that the the input input to the progr program am 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 Define a class class,, mcmleng mcmlength th,, to repres represent ent a lengt length h measure measured d in meters meters,, centim centimete eters, rs, 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 methods for weight conversion conversion and to calculate total weight. 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.