class blackjack {
public static void main ( String[] args ) {
Random r = new Random();
Scanner keyboard = new Scanner(System.in);
String money;
String name;
[Code]...
I know people will want me to tidy it up, or do it "their" way, but honestly I just need method of getting the user to press h or s and have the program continue under it's own steam.
I am a begMy task is to write a program that plays the "Hi Lo guessing game." The program runs smoothly. However, it does not proceed to the next game after the previous game is done. I need to add a "play again" choice to the program so that the user will continue to play until they have chosen to quit. I have tried several different ways but each one has failed. I am completely stuck on this. I have attached my code to this.
So, after my graphics card melted down, I decided to use a chat program because I can't play the game server which I am staff on. I've downloaded this:
CactusChat: MC 1.7.4 - 1.7.5 chat client for Windows, Mac and Linux Operating Systems | EcoCityCraft Economy | Minecraft Servers
After I knew it was a .jar file, it would basically fail, I would launch it, it turns into a cmd for 0.5 seconds, and closes without any progress. Typical, and expected.I downloaded the latest java update, removed 3 older versions, and now my Java SE Binary program went missing. I can't even launch it, and it tells me to look for another program to launch it with.
I am creating a roulette program that I converted from C++ to Java. Why its not finding the main class. Therefore it will not compile. Heres the code:
import java.util.Scanner; public class P1RouletteDB { // This program demonstrates the use use multiple arrays to play a roulette game. //Also a random number will generated to be used as the ball in the game. The user will be provided the random number to test the win algorithms // Program Set 2 Roulette Game
// Global constants public static final int COLS = 3; // Number of columns in each array
The project is to develop the game Translate the Word .... It is asking user to translate a word proposed to and check if the input response is correct. At the end of the game score will be calculated and displayed.
Game Play :
1 - Ask the user to specify , through the console , its name and the number of words to offer . It is up to you to handle exceptions (eg number of words greater than the number you provided ) 2 - Recover user response ( the word translated ) and check whether to continue . (eg you want to continue (y / n)) after each proposal. 3 - compare the response of the user with that which is preset for the word in question . 4 - Show the score at the end ( or at the breakpoint ) . 5 - Save the file in a user name , the score , the number of questions and the start date and end of the game played .
Some notes to consider :
1 - The language (eg, English - French , English - Arabic , etc. . ): It is up to you to specify the language adopted in the game and inform the user of your choice. 2 - The word bank to offer : It is up to you to develop the appropriate means to get the words to propose to the user. That said , the words and their translations can be retrieved :
a. a TXT file b . an XML file . ( Tutorials DOM and SAX ) c . CSV file ( OpenCSV Tutorial ) d. a database ( Tutorial Access) e . through APIs (eg Wordnet and google translate etc . ) . f . a combination of the previous options a, bc , d and / or e . (eg words stored in a txt file and answers retrieved from the api google translate) g . etc. .
Examples of files and databases are attached to the project statement . You will need to add one or more external libraries to your project. Click here for details on adding external libraries to Netbeans .
3 - A user will be associated with the question score if he can translate the word correctly. The score for each question can be calculated based on the number of words / questions to be proposed .
Development : In this project you will need at least a class called Question to encapsulate the word and its translations and provide all necessary methods to manipulate the object type Question.
An interface called IParser to make extensible project. Any class that implements IParser is a parser file (XML , TXT , CSV , etc.). / Database. In your project there will be a single class that implements IParser and will be used to retrieve words and their translations.
Add the ability to store the questions and answers of the user on the hard disk. Make the class Serializable Question
I tried this program, its guessing game. Where program decide 1 number and user will guess number. I am getting 1 problem. When user want to play game again.the random number remain same. So where i can put reset random in code..? And 1 more question if I want to write driver code for this. What should i transfer to driver code.
import java.util.Random; import java.util.Scanner; public class GuessGame { public static void main(String args[]) { String choice="y";
I am making a very simple 2D array game where the player is asked what size they would like the game board to be. After entering, it displays the board and the player 'P' starts at index [0][0]. After that, they are asked for an action, which can be "up", "down", "left", "right", or "exit". I will be including some extra later (like a treasure at the end, or random obstacles), but for now this is what the game consists of.
I was instructed to "do nothing" when/if the player attempts to go out of bounds. I am trying to simply print an error, such as "Out of bounds! Try again.", then prompt the player again for an action. I even tried to make a boolean method to catch it, but to no avail.
I don't want the exception to occur at all. I just simply want the error message to print to the player and ask for another action. I would prefer not to use try/catch, or try/catch/finally since I already tried that and it still gave the exception error.This program consists of two classes. I will show the class containing the main first, then the client-server type class second.
import java.util.Scanner; public class Driver { public static void main(String[] args) { World world = new World(); boolean keepPlaying; keepPlaying = true; boolean isOutOfBounds; isOutOfBounds = false; int height = 0; int width = 0; int x = 0; int y = 0;
I am creating a hangman code. So the game i am creating is 2 player, first player enters the word and second player guesses. i made the code but i don't know how to restrict the first player from adding random characters into the secret word because for my project the word can only contain letters. so i need making the code so the player 1 can only enter letters.
My code is below:
/** * Auto Generated Java Class. */ import java.util.Scanner; public class Hangman { public static void main(String[] args) { Scanner input= new Scanner(System.in); String player1,player2; int wrongguessamount = 0; //keeps the count of the amount of wrong guesses int correctguessamount = 0; //keeps count of the amount of correct guesses int maxincorrect=6;//makes sure the user cant guess more than 6 times
I will try to explain what i want to code , a HiLo game where the user can choose up to 3 different levels(1-10, 1-100, 1-1000) with these 3 methods
public static void main(String[] args) {...} public static int playGame(int maxNumber) {...} public static void giveResponse(int answer, int guess) {...}
with no Random , i will use the:
int number = (int)(Math.random() * max) +1; to generate numbers
I have tried so many times , but i don't get it ....
My code so far :
import java.util.Scanner; public class HL{ public static void main(String[] args ){ Scanner s = new Scanner(System.in);
My assignment is to create a hangman game. One of my first difficulties with it is how to scan the string for an input supplied by the user.
Here is my method:
//Guesses that character c is in the secret word. //Updates all instance variables accordingly, //and returns true if c is present in the secret word. public boolean guessCharacter(char c){ }
The problem occurs after the user inputs the guess.... it either runs the for loop if guess = numtoguess and reveals the answer even if the user input is wrong.... or it always runs the first if statement in the while loop if guess!= to numtoguess... heres the code
public static void main(String[] args) { String[] Answers = {"yes", "Yes", "No", "no"}; String Name = JOptionPane.showInputDialog(null, "Hello, What is your name?","Random Game", JOptionPane.QUESTION_MESSAGE); String UI = JOptionPane.showInputDialog(null, Name + " do you want to play a game", "Random Game", JOptionPane.QUESTION_MESSAGE);
I am trying to print the response of servlet as pdf. Below is my codeI am able to generate the response but not quite sure how should I write it to a pdf.
I have a requirement where a form is present with first name, last name, file upload etc. File upload is done through ajax call and then the form is submitted to a servlet. I want to know whether the file has been uploaded or not in the servlet which is called after i click on the form submit button. So is there any way i can read the response of the ajax call in the servlet ?
I have a EAR enterprise project with EJB and Web module.EJB module has a SongTokenImpl stateless session bean with @Stateless and @Webservice annotation.Web module has SongServlet.java and success jsp.
SongServlet has dependency injection to SongTokenImpl.
String songName = request.getParameter("songname"); Token token = tokentMaster.bookToken(new Song(songName)); System.out.println("we got song token for song "+token.getSongName());
[code]....
we got song token for song xyzInstead i see below error.SongServlet threw exception: java.lang.IllegalStateException: Cannot create a session after the response has been committed/
I have a SOAP Client with wsdl to send a query to a SOAP Server. Along with the SOAP response I am supposed to attach a generated csv file (Not required to open and read - just attach).
SOAP Handler has been implemented at server.
Since it is client code I am not supposed to paste the exact contents online.
I can create new SOAPMessage and use AttachmentPart to attach the file but I am stumped regarding where to set it as response. We have used only javax.xml and apache.cxf.
I am trying to make a method that takes in a cmd command (nslookup, systeminfo, etc), and outputs the response to a text file. I have tried a dozen different ways with no success. below is my most current failure. It succeeds when i run it, but nothing shows up in the text file.
public static void runSystemCommand(String command) { command = "ping 192.168.1.3"; try{ Process proc = Runtime.getRuntime().exec(command); InputStream in = new BufferedInputStream(proc.getInputStream()); OutputStream out = new BufferedOutputStream(new FileOutputStream("C:NetPanelDataping.txt"));
i am using eclipse kepler and tomcat 7 with the below code to get a response from the browser. i get no errors on my code and i organize my imports but when i run the code i get an http 404 error. i restart the server and it goes into the whole motion telling me that "Tomcat v7.0 Server at localhost started and is synchonized" i refresh it and i still get the error.
I want to print RAW Request Response XML to console. I have created the stubs using wsdl2java axis2. wsdl2java has created 2 java files, one for stub and one for callbackhandler.
I am trying with below method but getting null value for
operationContext.getMessageContext("Out") / operationContext.getMessageContext("In");. public void SOAPLogHandler(Stub stub){
//**** Enable the Cache to hold the last operation OperationContext OperationContext = new OperationContext(); boolean cacheLastOperationContext = true; OperationContext.setComplete(true); // Enable the Cache value serviceConxt.setCachingOperationContext(cacheLastOperationContext); serviceConxt.setLastOperationContext(OperationContext);
I am calling a SOAP based webservice using JAX-WS and a client jar. I want to get a request and response somehow and save it for audit purposes. How I can do this?
When I google it, only Handlers come up, but, as far as I understand, it is not applicable on client side.
I have been using JavaFX for some time now and have encountered many performance issues, mainly with the initial display of GUI elements. For example, a simple stage with a table view (with about 10 columns) and chart takes about 5 seconds to display. A color picker will take about 3 seconds from the time I click the control to when it displays the pallet. This only happens when the controls are first displayed. This can't be right. I have searched and none seems to have a similar problem so I thought I would ask here just to make sure. Here is a sample Hello world that shows the problem with the color picker (takes ~ 3 seconds to show pallet when clicked).
public class HelloWorld extends Application { @Override public void start(Stage primaryStage) { StackPane root = new StackPane(); ColorPicker cp = new ColorPicker(); root.getChildren().add(cp);
I was looking at the Sound API pages in the java tutorials. I was planning to use it to run wma files. Fortunately, for me, I found, soon into the tutorials, that these API DON'T support the type I have all of my files in (I have a ton of wma files but none of the libraries mentioned support them.)
I almost thought I heard JavaFx or whatever it's called does, but that sounds foreign and Netbeans lists it as a separate type of java in a way, so I don't know if it would be cross-platform or if it could work with the JavaSE API.) Nor do I know what JavaSX or whatever it's called is really, other than that it's more for internet than application.
If I wanted a JPanel or Applet acting as the content pane of a JFrame or being in a JFrame, could I use JavaFX (or whatever it's called) or some third party library (that I always tend to end up spending hours on trying to get it to find the jar files when I import them, so I hope I don't need too many jar files!!!! ) would it work with the JavaSE API?
I don't know much about Java and playing sounds (other than that there is a static method, I think under Toolkit, that will play a system beep) with programs.
However, I can see that that packages don't support certain types (so much for cross-platform!!!!!!! ) and also that a while back that Oracle took over and that they aren't really updating the Java Sound APIs really that much at all
So, without having to learn a whole new Java set of standards (assuming JavaFX or whatever it's called is a different set of standards from JavaSE), is there a way to play .wma?
That's all I seem to have on my computer.
(I suppose I could create new sounds, though if Oracle isn't updating the library, who knows if even that works anymore, but if you're trying to run a Java Media Player that runs lots of DIFFERENT sound file types, this seems a real setback. )
I heard you could convert them to MP3s (I heard there were free things that did it, but who knows if the things aren't filled with viruses that'll do it or, even if they're not, that they'll really mess up the quality of the sound and that I might lose the old .wma file in the process even if it doesn't corrupt the sound.)
But, even if I get a .mp3, I heard the main JavaSE libraries DON'T cover that either, though it was said it was easier to make it run them than .wma files.
MediaPlayer and the main JavaSE classes don't seem to be able to fit for this type of program (a java media player) that I was planning. Heck, they can't even play any music I have on my computer at all, media player or not.
I have an arraylist in my servlet which i need to pass to jsp as a response for a javascript call. This is an arraylist of DTOs. There are 24 DTO objects in the list. The DTO has an int variable and a HashMap. And i need to pass this into the javascript code in my jsp page. Do i use json? Do i send the entire list as a json object or should i iterate through the arraylist (from servlet) and serialize all the DTOs and pass that to the jsp?