Assignment

IntroductionIn Assignment 4 you created a rudimentary war game. In this assignment we are going to use class construction to improve upon it a bit. You will create a Card class. The Card class will hold all of the information about an individual card. This means the cards value and suit.Additionally, we will create an enumerated type to relate the suit of the card.Step 1 – The Card ClassFor this first step you might want to create a new project called Assignment5 and then copy the code from Assignment4 into it. You don’t have to do this step but it is always a good plan to be able to roll back to a previous version. Once you have done this test your code and make sure it works like assignment 4.******CODE FOR ASSIGNMENT 4 IS PASTED AT BOTTOM OF THIS ASSIGNMENT***********CARD IMAGE DOWNLOAD LINK: For accessing the in-class card images needed for the assignment: .s3.amazonaws.com/account_54980000000000001/attachments/153099/img.zip?response-content-disposition=attachment%3B%20filename%3D%22img.zip%22%3B%20filename%2A%3DUTF-8%27%27img.zip&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAJFNFXH2V2O7RPCAA%2F20170220%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20170220T012616Z&X-Amz-Expires=86400&X-Amz-SignedHeaders=host&X-Amz-Signature=eefbbd70cf4caca49e0a6389ca90a95310f8ec896a3db024ff6223c89f696d54″>LinkCreate a class called Card. You will need to make sure you have imported Image, ImageView, and javafx.scene.control.*. In the field of the class you will need to create the following private variables:· A Label to hold the image· A reference to an Image to hold the card image and to place in the Label· An int to hold the value of the card· A String to hold the name of the path to the imageCreate a private boolean method called loadCard that takes as an argument a String that represents the full path to the Image. This method should do the following1. Create space for the Image reference you created in the field by calling the constructor that takes the path to the image2. Set the graphic on the Label you created in the field. Don’t forget you will need an ImageView3. For now simply have this method return true. In the future we will use this for potential error handling.Create a public void method called setImage that takes as an argument a String that represents the path to the image to load. This method should do the following:1. Set the String you created in the field that holds the path to the String passed as an argument2. Call the loadCard method passing it the path to the ImageCreate a public method called getCard that simply returns the Label that was created in the field.At this point you should have a card that can be tested.Step 2 – Test The CardInside the Assignment5.java (or whatever you called the main file) you should be able to create Cards and use them for the game. This involves the following:Replace the code that creates the image with a new Card. We haven’t created constructors yet so you will need two lines of code to replace:Image imgCardLeft = new Image(“file:img155.gif”);You will have to create a new Card and then call the setImage method to initialize the Card. You will then call the setGraphic method on the label this time you are going to supply it an image by calling the getCard method that is a member of the Card you just created.Please note that you will have to do this for all of the Labels you have created. Also note that this is not quite ideal but we have abstracted some of the details. We will get to the rest as we go.Once you have replaced all of the Labels with Cards you should test your game to make sure it still works the same as it did in assignment 4Step 3 FeaturesTo make the card complete we need to keep track of both the Suit and that Cards value. To begin with create a java file called Suit.java. Inside this file create an enumerated type called Suit. An enumerated type is a way to relate a numeric value to a name. Like the days of the week are numbered 1 to 7 and correspond to the values Monday – Sunday. The enumerated type should simply look like the following:public enum Suit{Diamonds, Hearts, Spades, Clubs}Inside the Card class create a private Suit variableto hold the suit of the Card. You might want to consider calling this variable suit.In addition create a private int variable to hold the value of the card. You might want to consider calling this variable value.Create a private method called getCardValue that takes as an argument a String that holds the path to the Card.Step 4 – getCardValueThe getCardValue method’s purpose is to determine the suit of the card, and it’s value. You are going to have to extract the number of the card from the path and convert it to a numeric type. Consider King, Queen, and Jack to be worth 10 and the Ace worth 11.Using the numeric value of the card determine the actual value the card has. I will leave it to you to design an algorithm to do this but please do not have a switch statement that contains 52 cases. You should try to work out an algorithm that mathematically determines the value. You will undoubtedly need to use decisions but try to write the code as concise as possible.In addition to this you need to determine the the suit of the card. You should set the value and suit created in the field from this method. The suit would be something like this:this.suit = Suit.SpadesOnce you have this method finished create a public accessor method called getValue that simply returns the value of the Card. Also, create an accessor method called getSuit that will return the suit of the card. In order for this to work when a Card is created you are also going to want to call this method from the loadCard method.At this point you should have a working Card class that will keep track of the suit and the value. It is not ideal at this point but is getting better. The last thing to do is to update the game so that it uses the value of the card instead of the name of the card.Step 5 – Modifying The GameCurrently the game keeps score by adding one to the side that has the higher value card. This value is simply determined by the name of the card. We have just created a method that will return the Card’s value so we want to use this method to determine which side wins. You are going to have to modify the decisions inside the handle method of the mouse clicked event.We also want to change the score. Instead of adding one to the side with the higher value we now want to add the value of the card to the score. This means if the Card value is 10 the score will go up by 10.At this point your game should work with the Card Class. It should also have updated scoring.ASSIGNMENT 4 CODE:package lab4solution;import javafx.application.Application;import javafx.event.ActionEvent;import javafx.event.EventHandler;import javafx.event.EventType;import javafx.geometry.HPos;import javafx.geometry.Pos;import javafx.scene.Scene;import javafx.scene.control.*;import javafx.scene.image.Image;import javafx.scene.image.ImageView;import javafx.scene.input.MouseEvent;import javafx.scene.layout.*;import javafx.stage.Stage;import java.util.Random;import javafx.scene.paint.Color;import javafx.scene.text.Font;import javafx.scene.text.FontWeight;public class Lab4Solution extends Application {private booleanrightsTurn = true;private Label lblCardLeft = new Label();private Label lblCardDeck = new Label();private Label lblCardRight = new Label();private TextFieldtfLeft = new TextField();private TextFieldtfRight = new TextField();private Button btnReset = new Button(“Reset”);Random rnd = new Random();private intrightVal = 0;private intleftVal = 0;private int score = 0;@Overridepublic void start(Stage primaryStage) {btnReset.setOnAction(new EventHandler() {@Overridepublic void handle(ActionEvent event) {rightVal = 0;leftVal = 0;score = 0;tfRight.setText(“0”);tfLeft.setText(“0”);resetCardImages();rightsTurn = true; }});lblCardDeck.setOnMouseClicked(new EventHandler(){ @Overridepublic void handle(MouseEvent arg0) {int max = 152;int min = 101;intval = (rnd.nextInt((max – min) + 1) + min);String cardName = “file:img” + val + “.gif”;if(rightsTurn == true){rightVal = val;Image imgCardRight = new Image(cardName);lblCardRight.setGraphic(new ImageView(imgCardRight));}else{leftVal = val;Image imgCardLeft = new Image(cardName);lblCardLeft.setGraphic(new ImageView(imgCardLeft));if(rightVal>leftVal){score = Integer.parseInt(tfRight.getText());score++; tfRight.setText(“” + score);}else if(leftVal>rightVal){score = Integer.parseInt(tfLeft.getText());score++; tfLeft.setText(“” + score);} }rightsTurn = !rightsTurn;}});tfLeft.setPrefWidth(50);tfRight.setPrefWidth(50);tfLeft.setDisable(true);tfRight.setDisable(true);tfLeft.setText(“0”);tfRight.setText(“0”);this.resetCardImages();BorderPane root = new BorderPane();GridPanecardPane = new GridPane();cardPane.setHgap(20.0);cardPane.add(lblCardLeft, 0, 0);cardPane.add(lblCardDeck, 1, 0);cardPane.add(lblCardRight, 2, 0);cardPane.setAlignment(Pos.CENTER);GridPanetopPane = new GridPane();topPane.setHgap(20.0);topPane.setVgap(10.0);Label lblScore = new Label(“Score:”);Font fntScore = Font.font(“Verdana”, FontWeight.BOLD, 14.0);lblScore.setFont(fntScore);lblScore.setTextFill(Color.RED);topPane.add(lblScore, 0, 0);topPane.add(new Label(“Left: “), 0, 1);topPane.add(tfLeft, 1, 1);topPane.add(new Label(“Right: “), 2, 1);topPane.add(tfRight, 3, 1); root.setTop(topPane);root.setCenter(cardPane);root.setBottom(btnReset);Scene scene = new Scene(root, 400, 300);primaryStage.setTitle(“Assignment 4 – Simple Game of War”);primaryStage.setScene(scene);primaryStage.show();}private void resetCardImages(){Image imgCardLeft = new Image(“file:img155.gif”);Image imgCardRight = new Image(“file:img155.gif”);Image imgCardDeck = new Image(“file:img155.gif”);lblCardLeft.setGraphic(new ImageView(imgCardLeft));lblCardDeck.setGraphic(new ImageView(imgCardDeck));lblCardRight.setGraphic(new ImageView(imgCardRight));}public static void main(String[] args) {launch(args);

Save Time On Research and Writing
Hire a Pro to Write You a 100% Plagiarism-Free Paper.
Get My Paper
Calculate the price
Make an order in advance and get the best price
Pages (550 words)
$0.00
*Price with a welcome 15% discount applied.
Pro tip: If you want to save more money and pay the lowest price, you need to set a more extended deadline.
We know how difficult it is to be a student these days. That's why our prices are one of the most affordable on the market, and there are no hidden fees.

Instead, we offer bonuses, discounts, and free services to make your experience outstanding.
How it works
Receive a 100% original paper that will pass Turnitin from a top essay writing service
step 1
Upload your instructions
Fill out the order form and provide paper details. You can even attach screenshots or add additional instructions later. If something is not clear or missing, the writer will contact you for clarification.
Pro service tips
How to get the most out of your experience with Essay Fountain
One writer throughout the entire course
If you like the writer, you can hire them again. Just copy & paste their ID on the order form ("Preferred Writer's ID" field). This way, your vocabulary will be uniform, and the writer will be aware of your needs.
The same paper from different writers
You can order essay or any other work from two different writers to choose the best one or give another version to a friend. This can be done through the add-on "Same paper from another writer."
Copy of sources used by the writer
Our college essay writers work with ScienceDirect and other databases. They can send you articles or materials used in PDF or through screenshots. Just tick the "Copy of sources" field on the order form.
Testimonials
See why 20k+ students have chosen us as their sole writing assistance provider
Check out the latest reviews and opinions submitted by real customers worldwide and make an informed decision.
Sociology
Thank you
Customer 452919, September 2nd, 2024
Sociology
Thank you for following the guidelines of the discussion essay. We are off to a great start.
Customer 452919, March 20th, 2024
Political science
Great paper
Customer 452863, September 11th, 2021
Logistics
The presentation slides were not narrated as asked per the instructions.
Customer 452623, September 28th, 2021
Nutrition, Hospitality & Human Services
Thank you for your assistance.
Customer 452919, April 13th, 2024
Sociology
Thank you!
Customer 452919, April 5th, 2022
Humanities
Best Serivces
Customer 452995, January 24th, 2022
Business Studies
This is fantastic! Thank you so much! Great customer service and help!
Customer 453131, November 15th, 2022
Nursing
misunderstanding paper was late
Customer 452695, April 2nd, 2021
Economics
Satisfactory
Customer 452963, November 11th, 2021
Nursing
Very good service
Customer 453075, April 27th, 2022
Education
Thank you so much!!! Will use this service again highly recommend this site!!!
Customer 452739, May 2nd, 2021
11,595
Customer reviews in total
96%
Current satisfaction rate
3 pages
Average paper length
37%
Customers referred by a friend
OUR GIFT TO YOU
15% OFF your first order
Use a coupon FIRST15 and enjoy expert help with any task at the most affordable price.
Claim my 15% OFF Order in Chat