Constructor Needs To Import Enum Blackjack Game

Jun 21, 2014

I am just not importing the Enum value properly. The error I am getting with the DECK class is

import java.util.ArrayList;
public class Deck {
ArrayList<Card> deckList = new ArrayList<Card>();
String[] value = {"Two","Three","Four","Five","Six","Seven","Eight","Nine","Ten","Jack","Queen","King","Ace"};
String[] suit = {"Hearts","Clubs","Spades","Diamonds"};

[Code] ....

1 error found:
File: C:UsersFouadDesktopSchooCSC 162 SUMMER 14lackjack1Deck.java [line: 19]
Error: constructor Card in class Card cannot be applied to given types;
required: CardEnum.Rank,CardEnum.Suit
found: java.lang.String,java.lang.String
reason: actual argument java.lang.String cannot be converted to CardEnum.Rank by method invocation conversion

I have also tried this with the Deck Class

import java.util.ArrayList;
public class Deck {
ArrayList<Card> deckList = new ArrayList<Card>();
String[] value = {"Two","Three","Four","Five","Six","Seven","Eight","Nine","Ten","Jack","Queen","King","Ace"};
String[] suit = {"Hearts","Clubs","Spades","Diamonds"};

[Code] ....

Resulting ERROR message

2 errors found:
File: C:UsersFouadDesktopSchooCSC 162 SUMMER 14lackjack1Deck.java [line: 19]
Error: cannot find symbol
symbol: variable value
location: class CardEnum
File: C:UsersFouadDesktopSchooCSC 162 SUMMER 14lackjack1Deck.java [line: 19]
Error: cannot find symbol
symbol: variable suit
location: class CardEnum

THE FULL CODE!(BELOW)

public class BlackJack{
BlackJack() {
Deck deck = new Deck();
deck.createDeck();
System.out.println(deck.deckList);
}
public static void main(String[] args) {
new BlackJack();

[Code] ....

View Replies


ADVERTISEMENT

Turning Single Player Blackjack Game Into Multiplayer

Mar 19, 2014

I wrote a single player blackjack code and i want to play this game with multiplayers, which steps should i take to do this

package blackjack;
import java.util.Random;
import java.util.Scanner;
public class Blackjack {
public static void main(String[] args) {
Random kagit=new Random ();

[Code] .....

View Replies View Related

How To Get Sound To Import It To Game

Apr 7, 2015

how to make a simple game. I am having trouble when it comes to adding sound though. It tells me to do this:

package net.game.Game;
 
import java.applet.Applet;
import java.applet.AudioClip;
 public class Sound {
public static final AudioClip BALL = Applet.newAudioClip(Sound.class.getResource("ball.wav"));
public static final AudioClip GAMEOVER = Applet.newAudioClip(Sound.class.getResource("gameover.wav"));
public static final AudioClip BACK = Applet.newAudioClip(Sound.class.getResource("back.wav"));
}

What this does is it gets the sound file then gives it a name(BALL=ball.wav GAMEOVER=gameover.wav ect..) and then there is other code in other classes that call the sound so it will run but it keeps giving me an error and I don't know what to do. How can I get it to import the sound? Here is the error.

PHP Code:

Exception in thread "main" java.lang.ExceptionInInitializerError
    at net.game.Game.stuff.<init>(stuff.java:35)
    at net.game.Game.stuff.main(stuff.java:62)
Caused by: java.lang.NullPointerException
    at sun.applet.AppletAudioClip.<init>(Unknown Source)
    at java.applet.Applet.newAudioClip(Unknown Source)
    at net.game.Game.Sound.<clinit>(Sound.java:7)
    ... 2 more 

View Replies View Related

Blackjack Program - Error Occurred During Initialization Of VM

May 21, 2014

I've been trying to finish this blackjack program I have been making for my programming class, however, there are a few bugs I can't seem to iron out. It's a pretty short program, it's just that I'm an idiot and can't figure basic stuff like this out. Specifically, when I try and run it, I get this error:

Error occurred during initialization of VM
java.lang.OutOfMemoryError: unable to create new native thread

Java Code:

import static java.lang.System.*;
import java.applet.Applet;
import java.util.Scanner;
import java.io.*;
import java.util.Random;
import java.util.Date;

[Code] .....

So, obviously I'm doing something horribly wrong.

View Replies View Related

File Import Which Is Not Standard Import

Apr 5, 2014

Usually, most of the time, I import the standard java stuff.But what happens when I find a code with a list of those com. imports:

import java.io.File;
import java.io.IOException;
import com.itseasy.rtf.RTFDocument;
import com.itseasy.rtf.text.Border;
import com.itseasy.rtf.text.Field;

Where are these imports and how do I "get" them?

View Replies View Related

How To Get Enum Name By Value

Jan 12, 2015

I want to have a priceObject which is constructed by a price the enumtype and the name.

public class Testing {
public static void main(String[] args) {
PreisObject p1 = new PreisObject(1,Price.liquid,"TEST1");
System.out.println(p1);
PreisObject p2 = new PreisObject(2,Price('f'),"Test2");

[Code] .....

As you can see with PreisObject2 I want to check the enum by the value and not by the name as in PreisObject1.

Or do I have to use a if-else or switch statement to do something like this?

View Replies View Related

Enum Type And Array List

Feb 10, 2015

Here I have an enum class

public enum Money{

ONE_PENNY(1),
TWO_PENCE(2),
FIVE_PENCE(5),
TEN_PENCE(10),
TWENTY_PENCE(20),
FIFTY_PENCE(50),
ONE_POUND(100),
TWO_POUNDS(200);

private int coin;
Money(int c) {
coin = c;
}
int showCoin() {
return coin;
}

and for a test class, I need an array list with a couple of coins in it (i.e. ONE_POUND, TWO_POUNDS) and a loop that adds together the values of the coins in the list and prints the result. How can I do this?

View Replies View Related

JSF :: Enum Type In Parametrized Class

Dec 4, 2014

I'm developing a JSF application.I have some enums, for example

public enum Gender {
MALE("Male"),
FEMALE("Female");
private final String label

[code]....

I want to put the enum value in <h:selectOneMenu>. I use a bean:

@Named(value = "genderBean")
@RequestScoped
public class GenderBean {
/**
* Creates a new instance of GenderBean
*/
public GenderBean() {

[code]...

How can i call the method .values() of enum for a generic enum T, like in the striked code?

View Replies View Related

Iterate Enum Type Without Instance

Sep 16, 2014

Is there anyway to iterate an enum type without an instance. As some context, consider the following code:

Java Code: public interface GenericChecker
{
public bool isValid(String str);
} mh_sh_highlight_all('java'); Java Code: public class EnumChecker<T extends Enum<T> > extends GenericChecker
{
private Class<T> enumType; //No instance

[code]....

toString method of the enum types has been overridden so that it returns the name assigned to the enum rather than the enum name itself. For example an enum might be SOME_ENUM("Assigned name"), therefore toString returns "Assigned name" rather than "SOME_ENUM". The idea is that a field from a table can be handed to the isValid(String) function on the GenericChecker base, and the derived class will then check to see if the field matches valid data as far as it is concerned.Thus, I can create a whole bunch of checkers easliy:

Java Code: GenericChecker checker1 = EnumChecker<EnumType1>();
GenericChecker checker2 = EnumChecker<EnumType2>();
GenericChecker checker3 = EnumChecker<EnumType3>();
GenericChecker checker4 = SomeOtherChecker(); mh_sh_highlight_all('java');

The problem is, if I use the EnumChecker then the expression "enumType.getEnumConstants()" in the isValid function blows up because enumType is null.

View Replies View Related

Why Enum Types Not Being Recognized By Methods

Mar 17, 2014

Attempting to write a custom comparator for sorting songs, but I keep getting errors saying that the types cannot be resolved.

Java Code:

import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.util.*;
public class SongCollection {

[Code] .....

View Replies View Related

Creating Enum With String And Method

Nov 9, 2014

How would I go about and make an enum, that has Strings and Methods?I want to make a class called GraphicalEffects, this class and be instanstiated and it has a method to apply graphicalEffects AS methods or some type of references to methods in an ArrayList.

View Replies View Related

Method Values For Enum Types

Nov 21, 2014

What class does method Planet.values() in the code below belong to? I thought it belongs to java.lang.Enum but when I could not see it in Java API 7.

package enumeration;
public class EnumTest {
public static void main(String[] args) {
//Planet myPlanet = Planet.EARTH;
// Check arguments supplied
if (args.length != 1) {
System.err.println("Usage: java EnumTest <earth_weight>");
System.exit(-1);

[code]....

View Replies View Related

Enum Properties / Values / Fields

Jul 11, 2014

So I have an Enum file with 119 constants and each constant of that type has 20 fields that come with it. All the fields are the same type and named the same (e.g. there are 119 of Object obj, one for each constant), and I want to run the same methods over them. Since the Objects of the same type are named the same for each constant, I just have them named explicitly in get-er methods.

This worked fine when I just put all 20 fields through the constructor and set them as fields under all the constants. But I realized that if I wanted to make an instance of this Enum class, I'd have to enter in all 20 fields when they are all a set of Objects with unique values. So I then put them as fields under their own respective constant to make it easier to create instances of this enum. But now my methods don't work.

A) I don't really understand why they don't work anymore?
B) Is there a way to fix it without putting all the methods under each constant?

Example:

public enum MyEnum {
AAA {
private MyObject obj = new MyObject (3.0);
},
BBB {
private MyObject obj = new MyObject (1.5);
},
CCC {
private MyObject obj = new MyObject (6.5);
},
DDD {
private MyObject obj = new MyObject (3.5);
};

public double getObjVal() {
return obj.value(); // it can't find this obj should I move it up to where the constants are declared?
}
}

View Replies View Related

How To Find Maximum Of Two Enum Values

Oct 6, 2014

I have a set of enum values (let's call then ONE, TWO, THREE.....). I want to find the larger of two of them. But max(ONE,THREE) gives a compile error as MAX isn't defined for type-safe enums. Fair enough.
 
I also agree that one shouldn't be able to use arithmetic functions on enums.
 
But as Enum implements Comparable, one can write a function which implements max and min, rather inefficiently I assume.
 
Is there a better way of getting the max/min of an enum? And if not, can the Java team be persuaded to implement it?

View Replies View Related

Getting Error - Class Interface Or Enum Expected

Aug 7, 2014

import java.io.*;
class addition {
public static void main(String[] args) {
int num1,num2,sum;
try {
DataInputStream x=new DatainputStream(system.in);

[Code] ,,,,,

View Replies View Related

Dynamic Enum - How To Make DIME(10) False

Apr 20, 2015

I wrote a simple enum and a test class. The enum represents us coins and my test class uses the enum to calculate the change with the least number of coins. For example, I pass in 95 cents, I get back 3 quarters, 2 dimes. It all works just fine, easy to implement and I see why I should use an enum. Then I thought, what if the person is out of dimes. How could I tell the enum to skip dimes in it's switch statements? How would I make DIME(10) false?

View Replies View Related

Strings With Digits Not Permitted Enum Values?

May 28, 2013

If you have an enumeration type with instances whose publicly accepted names are numbers, e.g. a Chevy 396 and I'm sorting this car according to makes and models that I've already laid out within enum types for each. Here the make instance is "Chevy" and the model instance is just "396".

I know I could make this "396" into "Ch396" and this would work programmatically. But this might confuse some people who just expect to see "396".

In short, why are enum instances not allowed to be of String type rather than just standard Java identifiers ?

View Replies View Related

Enum Class Throwing Illegal Argument Exception?

Mar 4, 2015

I have a enum class which contains some string which i am comparing to a string i get from a user

Java Code:

public enum Compare {
a, b, c, d, e, f
} class SomeClass {
String method(String letter){
Compare word= Compare.valueOf(letter);
}
} mh_sh_highlight_all('java');

Everything works fine but when I added a new word to it like "g" it throws the IllegalArgumentException ?

View Replies View Related

Enum Class - How To Pass In Faction Type In For Daunt

Mar 6, 2015

Suppose I have an enum class named Faction and one of the constants is named DAUNT. I created a class of the enum DAUNT but how can I pass in a DAUNT faction type in for Daunt?

Java Code:

public enum Faction {
ALMIGHTY, AMBITION, DAUNT, RESTLESS, CAN;
}

//new file
public class Daunt {
public Daunt() {
}
} mh_sh_highlight_all('java');

View Replies View Related

Calendar (Days Enum) - Determine If Day Is Weekday Or Weekend

Oct 17, 2014

The instructions state: Create the following values for the enum (and make sure that they are spelled correctly, case matters):

a. SUN
b. MON
c. TUE
d. WED
e. THU
f. FRI
g. SAT

Create a private constructor for the Day enum that takes a boolean value. This boolean will determine if the day is a weekday (if it is true) or weekend (if it is false). Document it with a JavaDoc. This value will need to be stored as part of the object. Update the enum values so that they correctly call the constructor. Saturday and Sunday are the only days considered part of the weekend.

Implement the following methods:
a. boolean isWeekday()
i. Returns true if the day is a weekday.

b. Boolean isWeekend()
i. Returns true if the day is a weekend. (How could you determine that?)

c. String toString()
i. Returns the full name of the day for the enum value (i.e. Monday or Tuesday). Use either a set of nested ifs or a switch statement.

Hint: You will want to compare the this reference against the possible values in the enum.

View Replies View Related

Creating Enums Without Using Enum Class And Private Static Final Keywords?

Jun 11, 2014

I am wondering if there is a way in jave to use enums WITHIN a class (without creating a separate enum class) without using private static final. Something like as folows:

class My Class {
myEnum {ACTIVE, INACTIVE, PENDING};
}

is there something like this available?

View Replies View Related

JSP :: How To Import / Refer Css

Aug 7, 2014

accdg to this: [URL]....

we can use EL expression as follows:

${pageContext.request.contextPath}

but there's no instructions as to how I will set its value.

And also, what would happen in case I refer 2 css files in my jsp and both defines the following:

CSS 1 :
body { background-color: #fdf5e6;
font-size: 810px;
}

CSS 2:
body { background-color: #fdf5e6;
font-size: 50px;
}

View Replies View Related

How To Import Certificates From One JVM To Another

Jul 1, 2015

i am migrating my web application from Server1 (Tomcat 5 and Java 1.5) to Server2 (Tomcat 7 wand Java 1.6).

In my web application, I have multiple adapters (web clients) that are connecting to external web services, https interfaces, sftp servers etc.

In order to connect with all these external interfaces, i have installed multiple certificates in my JRE keystore on Server1.
 
Now since the application is going to be migrated to Server2, i need to know if there is any way I can import all the existing certificates from Server1 JRE to Server2 JRE?
 
Since the application has been running on Server1 for a long time, I am not sure, what exactly is a complete list of certificates that I need to install on my Server2 JRE.
 
So i am kind of looking how can i generate the keystore file with certificates from the existing server1 JRE and then import it into Server2 JRE.
 
Does this command provide a list of all the installed certificates on my Server1 JRE?

server1:/webdienste/java/jdk/xxx/current/jre/lib/security> sudo /webdienste/java/jdk/xxx/current/bin/keytool -list -v -keystore cacerts | grep Eigner

The other solution i can think of is to manually download/save all the certificates by opening all the URLs in the browser and then import the .pfx files through keytool into my Server2 JRE.

View Replies View Related

Opoly Game - Goal Of The Game Is To Reach Or Exceed Reward Value 1000

Mar 12, 2015

Opoly works this way: The board is a circular track of variable length (the user determines the length when the game app runs). There is only one player, who begins the game at position 0.

Thus, if the board length is 20, then the board locations start at position 0 and end at position 19. The player starts with a reward of 100, and the goal of the game is to reach or exceed reward value 1000. When this reward value is reached or exceeded, the game is over. When the game ends, your program should report the number of turns the player has taken, and the final reward amount attained.

In Opoly the game piece advances via a spinner - a device that takes on one of the values 1, 2, 3, 4, 5 at random, with each of the five spin values equally likely.

Although the board is circular, you should draw the state of the board as a single "line", using an 'o' to represent the current player position, and * represent all other positions. Thus if the board size is 10, then this board drawing:

**o******

means that the player is at location 2 on the board.

Here are the other Opoly game rules:

If your board piece lands on a board cell that is evenly divisible by 7, your reward doubles.

If you land on the final board cell, you must go back 3 spaces. Thus if the board size is 20, the last position is position 19, and if you land there, you should go back to position 16. (If the position of the last cell is evenly divisible by 7, no extra points are added, but if the new piece location, 3 places back, IS evenly divisible by 7, then extra points ARE added).

If you make it all the way around the board, you get 100 points. Note that if you land exactly on location 0, you first receive 100 extra points (for making it all the around), and then your score is doubled, since 0 is evenly divisible by 7,

Every tenth move (that is, every tenth spin of the spinner, move numbers 10,20,30,... etc.), reduces the reward by 50 points. This penalty is applied up front, as soon as the 10th or 20th or 30th move is made, even if other actions at that instant also apply. Notice that with this rule it's possible for the reward amount to become negative.

Here is the driver class for the game:

import java.util.*;
public class OpolyDriver{
public static void main(String[] args){
System.out.println("Enter an int > 3 - the size of the board");
Scanner s = new Scanner(System.in);
int boardSize = s.nextInt();

[Code] ....

heres the methods:

REQUIRED CODE STRUCTURE: Your Opoly class must include the following methods (in addition to the Opoly constructor) and must implement the method calls as specified:

playGame - The top-level method that controls the game. No return value, no parameters. Must call drawBoard, displayReport, spinAndMove, isGameOver.

spinAndMove - spins the spinner and then advances the piece according to the rules of the game. No return value, no parameters. Must call spin and move.

spin - generates an integer value from 1 to 5 at random- all equally likely. Returns an integer, no parameters.

move - advances the piece according to the rules of the game. No return value, takes an integer parameter that is a value from 1 to 5.

isGameOver - checks if game termination condition has been met. Returns true if game is over, false otherwise. No parameters.

drawBoard - draws the board using *'s and an o to mark the current board position. Following each board display you should also report the current reward. No return value, no parameters.

displayReport - reports the end of the game, and gives the number of rounds of play, and the final reward. No return value, no parameters.

View Replies View Related

Tic Tac Toe Game - Random Number Generator And Two Dimensional Arrays For Game Board

May 9, 2015

Im trying to make a tic tac toe game that you play against the computer using a random number generator and two dimensional arrays for the game board. Im not trying to make a GUI, the assignment is to have the board in the console, which I have done. I have run into a few problems with trying to get the computer player to correctly generate 2 integers and have those two integers be a place on the game board. Here is my code so far.

import java.util.Random;
import java.util.Scanner;
 public class TicTacToe {
 private static Scanner keyboard = new Scanner(System.in);
private static char[][] board = new char[3][3];
public static int row, col;
 
[Code] ....

View Replies View Related

Import All Library Within Directory

Sep 1, 2014

I see you can import in 2 ways:

import java.util.*;

or

import java.util.Scanner/Random/etc;

if I used the first one it imports all the librarys within that (directory?). If so would that add to a bigger file size?

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved