I am trying to manipulate objects in Java. To better explain, I have a superclass that is a called Creature and two subclasses called (Dragon and Warrior). I created two objects one for each the dragon and the warrior to fight each other. How can I set an attack method that does damage from one object and use that number to subtract it from the health of the second object.
please note that warrior and dragon are both subclasses.
public class Creature {
private int health = 50;
private int attack;
private int level = 1;
private String name;
private Creature random;
private Creature random2;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getHealth() {
if(health >= 3000)
{
health = 3000;
}
if(health <= 0)
{
health = 0;
}
return health;
}
public void setHealth(int health) {
this.health = health < 0 ? 0 : health;
}
public int getAttack() {
Random generator = new Random();
attack = generator.nextInt(10) * level + 1;
return attack;
}
public void setAttack(int attack) {
this.attack = attack;
}
public int getLevel() {
if(level >= 60)
{
level = 60;
}
return level;
}
public void setLevel(int level){
this.level = level;
}
public boolean isAlive() {
if(getHealth() <= 0)
{
return false;
}
return true;
}
public String getWelcome()
{
String welcome = "Hello and welcome to Dragonslayer!";
return welcome;
}
public String getStab()
{
String stab = "You choose to stab the dragon and dealt " + getAttack() + " damage. The dragon now has " + getHealth() + " health remaining.";
return stab;
}
public String getSlash()
{
String slash = "You choose to slash the dragon and dealt " + getAttack() + " damage. The dragon now has " + getHealth() + " health remaining.";
return slash;
}
public String getCut()
{
String cut = "You choose to cut the dragon and dealt " + getAttack() + " damage. The dragon now has " + getHealth() + " health remaining.";
return cut;
}
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
System.out.print("You come across the dragon and you have two options. Do you run or fight? ");
Creature kirsta = new Dragon();
kirsta.setHealth(50);
Creature brenton = new Warrior();
brenton.setHealth(50);
while(in.hasNextLine())
{
switch(in.nextLine())
{
case "run":
System.out.println("I am so sorry, you could not outrun the dragon, you have been killed!");
break;
case "fight":
while(kirsta.isAlive() && brenton.isAlive())
{
System.out.println("Do you want to stab, slash, or cut the dragon? ");
switch(in.nextLine())
{
case "stab":
System.out.println("You choose to stab the dragon and dealt " + brenton.getAttack() + " damage. The dragon now has " + kirsta.getHealth() + " health remaining.");
break;
case "slash":
System.out.println("You choose to slash the dragon and dealt " + brenton.getAttack() + " damage. The dragon now has " + kirsta.getHealth() + " health remaining.");
break;
case "cut":
System.out.println("You choose to cut the dragon and dealt " + brenton.getAttack() + " damage. The dragon now has " + kirsta.getHealth() + " health remaining.");
break;
default:
System.out.println("I am sorry that is not valid, try again. ");
}
}
break;
default:
System.out.println("I am sorry that is not a valid choice. ");
break;
}//end of switch
if(brenton.isAlive() == false && kirsta.isAlive() == false)
{
System.out.println("It is a horrid day today, as both you and the dragon have fallen.");
}
else if(brenton.isAlive() == true && kirsta.isAlive() == false)
{
System.out.println("Congratulations you have killed the dragon, and survived!");
}
else if(brenton.isAlive() == false && kirsta.isAlive() == true)
{
System.out.println("You have sadly fallen to the dragon, better luck next time.");
}
else
{
System.out.println("SOMETHING WENT WRONG!!!");
}
break;
}//end of while loop in.hasNextLine().
}//end of main
}//end of class
Assuming that your attack method has form similar to this
public void attack(Creature otherCreature){
otherCreature.decreaseHitPointsBy(this.attackValue);
}
Usage would look like
warrior.attack(dragon);
For example you can create two classess that extends creature and then create instances of them using new operator. They can interract by passing refference to other object as argument of attack method:
class Creature {
protected int health = 100;
protected int strength = 10;
public void attack(Creature other) {
other.takeDamage(strength);
}
public void takeDamage(int amount) {
health -= amount;
}
}
class Warrior extends Creature {
protected int strength = 2;
//method specific to warrior
public void eatPotion() {
health = 100;
}
}
class Dragon extends Creature {
//You can simply override values in subclasses
protected int strength = 20;
protected int health = 1000;
}
Dragon dragon = new Dragon();
Warrior warrior = new Warrior();
warrior.attack(dragon);
dragon.attack(warrior);
warrior.eatPotion();
warrior.attack(dragon);
Related
So the output for the warrior's level is not increasing as their experience go up. Warrior 1 starting level is 20 and warrior 2 is 18. I'm trying to increase each warrior's level by printing it out on Game.java file. I tried to increment the expLevel and then experience but it shows an error. What is the best way to increase each of the warrior's level?
public class Game {
public static void main(String[] args) {
// Part 3 of ICE16 then ICE17 edition
// List of weapons
Weapon mean = new Weapon("Mean Words", 1, "Mean words cause very little damage", 4);
Weapon bat = new Weapon("Baseball Bat", 10, "Some properties get destroyed", 4);
Weapon gun = new Weapon("Handgun", 100, "Stronger than a baseball bat", 4);
Weapon bazooka = new Weapon("Bazooka", 200, "Major destruction", 4);
Weapon laChancla = new Weapon("La Chancla", 4000, "Total annihilation", 4);
// Warriors
Warrior w1 = new Warrior(28, "Skeletor", 20, mean);
Warrior w2 = new Warrior(19, "Striker", 18, bat);
// Changes
for (int i = 0; i < 4; i++) {
w1.attack();
w2.attack();
}
w1.attack();
w1.assignWeapon(bazooka);
w2.attack();
w2.assignWeapon(laChancla);
w1.attack();
System.out.println(w1.getExpLevel());
System.out.println(w2.getExpLevel());
}
}
Here is a warrior class:
public class Warrior {
// Part 2 of ICE16 then ICE17 edition
// 4 properties: int age, String name, int expLevel, Weapon weapon
private int age;
private String name;
private int expLevel;
private Weapon weapon;
private int experience = 0;
// Create a constructor that assigns each value to the property
public Warrior(int age, String name, int expLevel, Weapon weapon) {
this.age = age;
this.name = name;
this.expLevel = expLevel;
this.weapon = weapon;
}
// Method 1
public void attack() {
System.out.println("Warrior, " + name + " with experience level " + expLevel + " attacks!");
// Call the strike method from the weapon class
this.weapon.strike();
if (weapon.strike()) {
experience++;
}
if (experience >= 4) {
expLevel++;
} else {
System.out.println("The warrior cannot attack");
}
}
// Method 2
public void assignWeapon(Weapon weapon) {
this.weapon = weapon;
System.out.println(this.name + " now has " + weapon.getType());
}
public int getExpLevel() {
return expLevel;
}
}
Here is a weapon class:
public class Weapon {
// Part 1 of ICE16 then ICE17 edition
// 3 properties: String type, int power, and String strikeMessage
private String type;
private int power;
private String strikeMessage;
private int health = 4;
// In class Weapon, create a constructor that assigns values to each of these internal private properties of the class in the order above.
public Weapon (String type, int power, String strikeMessage, int health) {
this.type = type;
this.power = power;
this.strikeMessage = strikeMessage;
this.health = health;
}
// Method 1
public int getPower() {
return power;
}
// Method 2
public boolean strike() {
System.out.println("Weapon of type " + type + " has power " + power);
System.out.println(strikeMessage);
if (health < 0) {
System.out.println("Weapon " + this.type + " cannot strike because it's damaged");
return true;
} else {
health--;
return false;
}
}
// Method 3
public void setPower(int power) {
this.power = power;
}
// Weapon's Health Level
public String getType() {
return type;
}
}
Your code to increase explevel is within an if statement that will only increase the explevel if the explevel is already 4 or greater.
This means that all Warrior instances with a level of 3 or lower can never increase their level (until you change this code).
I'm stuck on this one exercise where I should create a second class called Car, that is linked to Vehicle. This is how it should look:
The vehicle class along with the testprogram works great, but now I want to connect the class Car to the vehicle, and then create a testclass for car. This is my vehicle class:
public class Vehicle {
int speed;
// Constructor
public Vehicle() {
this.speed = 0;
}
public class Car extends Vehicle {
String regnr;
public Car(String regnr) {
this.regnr = regnr;
}
public String getRegNbr() {
return this.regnr;
}
}
public void increaseSpeed(int differenceInc) {
int currentSpeed = this.speed;
// Kör loopen så länge den nuvarande hastigheten inte är lika med den önskade
while (this.speed != (currentSpeed + differenceInc)) {
this.speed += 1;
System.out.println("The current speed is increasing to: " + this.speed);
}
}
public void decreaseSpeed(int differenceDec) {
int currentSpeed = this.speed;
while (this.speed != (currentSpeed - differenceDec)) {
this.speed -= 1;
System.out.println("The current speed is decreasing to: " + this.speed);
}
}
public void brake() {
int currentSpeed = this.speed;
while (this.speed != 0) {
this.speed /= 2;
System.out.println("The current speed is decreasing to: " + this.speed);
}
}
public int getSpeed() {
return this.speed;
}
public void testVehicle() {
Scanner myScanner = new Scanner(System.in);
while (this.speed != 0) {
System.out.println("You're driving at: " + " " + this.speed + "KM/H" + "\n\nDo you want to:"
+ "\n(1) Slow down to " + "lower speed??" + "\n(2) Maintain current speed?"
+ "\n(3) Hit the brakes?" + "\n(4) Accelerate even more?");
int choice = myScanner.nextInt();
if (choice == 1) {
System.out.print("By how much would you like to decrease your speed? ");
Scanner in = new Scanner(System.in);
int dec = in.nextInt();
this.decreaseSpeed(dec);
} else if (choice == 2) {
System.out.println("Maintaining current speed");
} else if (choice == 3) {
System.out.println("Breaking!");
this.brake();
}
else if (choice == 4) {
System.out.print("By how much would you like to increase your speed? (km/h)");
Scanner in = new Scanner(System.in);
int inc = in.nextInt();
this.increaseSpeed(inc);
}
else {
System.err.println("Incorrect value entererd.");
System.exit(0);
}
}
if (this.getSpeed() == 0)
{
System.out.println("Bilen står still");
}
}
}
As you can see, the testVehicle() class along with a small separate test-program called VehicleTest runs the Vehicle class I created. I've added the Car-class to the program, and it extends vehicle as it should. The only question I have is how do I implement it into the test class?
My current separate test-program looks like this:
public class VehicleTest {
/**
* #param args
*/
public static void main(String[] args) {
Vehicle bmw = new Vehicle();
Scanner scan = new Scanner(System.in);
System.out.println("How fast do you want to drive?");
int fast = scan.nextInt();
bmw.increaseSpeed(fast);
bmw.testVehicle();
}
}
You should extend Car from Vehicle. Try this:
public class Car1 extends Vehicle {
...
}
Thus you may use Car like a Vehicle.
Some info to read https://books.trinket.io/thinkjava2/chapter14.html
Derive your Car1 class from Vehicle class
public class Car1 extends Vehicle{
String regnr;
public Car1(String regnr) {
super();//pass data to parent constructor if needed
this.regnr = regnr;
}
public String getRegNbr() {
return regnr;
}
}
Now you will be able to call public methods from Vehicle class.
Car1 car = new Car1("DHM1234");
car.increaseSpeed(5); // The current speed is increasing to: 5
if you want to change behavior of any public/protected methods of your vehicle (parent) class for your car class, override that method
i.e
#Override
public void brake() {
int currentSpeed = 0;
System.out.println("Hard break");
}
now if you call brake() from car object
car.brake(); // Hard break will be printed
Give Java Inheritance a read to learn more.
I'm trying to pass two values for an object to be passed into an ArrayList from a constructor, I'm stuck trying to figure out how to pass the rate value which has a fixed value in the constructor which another class is also inheriting from. The obj requires an int, double (int is via input).
public static HotelRoom roomNormal()
{
int room1to299;
double rate;
HotelRoom obj = null;
room1to299 = Integer.parseInt(JOptionPane.showInputDialog("Enter room number"));
rate = obj.getRate();
obj = new HotelRoom(room1to299, rate);
JOptionPane.showMessageDialog(null,"--Rooms Booked out--\n\n\n"
+ "Room No. " + room1to299
+ "Nightly Rate $" + obj.getRate());
return obj;
}
This is the HotelRoom class
public class HotelRoom
{
private int roomNo;
private double rate;
public HotelRoom(int roomNo, double rate)
{
this.roomNo = roomNo;
this.rate = rate;
if(roomNo < 300)
this.rate = 69.95;
else
this.rate = 89.95;
}
public int getRoomNo()
{
return roomNo;
}
public void setRoomNo(int roomNo)
{
this.roomNo = roomNo;
}
public double getRate()
{
return rate;
}
public void setRate(double rate)
{
this.rate = rate;
}
#Override
public String toString()
{
return "Room No.: " + roomNo + ", Rate: " + rate + '\n';
}
public double increaseRate(double surcharge)
{
return (this.rate + surcharge);
}
}
this is the class inheriting from HotelRoom
public class Suite extends HotelRoom
{
private double surcharge = 40.00;
public Suite(double surcharge, int roomNo, double rate)
{
super(roomNo, rate);
this.surcharge = surcharge;
}
public double getSurcharge()
{
return surcharge;
}
public void setSurcharge(double surcharge)
{
this.surcharge = surcharge;
}
#Override
public String toString()
{
return super.toString() + "Surcharge: " + surcharge + 'n';
}
}
This is the main method so far
public static void main(String[] args)
{
ArrayList<HotelRoom> hrs = new ArrayList<>();
int userSelect = menu();
while(userSelect != 4)
{
switch(userSelect)
{
case 1:
subMenu();
break;
case 2:
roomBooked();
break;
case 3:
roomBookedAll();
break;
default:
JOptionPane.showMessageDialog(null, "Invalid input");
}
}
}
public static int menu()
{
String selectMenu = "--HOTEL RENTAL SYSTEM--\n\n"
+ "1. Choose a room type\n"
+ "2. Room rates information\n"
+ "3. Rooms currently booked\n\n"
+ "4. Exit";
int select = Integer.parseInt(JOptionPane.showInputDialog(selectMenu));
return select;
}
public static void subMenu()
{
String subMenu = "1. Normal Hotel room\n"
+ "2. Suite\n\n"
+ "Choose room type";
int select = Integer.parseInt(JOptionPane.showInputDialog(subMenu));
switch(select)
{
case 1:
roomNormal();
break;
case 2:
roomSuite();
break;
default:
break;
}
}
public static HotelRoom roomNormal()
{
int room1to299;
double rate;
HotelRoom obj = null;
room1to299 = Integer.parseInt(JOptionPane.showInputDialog("Enter room number"));
rate = obj.getRate();
obj = new HotelRoom(room1to299, rate);
JOptionPane.showMessageDialog(null,"--Rooms Booked out--\n\n\n"
+ "Room No. " + room1to299
+ "Nightly Rate $" + obj.getRate());
return obj;
}
Your question is a little vague, so I assume the error is in the first block of code you've provided, which is the roomNormal() method. That being said, your HotelRoom object obj needs to be initialized first before it can access the getRate() method. Otherwise, it will throw a null pointer exception.
Solution: rate = 4.5 instead of rate = obj.getRate()
My goal is to have 2 different objects fight each other, and show the results. My problem is I cant figure out how to set the attack and health properly so that it actually updates the way it is supposted to.
import java.util.Random;
import java.util.Scanner;
/**
*
* #author Brenton
*/
public class Fighter {
private String name;
private int attack;
private int level = 1;
private int health = 50;
private boolean isAlive = true;
private Fighter fighterTwo;
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}
public int getAttack() {
Random generator = new Random();
attack = generator.nextInt(10) * level + 1;
return attack;
}
public void setAttack(int attack) {
this.attack = attack;
}
public int getLevel() {
if(level >= 60)
{
level = 60;
}
return this.level;
}
public void setLevel(int level) {
this.level = level;
}
public int getHealth() {
if(this.health <= 0)
{
this.health = 0;
}
return this.health;
}
public void setHealth(int health) {
this.health = health;
}
public boolean isAlive() {
if(this.health <= 0)
{
this.isAlive = false;
}
return this.isAlive;
}
public static String getWelcome() {
String welcome = "Hello and welcome to FightClub, do you wish to fight, yes or no? ";
return welcome;
}
public String getPunch(Fighter fighterTwo) {
this.fighterTwo = fighterTwo;
String hit = "You choose to punch the other fighter and dealt " + getAttack() + " damage, your opponent now has " + this.decreaseHitPoints(fighterTwo) + " health remaining";
return hit;
}
public int decreaseHitPoints(Fighter fighterTwo) {
this.fighterTwo = fighterTwo;
int health = fighterTwo.getHealth();
int attack = getAttack();
health = health - attack;
return health;
}
public static String invalidInput() {
String invalid = "I am sorry that is not a valid input option ";
return invalid;
}
public void getWinner(Fighter fighterTwo) {
this.fighterTwo = fighterTwo;
if(this.isAlive() == false && fighterTwo.isAlive() == false)
{
System.out.println("Both fighters have fallen heroically");
}
else if(this.isAlive() == true && fighterTwo.isAlive() == false)
{
System.out.println(this.getName() + " is victorious! ");
}
else if(this.isAlive() == false && fighterTwo.isAlive() == true)
{
System.out.println(fighterTwo + " is victorious! ");
}
else
{
System.out.println("ERROR ERROR ERROR");
}
}
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
Fighter a = new Warrior();
Fighter b = new Dragon();
System.out.print(getWelcome());
while(in.hasNextLine())
{
switch(in.nextLine())
{
case "no":
System.out.println("Wow, you are not even gonna try, you have lost!");
break;
case "yes":
System.out.println("Let the fight begin! ");
while(a.isAlive() && b.isAlive())
{
System.out.println("Do you want to punch, kick, or headbutt the other fighter? ");
switch(in.nextLine())
{
case "punch":
System.out.println(a.getPunch(b));
break;
/*case "kick":
System.out.println(a.getKick(b));
break;
case "headbutt":
System.out.println(a.getHeadbutt(b));
break;*/
default :
System.out.println(invalidInput());
break;
}
}
default:
System.out.println(invalidInput());
break;
}//end of first switch statement
}//end of first while loop
}//end of main
}
You're calculating the attack correctly. You're just not updating the state of the other fighter.
In your main() method you launch the attack with
System.out.println(a.getPunch(b));
That's just fine. a throws a Punch at b, then you print out the hit points returned from getPunch(). So let's dig deeper into getPunch() to try to find the problem.
In getPunch() you end up invoking
this.decreaseHitPoints(fighterTwo)
while constructing the return String. This seems like the right approach, so is there a problem in decreaseHitPoints()?
public int decreaseHitPoints(Fighter fighterTwo) {
this.fighterTwo = fighterTwo;
int health = fighterTwo.getHealth();
int attack = getAttack();
health = health - attack;
return health;
}
You assign the fighterTwo argument to your fighterTwo field. Not sure why, but that's not wrong per se. Then you get his health into a local variable called health. Then you get the attack into a local variable called attack. Then you subtract attack from health, and then return the calculated value. But you never update the health value on fighterTwo! So you just need one more line in your program: right before your return statement, insert
fighterTwo.setHealth(health);
I am trying my hand at using what I have learned to create a Blackjack game, but I seem to be having problems. It seems like everything I do in this project requires me to use static variables, but when I do, I'm not getting the correct answers. What makes java require variables to be static, even when you don't wish to use them, and is that the reason that my results are always wrong? i.e. You and the dealer having the same hand despite .remove(0) being called each time.
Card Class:
package cardGames;
import java.util.ArrayList;
public class Card {
private final Rank rank;
private final Suit suit;
private static final ArrayList<Card> deck = new ArrayList<Card>();
public enum Rank {
Two(2), Three(3), Four(4), Five(5), Six(6), Seven(7), Eight(8), Nine(9), Ten(10), Jack(10), Queen(10), King(10), Ace(11);
private int rankNum;
Rank(int value) {
this.rankNum = value;
}
public int getRankIDNum() {
return this.rankNum;
}
}
public enum Suit {
Clubs(0), Diamonds(1), Hearts(2), Spades(3);
private int suitNum;
Suit(int value) {
this.suitNum = value;
}
public int getSuitIDNum() {
return this.suitNum;
}
}
public Card(Rank rank, Suit suit) {
this.rank = rank;
this.suit = suit;
}
static {
for(Suit suit: Suit.values()) {
for(Rank rank: Rank.values()) {
deck.add(new Card(rank, suit));
}
}
}
public Rank getRank() {
return this.rank;
}
public Suit getSuit() {
return this.suit;
}
public static ArrayList<Card> createDeck() {
return new ArrayList<Card>(deck);
}
#Override
public String toString() {
return rank + " of " + suit;
}
}
And this is the class for my game.
Blackjack Class:
package cardGames;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;
public class Blackjack {
static ArrayList<Card> deck;
static ArrayList<Card> hand = new ArrayList<Card>();
static ArrayList<Card> dealer = new ArrayList<Card>();
private static int value = 0;
private static int dealerValue = 0;
private static int choice;
private static Scanner play = new Scanner(System.in);
public static void main(String[] args) {
deck = Card.createDeck();
Collections.shuffle(deck);
Collections.shuffle(deck);
playBlackjack();
}
public static void playBlackjack() {
dealCards();
showHand();
showDealer();
System.out.println("\nThe value of your hand is: " + getValue(hand) + ". What would you like to do?"
+ "\n 1. Hit \t2. Stay \t3. Quit");
while(play.hasNextInt()) {
choice = play.nextInt();
switch(choice) {
case 1:
hit();
break;
case 2:
stay();
break;
case 3:
System.exit(0);
break;
default:
System.out.println("That was not a valid choice, please choose again.");
}
}
}
public static void dealCards() {
hand.add(deck.get(0));
deck.remove(0);
hand.add(deck.get(0));
deck.remove(0);
dealer.add(deck.get(0));
deck.remove(0);
dealer.add(deck.get(0));
deck.remove(0);
}
public static void showHand() {
for(Card card: hand) {
System.out.println(card.toString());
}
}
public static int getValue(ArrayList<Card> hand) {
for(Card card: hand) {
value += card.getRank().getRankIDNum();
}
return value;
}
public static void hit() {
hand.add(deck.get(0));
deck.remove(0);
if(getValue(hand) > 21) {
System.out.println("You have busted with a score of " + getValue(hand) + "! Game over.");
System.exit(0);
} else {
showHand();
System.out.println("The current value of your hand is: " + value + ".");
}
}
public static void stay() {
System.out.println("You are choosing to stay with a score of " + getValue(hand) + ". Let's see what the dealer gets.\n");
dealer();
}
public static void dealer() {
showDealer();
while(getDealer(dealer) > 17) {
System.out.println("The dealer is currently sitting at " + getDealer(dealer) + "."
+ "\nThe dealer draws a :" + deck.get(0).toString());
hitDealer();
showDealer();
}
if(getDealer(dealer) >= 17) {
System.out.println("The dealer is staying with his " + getDealer(dealer) + ".\n");
System.out.println("Your Hand: \n");
showHand();
System.out.println("\nDealer's Hand: \n");
showDealer();
if(getDealer(dealer) > getValue(hand)) {
System.out.println("They always say, 'Never bet against the house.");
} else if(getDealer(dealer) == getValue(hand)) {
System.out.println("It's a push, you have the same score as the dealer.");
} else {
System.out.println("Your " + getValue(hand) + " beat the dealer's " + getDealer(dealer) + ". Congratulations!");
}
System.out.println("Would you like to play again? (1. Yes \t2. No)");
choice = play.nextInt();
switch(choice) {
case 1:
new Blackjack();
break;
case 2:
System.out.println("\nThanks for playing.");
System.exit(0);
break;
default:
System.out.println("That was unintelligible, you must have had a little too much Chardonnay. We're calling you a cab.");
System.exit(0);
}
}
}
public static void showDealer() {
for(Card card: hand) {
System.out.println(card.toString());
}
System.out.println("\n");
}
public static int getDealer(ArrayList<Card> dealer) {
for(Card card: dealer) {
dealerValue += card.getRank().getRankIDNum();
}
return dealerValue;
}
public static void hitDealer() {
dealer.add(deck.get(0));
deck.remove(0);
}
}
Well, you brought it on yourself.
public static void main(String[] args) {
deck = Card.createDeck();
Collections.shuffle(deck);
Collections.shuffle(deck);
playBlackjack();
}
The createDeck() method. Does it need to be static? the playBlackjack() method. Does it need to be static? You need to work with objects by using the new operator.
It is asking you to make everything static because you arent working with objects. the main method should be something like this.
public static void main(String[] args) {
Card cardDeck = new Card();
.... // your code here
card.playBlackjack();
}
You are doing all your logic in a static main method and thats why its asking for all the variables to be static.
Abstract out the entire logic of blackjack in a different class and use that class instance to do all your required tasks.