Answered step by step
Verified Expert Solution
Question
1 Approved Answer
This is a review exercise, so the primary goal of the exercise is to get your mind working and in the correct space. In this
This is a review exercise, so the primary goal of the exercise is to get your mind working and in the correct space. In this activity you will create an object that models a card from a hypothetical card game. This Card class will model a card with three attributes labeled R,P and S, where each of these values are within a range of 1R,P,S value 100. You will then create an array of these values and test them out. Using Java, create the following classes and primary program that uses the classes that you developed. INSTRUCTIONS Create the following classes. CARD CLASS Create a Card class. Each card will have three integer values (R,P, and S) within the boundaries set above, and a title which is a string. You will need to create the following methods. - A default constructor that picks random numbers [1,100] for R, P,S and gives the card a random name of "CARD \#?????", where the question marks a number between 10000 and 99999 . For example "Card \#45624" or "Card \#12352". - A constructor that allows the user to start with a given name. - In this case, the constructor should give the Card random R, P,S values, but use the given name. - A parameter constructor that allows the programmer to input all 4 pieces of information. (R, P,S, name) - Check the parameters for valid input based on the constraints. If any of the input values is invalid, that particular value should be set to 1 . - i.e. don't let the RPS values be outside the values - getr() - getP () - getO(l - getName() - getCost() - This method should find and return the integer "cost" of the card. - The cost of the card will be a value between 1 and 200 . - The formula for finding the cost of a card is given below: Revised: Winter 2023 Version 2.0 - X=100(R+P+sRP+R+P+sRS+R+P+sSP) - Note the absolute value symbols in there. - Y=X - x is the floor function - Cost =200Y - tostring() - This should print out the name of the card, and the RPS values, and the cost of the card in the format below: - Example 1 - Card \#23987 [2,5,7:129] - Example 2 - Purple Knight [55,66,1:93] - pickValue() - This method should return a single character: an ' R or ' S or P. - The character returned should be chosen at random based upon the values inside the card. - What you should do is find the total value of R+P+S and then give each value an appropriate random value based upon the total and pick at random. - EXAMPLE: Inside your main class do the following - Create an array that can hold 10 cards. - Fill the array with 5 cards with names and values of your choice. - Not the user's choice, your choice as the programmer. - Fill the array with 3 named cards but with random values. - Finish filling the array with two default cards. - Print off all the cards in the array. - Print \#- - Then do the following loop. - Pick two cards at random. - Note, they might be the same card. Revised. Winter 2023 Versian 4 - Pick a Value ['R', 'P', 'S'] for card 1. - Pick a Value ['R', 'P', ' 'S' ] for card 2 - Determine who wins or if there is a tie: - Remember R beat S - S beats P - P beats R - And it is a tie if they are the same. - Print out the result like the following - Round 4 Pawn Two beats Blue King S v5 P - OR " Round 5 Card \#18567 ties White Rook S v5 S. - Repeat the loop above until there are at least 10 ties. - Print \#- - Print out the total number of rounds. This is a review exercise, so the primary goal of the exercise is to get your mind working and in the correct space. In this activity you will create an object that models a card from a hypothetical card game. This Card class will model a card with three attributes labeled R,P and S, where each of these values are within a range of 1R,P,S value 100. You will then create an array of these values and test them out. Using Java, create the following classes and primary program that uses the classes that you developed. INSTRUCTIONS Create the following classes. CARD CLASS Create a Card class. Each card will have three integer values (R,P, and S) within the boundaries set above, and a title which is a string. You will need to create the following methods. - A default constructor that picks random numbers [1,100] for R, P,S and gives the card a random name of "CARD \#?????", where the question marks a number between 10000 and 99999 . For example "Card \#45624" or "Card \#12352". - A constructor that allows the user to start with a given name. - In this case, the constructor should give the Card random R, P,S values, but use the given name. - A parameter constructor that allows the programmer to input all 4 pieces of information. (R, P,S, name) - Check the parameters for valid input based on the constraints. If any of the input values is invalid, that particular value should be set to 1 . - i.e. don't let the RPS values be outside the values - getr() - getP () - getO(l - getName() - getCost() - This method should find and return the integer "cost" of the card. - The cost of the card will be a value between 1 and 200 . - The formula for finding the cost of a card is given below: Revised: Winter 2023 Version 2.0 - X=100(R+P+sRP+R+P+sRS+R+P+sSP) - Note the absolute value symbols in there. - Y=X - x is the floor function - Cost =200Y - tostring() - This should print out the name of the card, and the RPS values, and the cost of the card in the format below: - Example 1 - Card \#23987 [2,5,7:129] - Example 2 - Purple Knight [55,66,1:93] - pickValue() - This method should return a single character: an ' R or ' S or P. - The character returned should be chosen at random based upon the values inside the card. - What you should do is find the total value of R+P+S and then give each value an appropriate random value based upon the total and pick at random. - EXAMPLE: Inside your main class do the following - Create an array that can hold 10 cards. - Fill the array with 5 cards with names and values of your choice. - Not the user's choice, your choice as the programmer. - Fill the array with 3 named cards but with random values. - Finish filling the array with two default cards. - Print off all the cards in the array. - Print \#- - Then do the following loop. - Pick two cards at random. - Note, they might be the same card. Revised. Winter 2023 Versian 4 - Pick a Value ['R', 'P', 'S'] for card 1. - Pick a Value ['R', 'P', ' 'S' ] for card 2 - Determine who wins or if there is a tie: - Remember R beat S - S beats P - P beats R - And it is a tie if they are the same. - Print out the result like the following - Round 4 Pawn Two beats Blue King S v5 P - OR " Round 5 Card \#18567 ties White Rook S v5 S. - Repeat the loop above until there are at least 10 ties. - Print \#- - Print out the total number of rounds
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started