Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This is a review exereise, so the primary goal of the exercise is to eet your mind working and in the correct space. in this

image text in transcribed
image text in transcribed
This is a review exereise, so the primary goal of the exercise is to eet your mind working and in the correct space. in this activity you will create an object that models a card from a mpothetical 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 tulue 5100 . You will then create an anry of these values and tert shem out. Using Java, create the following classes and primary program that saes the classes that you developed. INSTAUETIOWS Create the following classes. CARO CLASS Create a Card class. Fach card will have three inseger values (iR. P4 and 5) within the boundaries set above, and a title which is a string. You will need to create the following methods. * A detaull constructor that picki fandom numbers [3. 100] for R,, P, S and gives the card a random name of "Ca:h s P????, where the question marks a number between 10000 and 99900 . For example "Card 345624" or "Cand 212352 ". - A constructor that allows the user to start with a given name. = In this case, the constructor should eive the Card tandom R, P., valuen, but one the ghen name. - A parameter constructoe that allows the progammer to input all 4 pieces of intoemation. (it,, , 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. - L.e, don't let the Ros values be outside the vatues - getali - getif) - gets() - gethane() - getcosti) 7. This method should find and return the integer "cost" of the card. 4. The cost of the card wili be a value between 1 and 200 . n. The formula for finding the cost of a card is given below: kernet wheve 2 ty - Note the absolute value symbols in there. a Y=X - x is the fioor finction - Cost =200Y - tostring(? a This should print out the name of the card, and the hiss values; and the cost of the card in the format below: - fxample 1 - Card una3s 7[2,5,7;129] = Example 2 - Purple knight [55,56,1:93] - pickvalue() This method should return a single character: an +R " ar " S of " 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+5 and then ghe each value an appropriate random value based upon the total and pick at random. a EXAMPLE: EXAMPPLF - With A card with APS values of Rx5, Proto, 5050 - The total is 50+10+5=65 - Se there is a 5/65 chance of pickine an 8 - So there is a 10065 chance of picking a P. - So there is a sofbs chance of pickine an 5 MaIN CUASS Invide your main class do the following - Create an array that can hold 10 cards. of fill the array with 5 cards with names and values of your choice. - Not the user's choise, your choice as the progammer. Q. fill the array with 3 named cards but with random values. Finish filing the array with fwo defacult cards. - Print off all the cards in the array. - Print In - Then do the following loop. D. Pick two cards at random. * Note, they might be the same card. D Pick a Value [ "R", " P ", "5"] for card 1. o Pick a Value ['Il'. 'P', " S ] for card? o Determine who wins or it there is a tie: - Remember in beat 5 - S beats P - Pbeats R - Andit is a tie if they are the same. Print out the result like the following * Roand 4 Pown Tue beats blise kilfil 5 wh b - D\$ * Round 5 Card =15567 tien lhite fook 5 vs 5 . - Repeat the loop above until there are at least 10 ties. - Print - Print out the total number of rounds. atront sunmission before submitting your asignment, make sure your program is torrectly lava Dotamented and is listed as your name as the author, This is a review exereise, so the primary goal of the exercise is to eet your mind working and in the correct space. in this activity you will create an object that models a card from a mpothetical 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 tulue 5100 . You will then create an anry of these values and tert shem out. Using Java, create the following classes and primary program that saes the classes that you developed. INSTAUETIOWS Create the following classes. CARO CLASS Create a Card class. Fach card will have three inseger values (iR. P4 and 5) within the boundaries set above, and a title which is a string. You will need to create the following methods. * A detaull constructor that picki fandom numbers [3. 100] for R,, P, S and gives the card a random name of "Ca:h s P????, where the question marks a number between 10000 and 99900 . For example "Card 345624" or "Cand 212352 ". - A constructor that allows the user to start with a given name. = In this case, the constructor should eive the Card tandom R, P., valuen, but one the ghen name. - A parameter constructoe that allows the progammer to input all 4 pieces of intoemation. (it,, , 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. - L.e, don't let the Ros values be outside the vatues - getali - getif) - gets() - gethane() - getcosti) 7. This method should find and return the integer "cost" of the card. 4. The cost of the card wili be a value between 1 and 200 . n. The formula for finding the cost of a card is given below: kernet wheve 2 ty - Note the absolute value symbols in there. a Y=X - x is the fioor finction - Cost =200Y - tostring(? a This should print out the name of the card, and the hiss values; and the cost of the card in the format below: - fxample 1 - Card una3s 7[2,5,7;129] = Example 2 - Purple knight [55,56,1:93] - pickvalue() This method should return a single character: an +R " ar " S of " 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+5 and then ghe each value an appropriate random value based upon the total and pick at random. a EXAMPLE: EXAMPPLF - With A card with APS values of Rx5, Proto, 5050 - The total is 50+10+5=65 - Se there is a 5/65 chance of pickine an 8 - So there is a 10065 chance of picking a P. - So there is a sofbs chance of pickine an 5 MaIN CUASS Invide your main class do the following - Create an array that can hold 10 cards. of fill the array with 5 cards with names and values of your choice. - Not the user's choise, your choice as the progammer. Q. fill the array with 3 named cards but with random values. Finish filing the array with fwo defacult cards. - Print off all the cards in the array. - Print In - Then do the following loop. D. Pick two cards at random. * Note, they might be the same card. D Pick a Value [ "R", " P ", "5"] for card 1. o Pick a Value ['Il'. 'P', " S ] for card? o Determine who wins or it there is a tie: - Remember in beat 5 - S beats P - Pbeats R - Andit is a tie if they are the same. Print out the result like the following * Roand 4 Pown Tue beats blise kilfil 5 wh b - D\$ * Round 5 Card =15567 tien lhite fook 5 vs 5 . - Repeat the loop above until there are at least 10 ties. - Print - Print out the total number of rounds. atront sunmission before submitting your asignment, make sure your program is torrectly lava Dotamented and is listed as your name as the author

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_2

Step: 3

blur-text-image_3

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

The Structure Of The Relational Database Model

Authors: Jan Paredaens ,Paul De Bra ,Marc Gyssens ,Dirk Van Gucht

1st Edition

3642699588, 978-3642699580

More Books

Students also viewed these Databases questions

Question

Challenges Facing Todays Organizations?

Answered: 1 week ago