Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

answer in java programming language 7. Classes (Hint: refer to the program on the back page and questions 8 to 10) This is a long

answer in java programming language
image text in transcribed
image text in transcribed
7. Classes (Hint: refer to the program on the back page and questions 8 to 10) This is a long description, but the problem isn't hard. You're building a game in which the players each set the goal they must meet to win. As players move through the game, they must collect 10 objects from three categories: purple, green, and navy. Before the game begins, each player records how many objects they must collect in each category to win the game. The total of objects a player must collect must total to 10, and no category may have a negative number. For example, Sandy might choose to try to get 4 purple, 2 green, and 4 navy, while Terry might choose 0 purple, 7 green, and 3 navy. Your task is to build a class to support goal setting and recording. The Goal class has six integer instance variables to record the targets in each category (use PT, gt, and nT for the targets) and the number of objects accumulated in each category (p, g, and n). The constructor will take in the three target values for the categories as its parameters (PTO, GTO, and nTO). It will also initialize the accumulated objects counters in each category. Throw an IllegalArgumentException if the targets are not each at least zero or don't sum to ten. The class also has methods that update the accumulated object counts. For the test, we'll have only addPurple which adds 1 to the purple count (p). The class also has a boolean hasReachedGoal method that returns true if the goal has been reached and false otherwise. The goal is reached only when all of the targets have been met (they may be exceeded). Write the Goal class including the constructor, the two methods described above (addPurple and hasReachedGoal), and the six instance variables (PT, gt, and nT and p, , and n). // Game.java // Record.java IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII public class Record { private int wins; private int losses; private int ties; private int games; public class Game public static void main(String[] args) { Record papers = new Record(); Record scissors = new Record(); papers.addGame(4, 3); scissors.addGame(0, 4); print("Papers", papers); print("Scissors", scissors); papers.addGame(5, 7); scissors.addGame(4, 6); scissors.addGame(9, 1); papers.addGame(3, 7); scissors.addGame(7,3); papers.addGame(0,5); papers.addGame(1, 4); scissors.addGame(3, 1); print("Papers", papers); print("Scissors", scissors); public Record() { wins = 0; losses = 0; ties = 0; games = 0; public void addGame (int us, int them) { if (us > them) { wins++; } else if (us 0) { return (wins *100)/games; } else { throw new ArithmeticException ("divide by zero")

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Support For Data Mining Applications Discovering Knowledge With Inductive Queries Lnai 2682

Authors: Rosa Meo ,Pier L. Lanzi ,Mika Klemettinen

2004th Edition

3540224793, 978-3540224792

More Books

Students also viewed these Databases questions

Question

Make effective use of recognition to motivate others.

Answered: 1 week ago

Question

The CPU control unit is responsible for

Answered: 1 week ago