100% Original, Plagiarism Free, Tailored to your instructions

Order Now!

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.

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 Class
For 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.
******CARD IMAGE DOWNLOAD LINK: For accessing the in-class card images needed for the assignment: Link
Create 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 image
Create 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 following
Create space for the Image reference you created in the field by calling the constructor that takes the path to the image
Set the graphic on the Label you created in the field. Don’t forget you will need an ImageView
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:
Set the String you created in the field that holds the path to the String passed as an argument
Call the loadCard method passing it the path to the Image
Create 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 Card 
Inside 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 4
Step 3 Features
To 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 variable
to 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 – getCardValue
The 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.Spades
Once 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

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 Game
Currently 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. 

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 boolean rightsTurn = true;
private Label lblCardLeft = new Label();
private Label lblCardDeck = new Label();
private Label lblCardRight = new Label();
private TextField tfLeft = new TextField();
private TextField tfRight = new TextField();
private Button btnReset = new Button(“Reset”);
Random rnd = new Random();

private int rightVal = 0;
private int leftVal = 0;
private int score = 0;

public void start(Stage primaryStage) {

btnReset.setOnAction(new EventHandler() {
public void handle(ActionEvent event) {
rightVal = 0;
leftVal = 0;
score = 0;
rightsTurn = true; 
lblCardDeck.setOnMouseClicked(new EventHandler(){ 
public void handle(MouseEvent arg0) {

int max = 152;
int min = 101;
int val = (rnd.nextInt((max – min) + 1) + min);
String cardName = “file:img + val + “”.gif””;

Our Service Charter

  1. Excellent Quality / 100% Plagiarism-Free

    We employ a number of measures to ensure top quality essays. The papers go through a system of quality control prior to delivery. We run plagiarism checks on each paper to ensure that they will be 100% plagiarism-free. So, only clean copies hit customers’ emails. We also never resell the papers completed by our writers. So, once it is checked using a plagiarism checker, the paper will be unique. Speaking of the academic writing standards, we will stick to the assignment brief given by the customer and assign the perfect writer. By saying “the perfect writer” we mean the one having an academic degree in the customer’s study field and positive feedback from other customers.
  2. Free Revisions

    We keep the quality bar of all papers high. But in case you need some extra brilliance to the paper, here’s what to do. First of all, you can choose a top writer. It means that we will assign an expert with a degree in your subject. And secondly, you can rely on our editing services. Our editors will revise your papers, checking whether or not they comply with high standards of academic writing. In addition, editing entails adjusting content if it’s off the topic, adding more sources, refining the language style, and making sure the referencing style is followed.
  3. Confidentiality / 100% No Disclosure

    We make sure that clients’ personal data remains confidential and is not exploited for any purposes beyond those related to our services. We only ask you to provide us with the information that is required to produce the paper according to your writing needs. Please note that the payment info is protected as well. Feel free to refer to the support team for more information about our payment methods. The fact that you used our service is kept secret due to the advanced security standards. So, you can be sure that no one will find out that you got a paper from our writing service.
  4. Money Back Guarantee

    If the writer doesn’t address all the questions on your assignment brief or the delivered paper appears to be off the topic, you can ask for a refund. Or, if it is applicable, you can opt in for free revision within 14-30 days, depending on your paper’s length. The revision or refund request should be sent within 14 days after delivery. The customer gets 100% money-back in case they haven't downloaded the paper. All approved refunds will be returned to the customer’s credit card or Bonus Balance in a form of store credit. Take a note that we will send an extra compensation if the customers goes with a store credit.
  5. 24/7 Customer Support

    We have a support team working 24/7 ready to give your issue concerning the order their immediate attention. If you have any questions about the ordering process, communication with the writer, payment options, feel free to join live chat. Be sure to get a fast response. They can also give you the exact price quote, taking into account the timing, desired academic level of the paper, and the number of pages.

Excellent Quality
Zero Plagiarism
Expert Writers

Instant Quote

Single spaced
approx 275 words per page
Urgency (Less urgent, less costly):
Total Cost: NaN

Get 10% Off on your 1st order!