Help (Timed program)
I�ve done this game, that if the user takes more than 30 sec. to answer, the program, when the user answer, tells that the time has been more that 30 sec. so the answer is not valid;
I would like that the program, during the time the user is answering, displays the time passing and when it reaches 30 sec. it stops and says to the user that the time has passed, and that there is no more time, so the correct answer would be (for example) **-;
Does someone knows how to do this?
Thank�s for all your posts!
import java.io.*;
public class J24{
public static void main(String[] args){
String[] game, result;
game=new String[3176];
result=new String[3176];
TextReader readfile;
String name="JOGO24.txt";
try{
readfile = new TextReader(new FileReader(name));
catch (TextReader.Error e) {
System.out.println("\n\n\nAN ERROR OCURRED DURING READING FILE!");
return;
catch (FileNotFoundException e) {
return;
char c1, c2, c3, c4;
int count;
count=0;
try{
while(readfile.eof()==false){
c1=readfile.getChar();
c2=readfile.getChar();
c3=readfile.getChar();
c4=readfile.getChar();
String str = new StringBuffer().append(c1).append(c2).append(c3).append(c4).toString();
game[count]=str;
c1=readfile.getChar();
c2=readfile.getChar();
c3=readfile.getChar();
String str2= new StringBuffer().append(c1).append(c2).append(c3).toString();
result[count]=str2;
count++;
finally{
readfile.close();
int ran=0;
String Res;
ran=(int)(Math.random()*3176)+1;
boolean rpt=false;
while (rpt==false){
System.out.println("\n\nI ll give you 4 numbers and you have to find 4 operations to give 24. Ex.:");
System.out.println("8802");
System.out.println("8+8+0*2=24; You enter: ++*");
System.out.println("\n---YOU HAVE 30 SECONDS!!!---");
System.out.println("\nOk?");
rpt=TextIO.getBoolean();
ran=(int) (Math.random()*3176)+1;
System.out.println("\n\n");
System.out.println("Number to be 24: "+game[ran]);//ran
long startTime = System.currentTimeMillis();
Res=TextIO.getWord();
long endTime= System.currentTimeMillis();
if(endTime-startTime>30000){
System.out.println("");
System.out.println("Your Passed 30 Seconds!!!");
if(Res==result[ran]){//ran
System.out.println("But, in any case it is correct");
}else{
System.out.println("And the correct answer would be "+ result[ran]);
System.exit(0);
if(Res==result[ran]){//ran
System.out.println("Correct!");
}else{
System.out.println("Correct answer would be "+ result[ran]);
}
Hi,
Which hardware are you using??
Nevertheless, you will find an example VI with examples shipped with labVIEW called "temperature system demo.vi" a simulated temperature measurement program.
replace the temp simulation with hardware thermocouple acquisition VI's
That VI it might suit your purpose
find attached that VI
Any doubts, do get back
regards
Dev
Message Edited by devchander on 03-08-2006 10:48 PM
Attachments:
Temperature System Demo.llb 188 KB
Similar Messages
-
No matter what I try I can never get the Acrobat Reader to be added to the group of "Choose Helper Application" programs available in that window when downloading a pdf. I always have to browse to the Acrobat reader and select it that way.
I have enabled Acrobat in the add-ons manager, but that has not solved the problem.
In the options > applications menu I've selected use Acrobat Reader for pdf files but that doesn't work and furthermore doesn't seem to stick. That is, sometimes when I check that menu later the selection has reverted to "always ask".
I'm using Firefox 32 on Windows 7. I have used Firefox on XP for years and never had this problem.Here are some screen shots to backup my claims.
-
Hai,
Can any one give example for search help with Programming?
I hope we can create search help with help of coding.
With Regards,Jaheer.yes u can create search help by using match code in programs
for eq
go with abap editor se 38
provide the name of program
parameters : vendor like lfa1-lifnr matchcode object yzob.
double click on yzob
provide description for search help
provide selection method
provide search help parameter
enable check box for import and export
provide lpos
spos
save check activate
press f4 for check and import values i.e it will display a records list available in database table
rewards points please -
I switched to Apple Mail in the last two months. When I attempt to print an email message, I get a blank piece of paper. When I attempt to use the print options suggested in "Mail Help", the program crashes and has to be reopened. Any ideas?
Which version of Mail are you using as well as which Snow Leopard version you are using?
-
Adding the search help in program
hi i want to add a search help in program for a particular field of a parameter how to do this?
U need to create a serach help exit for this purpose.
F4IF_SHLP_EXIT_EXAMPLE - documents the different reasons to use a search help exit, and shows how it is done.
http://www.sapdevelopment.co.uk/dictionary/shelp/shelp_exit.htm
http://www.sapdevelopment.co.uk/dictionary/shelp/shelp_basic.htm
Create an Elementary Search help:
Eg: Zsearch
In the defintion tab:
Give the search help exit name: Zsearch_exit.
Also give the search help param and data element.
Copy F4IF_SHLP_EXIT_EXAMPLE into Zsearch_exit
Comment:
callcontrol-step = 'SELECT'. (1st line)
Inside:
IF CALLCONTROL-STEP = 'SELECT'.
Select required data for the search help
Select stmnts as per your requirement and populate in itab.
Move all the selected records to Record_Tab
LOOP AT itab INTO wa_itab.
MOVE wa_itab TO record_tab-string.
APPEND record_tab.
CLEAR record_tab.
ENDLOOP.
RC = 0 .
IF RC = 0.
CALLCONTROL-STEP = 'DISP'.
ELSE.
CALLCONTROL-STEP = 'EXIT'.
ENDIF.
EXIT. "Don't process STEP DISP additionally in this call.
Let me know if its working for you.
Also, chek this link if it helps you:Re: Find Storage location with respect to Plant -
I want parameters with f4 help for program names in value request
I want parameters with f4 help for program names in value request
points will be awarded if usefullv_name1 TYPE name1, "Vendor Name
CALL FUNCTION 'POPUP_TO_SEARCH_VALUE'
EXPORTING
textline1 = 'Vendor Name'(f09)
titel = 'Enter'(f17)
valuelength = 35
IMPORTING
value = lv_name1.
try this out .. -
Hi all,
is anyone able to explain me how to use Search Help freely programmed?
thanks
GNHi Gabriele,
Please go through the component DEMO_VALUE_HELP. This explains all the input help types. The freely programmed search help has been implemented for the CONNID input field of view V1. The Web Dynpro component FREE_VALUE_HELP in the same package is the component where the search help is coded.
Also below are the steps to be followed for implementing the freely programmed search help.
This kind of value help is implemented as a Web Dynpro component implementing the Web Dynpro
component interface IWD_VALUE_HELP. To be able to use the value help for a certain input field, the following steps are necessary:
1) A component usage of the value help component (HC) has to be declared
by the consumer component (CC).
2) A usage of the HC interface controller has to be declared in the CC view.
3) The input help mode User-Defined Programming has to be chosen for the attribute that is bound to the input field under consideration. The HC usage must be related to this attribute. The component interface of the HC has only one method: set_value_help_listener( ). This method is called by the Web Dynpro runtime if the value help button of the input field under consideration is clicked. The HC has to be implemented as follows:
1) The method set_value_help_listener( ) has an import parameter. This means that the reference to the listener, provided by the Web Dynpro runtime, is passed to the user-defined HC. This reference has to be saved as a user defined controller attribute.
2) To close the help value dialog box, the close_window( ) method of the listener has to be used.
3) All views have to be embedded into a window having the name WD_VALUE_HELP. This name is used by the Web Dynpro runtime.
4) To exchange data between the CC and the HC, context mapping can be used.
For implementing the component interface IWD_VALUE_HELP, you need to choose the Reimplement button in the HC. The implementation status changes to green and the events and the method of the component interface are visible in the HC controller.
Regards,
Uday -
Help with program flow and timing a loop please
I'm working on an application that will display vibration data on several tabs. 1 tab displays the time waveform, another a running RMS value, another an FFT etc.
On another tab I want the user to have the option of streaming the data to disk for 'x' number of seconds.
I created a sub-vi with a flat sequence structure.
The first frame open/creates a file. The second frame gets the current time in seconds and adds 'x' seconds to it. The third frame contains a while loop with a "Get Current Time in Seconds" and a "Write to Binary File" which executes while the current time is less than the "previous current time plus 'x'".
This sub-vi is in a while loop that is called when a "capture data" button is pressed.
My problem is that the rest of the program (waveform, RMS, FFT displays) stops executing when the while loop / sub-vi is executing.
This can be seen via the "TEST" indicator that doesn't update.
When the program flow goes back to the rest of the program I get an error 'cause the buffer has over-flown (ed)
I'm really new at this so any help is greatly appreciated.
I've attached images of the main vi (Project3.pdf) and the sub-vi containing the Flat Sequence (WriteToDisk.pdf)
I can attach the actual vis if it helps.
Thanks,
Erik
Attachments:
Project3.pdf 189 KB
WriteToDisk.pdf 85 KBThe behavior you're seeing is by design. There are two solutions to your problem:
Place the write to file in a separate loop that runs in parallel to your main loop. Thus, your "Project3" VI would have two loops. One is the data acquisition, the other is the streaming to file. You should not create data dependencies between the loops that would cause one loop to wait until the other is done. You want both running in parallel. You can stop both loops with the same stop button. With this method you can use local variables to get the Time Waveform data as you're doing now.
Launch the stream to file VI dynamically. This basically uses the VI Server to start a subVI and then immediately return to the caller. The subVI is then running on its own. There are examples that ship with LabVIEW that show you how to do this. You would have to have the subVI monitor something to determine if it should stop should the main program stop.
The first option would be the easiest to implement in your case. The second is more complex, but leaves you with one loop. -
Help with program structure - simple question.
Hi. I need a piece of advice on how to create the correct structure for my program. It consist on two main processes:
1)Detecting time difference between 2 rising edges, and showing the data. I used the concept of another user "panoramarts" that you can see here:
http://forums.ni.com/t5/Digital-I-O/Measuring-Time-between-two-Digital-Signals/m-p/2091868#M16230
(If anyone knows a better way to do it I will really appreciate it)
2) A continuous process.
I attached a picture of the structure I am using. The numbers I will refer to, are indicated there.
The program basically starts counting the time until a rising edge is detected (number 2 in the picture). After that the next sequence is executed (number 3 in the picture) counting the time again until the next edge is detected. After that the subtraction is made to have the time difference and then displayed (number 4 in the picture).
Here is the problem: I have a continuous process that must be executed, so if I place it in "Number 1" then the edge detection must be running otherwise i do not see the continuous process (is like Labview execute de FLAT sequence, and after that the continuous process). If a place the continuous process in another While loop, then is like sometimes I get inaccurate data from the edge detection.
How can I solve that? Is there another way to acquire time between edges? I hope you can help me without the VI.
I am using Arduino, so I can not use DAQmx VI's.
DMDsync
Attachments:
program structure.jpg 54 KBThanks for the quick feedback!
I believe my problem is that I am not using the best way to estimate time between edges. As I previously said, I am using almost the exact VI that "Panoramarts" shared in this link:
http://forums.ni.com/t5/Digital-I-O/Measuring-Time-between-two-Digital-Signals/m-p/2091868#M16230
The only difference is that instead of a DAQ assistant in each of the While Loops, I use the same input for both of them. It works ok. It measure the time difference between the 1st and 2nd edges, the 3rd and 4th, and so on. All that VI is inside a while loop to continuously perform the counting. May be I can simplify my question:
How can I continuously measure time difference between incoming edges (it could be a Boolean variable varying from true to false periodically) in a VI that already has a continuous process running?
As Altenbach said, I used a wait statement in the continuous process (as it is not necessary a fast data update for it, because it is just a simple temperature measurement), but that delay created some faulty timing in the edge timing sequence.
Any ideas?
Thanks again!
DMDsync -
Beginner timing program - triggering with photogates
Hello,
I am attempting to create a program in which I can time the sprint time of runners that break photogates, which are connected to channels on the measurement device. The idea is that once the photogate is broken, there is a voltage trigger that begins a timer, and the timer stops once the the next photogate trigger is broken (another voltage trigger). I have something very basic attached in which if a voltage threshold is surpassed (from one channel), a time is taken, and then potentially when the next threshold is surpassed, another time is taken, and perhaps the two times can be subtracted, but I can't seem to make this work out of the program, thus it is not quite exactly what I am looking for. I am very new to LabView and I think the solution might be simple, but I can't seem to work it out. Could you give me any suggestions?
Thanks for any help.
Attachments:
sprintspeed_timer2.vi 33 KBFor the program to do what you want you only have to have it remember all the times it triggered - in my example I used a shift register with an array for that.
There are a few things to be aware of (maybe more than I'll think of now):
1. Windows is not a real time OS - your measurement may be off by a couple of microseconds. If it has to be exact doing the timing in software will not suit you.
2. If you can live with that you still have to be careful with that timing VI. It counts to 2^32 - 1, and then it starts over. That might happen during the time you want to take.
Regards Florian
Attachments:
sprintspeed_timer2_array.vi 25 KB -
HELP - ABAP Program Cancelled After Running for 2.5 Hours in Background
I have an ABAP report program that was being tested in our QA system and it died after running for 2.5 hours with the status of "Cancelled" (which, I assume, means it was terminated by SAP for exceeding some type of governor).
I ran Code Analyzer and no performance issues were recognized.
I am running several SELECT statements during program execution. These are a list of all the SELECT statements used in my program. Also, I'm using PNPCE to get a list of pernrs for which to pull data at the beginning of the program.
SELECT *
INTO CORRESPONDING FIELDS OF TABLE gt_p0167
FROM pa0167
WHERE pernr EQ gt_selected_pernrs
AND bplan IN s_bplan
AND begda LE pn-endda
AND endda GE pn-begda.
SELECT SINGLE fgbdt fasex
INTO (lv_dob, lv_gender)
FROM pa0021
WHERE pernr EQ gt_selected_pernrs
AND subty EQ <fs_dtyxx>
AND objps EQ <fs_didxx>
AND begda LE pn-endda
AND endda GE pn-begda.
SELECT SINGLE agency ansvh
INTO (p_agency_out, lv_ansvh)
FROM pa0001
WHERE pernr EQ p_pernr_in
AND begda LE pn-endda
AND endda GE pn-begda.
SELECT SINGLE vorna nachn gbdat perid gesch
INTO (gt_control_table-fname, gt_control_table-lname, gt_control_table-dob, gt_control_table-mskssn, gt_control_table-gender)
FROM pa0002
WHERE pernr EQ p_pernr_in
AND begda LE pn-endda
AND endda GE pn-begda.
SELECT SINGLE perid
INTO (lv_ssn)
FROM pa0106
WHERE pernr EQ p_pernr_in
AND subty EQ p_subty_in
AND objps EQ p_objps_in
AND begda LE pn-endda
AND endda GE pn-begda.
SELECT SINGLE smoke
INTO (p_smoker_out)
FROM pa0376
WHERE pernr = p_pernr_in
AND begda LE pn-endda
AND endda GE pn-begda.
SELECT SINGLE state pstlz zcounty
INTO (p_state_out, lv_zip, p_county_out)
FROM pa0006
WHERE pernr EQ p_pernr_in
AND begda LE pn-endda
AND endda GE pn-begda.
SELECT SINGLE werks btrtl
INTO (lv_werks, lv_btrtl)
FROM pa0001
WHERE pernr EQ p_pernr_in
AND begda LE pn-endda
AND endda GE pn-begda.
SELECT SINGLE region
INTO (p_region_out)
FROM zpat_county_code
WHERE county EQ p_county_in.
SELECT SINGLE pernr
INTO lv_pernr
FROM pa0002
WHERE perid EQ gt_cobra_table-l_essn.
SELECT SINGLE eecst ercst
INTO (lv_eecst, lv_ercst)
FROM t5ubi
WHERE barea EQ '01'
AND bplan EQ lv_bplan
AND bcost EQ p_bcost_in
AND cstv1 EQ '0001'
AND smoke EQ p_smoker_in
AND begda LE pn-endda
AND endda GE pn-begda.
SELECT SINGLE kwert
INTO lv_kwert
FROM t511k
WHERE molga EQ '10'
AND konst EQ 'ZCOB1'
AND begda LE pn-endda
AND endda GE pn-begda.The screen shot the tester sent me only says that it was canceled. However, the log shows the following:
09/17/2008 16:54:32 Job Started
09/17/2008 16:54:32 Step 001 started (program ZBNI001...
09/17/2008 19:22:09 ABAP/4 processor: DATASET_NOT_OPEN
09/17/2008 19:22:09 Job cancelled
I'm not sure it was an error, per se, but maybe SAP canceled it because it had been running too long? The "DATASET_NOT_OPEN" is curious although I've no idea what it means.
Thanks for your help. -
Please help, java program terminating unexpectedly without reason
ok, so I have a project I'm working on, here's its description:
Create a new project named FML_Pig where F is your first initial, M is your middle initial, and L is your last initial. For example, if your name is Alfred Edward Neuman then you would name your project AEN_Pig. If necessary, add a new Java file to this project named FML_Pig.
Add a java file to the project named FML_Dice.
Design and implement a Dice class as follows. The Dice class has 2 twenty‑sided dice with numbers on the faces (1 � 20) and 2 twenty-six-sided dice with letters on the faces (a � z).
import java.util.Random;
public class FML_Dice
private static Random gen = new Random();
private final static int NUM_SIDES = 20;
private int die1, die2, numSnakeEyes, numVowels, totalPoints;
private char die3, die4;
Part 1
Add a rollDice() method to your FML_Dice class that sets die1 and die2 to a random number between 1 and 20 and it sets die3 and die4 to a random character between �a� and �z�.
Helpful Hint:
dice3 = (char)(�a� + gen.nextInt(26)); // sets dice3 to a random char between �a� and �z�.
Part 2
Write a constructor that sets die1 and die2 to a random number between 1 and 20 and it sets die3 and die4 to a random character. Your constructor can simply call rollDice() to do this. It should also initialize numSnakeEyes, numVowels, and totalPoints to 0 (after you roll the dice).
Part 3
Write methods getDie1(), getDie2(), getDie3(), and getDie4() that returns the value of the respective die. Write a method numSnakes() that returns the number of snake eyes that have been rolled. Write a method numVowels() that returns the number of vowels that have been rolled. Write a method totalPts() that returns the totalPoints.
Part 4
Write a toString() method that overwrites the default toString() method. It should return a String representation of the value of all 4 die. For example, 17 2 h w.
Part 5
Write a method updateTotals that updates numVowels, numSnakeEyes, and totalPoints based on the current values of die1, die2, die3, and die4. numVowels should be incremented by 1 if either die3 or die4 are a vowel. However, if both die3 and die4 are vowels, the totalPoints should be reset to 0 and numVowels should be reset to 0 also. numSnakeEyes should be incremented by 1 if either die1 or die2 have a face value of 1 (this is not truly a snake eyes, but it gives better odds for the game). totalPoints should be incremented by the sum of die1 and die2 multiplied by (numSnakeEyes + 1).
Part 6
Write a main program (use the one in FML_Pig.java) that plays a game of Pig. In this game, two people play against each other. Player1 begins by rolling the dice. The total of die1 and die2 is added to his total score. Player1�s turn continues until he/she rolls a total of 4 vowels then the turn switches to Player2. Whenever a turn switches to the other player, the number of vowels is reset to zero. Also, if at any time both die3 and die4 are vowels, the total score is reset to 0 and the turn switches to the other player. (So the turn switches to the other player whenever the total number of vowels reaches four or there are two vowels rolled at the same time.)
If a player rolls snakeeyes (for our game, snakeeyes occurs whenever either of the dice have a face value of one � in reality, both die1 and die2 should have a face value of one but then snakeeyes would occur only once every 400 rolls), then his point values are doubled from that point on (all future rolls for the rest of the game, point values for this player are doubled). When a player rolls snake eyes again, point values are tripled for that roll and all future rolls. (Three snake eyes, quadrupled, etc.)
(continued on the next page)
Be sure to display the results of the roll for each turn.
First player to get to 2000 points wins the game and gets to oink like a pig.
Note: Both players need their own set of Dice since the Dice keeps track of the totalPoints, the number of snake eyes rolled so far, and the number of vowels rolled so far for that particular player. You can do this simply by declaring it that way in the main program:
Dice player1 = new Dice();
Dice player2 = new Dice();
You may add additional methods and instance variables to the class as needed. For example, I would probably write a private helper method isVowel() that is passed a char argument ch and returns true if ch is a vowel.
Also, you can have the computer play for both player 1 and player 2. Simply loop it until somebody wins. Print out the result for each turn including who rolled the dice (player 1 or player 2), what they rolled, how many snakeeyes do they have, how many points did they get for this turn, and how many total points do they have.
When you are completely finished, hand in just the java files (FLM_Dice & FLM_Pig). If you happened to write any other classes, make sure they are named with the FML format, and turn these in as well. I do not need EasyReader or p.
Oink! Oink!
This pig won the game --------->
so here's my code:
this isn't my code but is required to compile my code: // package com.skylit.io;
import java.io.*;
* @author Gary Litvin
* @version 1.2, 5/30/02
* Written as part of
* <i>Java Methods: An Introduction to Object-Oriented Programming</i>
* (Skylight Publishing 2001, ISBN 0-9654853-7-4)
* and
* <i>Java Methods AB: Data Structures</i>
* (Skylight Publishing 2003, ISBN 0-9654853-1-5)
* EasyReader provides simple methods for reading the console and
* for opening and reading text files. All exceptions are handled
* inside the class and are hidden from the user.
* <xmp>
* Example:
* =======
* EasyReader console = new EasyReader();
* System.out.print("Enter input file name: ");
* String fileName = console.readLine();
* EasyReader inFile = new EasyReader(fileName);
* if (inFile.bad())
* System.err.println("Can't open " + fileName);
* System.exit(1);
* String firstLine = inFile.readLine();
* if (!inFile.eof()) // or: if (firstLine != null)
* System.out.println("The first line is : " + firstLine);
* System.out.print("Enter the maximum number of integers to read: ");
* int maxCount = console.readInt();
* int k, count = 0;
* while (count < maxCount && !inFile.eof())
* k = inFile.readInt();
* if (!inFile.eof())
* // process or store this number
* count++;
* inFile.close(); // optional
* System.out.println(count + " numbers read");
* </xmp>
public class EasyReader
protected String myFileName;
protected BufferedReader myInFile;
protected int myErrorFlags = 0;
protected static final int OPENERROR = 0x0001;
protected static final int CLOSEERROR = 0x0002;
protected static final int READERROR = 0x0004;
protected static final int EOF = 0x0100;
* Constructor. Prepares console (System.in) for reading
public EasyReader()
myFileName = null;
myErrorFlags = 0;
myInFile = new BufferedReader(
new InputStreamReader(System.in), 128);
* Constructor. opens a file for reading
* @param fileName the name or pathname of the file
public EasyReader(String fileName)
myFileName = fileName;
myErrorFlags = 0;
try
myInFile = new BufferedReader(new FileReader(fileName), 1024);
catch (FileNotFoundException e)
myErrorFlags |= OPENERROR;
myFileName = null;
* Closes the file
public void close()
if (myFileName == null)
return;
try
myInFile.close();
catch (IOException e)
System.err.println("Error closing " + myFileName + "\n");
myErrorFlags |= CLOSEERROR;
* Checks the status of the file
* @return true if en error occurred opening or reading the file,
* false otherwise
public boolean bad()
return myErrorFlags != 0;
* Checks the EOF status of the file
* @return true if EOF was encountered in the previous read
* operation, false otherwise
public boolean eof()
return (myErrorFlags & EOF) != 0;
private boolean ready() throws IOException
return myFileName == null || myInFile.ready();
* Reads the next character from a file (any character including
* a space or a newline character).
* @return character read or <code>null</code> character
* (Unicode 0) if trying to read beyond the EOF
public char readChar()
char ch = '\u0000';
try
if (ready())
ch = (char)myInFile.read();
catch (IOException e)
if (myFileName != null)
System.err.println("Error reading " + myFileName + "\n");
myErrorFlags |= READERROR;
if (ch == '\u0000')
myErrorFlags |= EOF;
return ch;
* Reads from the current position in the file up to and including
* the next newline character. The newline character is thrown away
* @return the read string (excluding the newline character) or
* null if trying to read beyond the EOF
public String readLine()
String s = null;
try
s = myInFile.readLine();
catch (IOException e)
if (myFileName != null)
System.err.println("Error reading " + myFileName + "\n");
myErrorFlags |= READERROR;
if (s == null)
myErrorFlags |= EOF;
return s;
* Skips whitespace and reads the next word (a string of consecutive
* non-whitespace characters (up to but excluding the next space,
* newline, etc.)
* @return the read string or null if trying to read beyond the EOF
public String readWord()
StringBuffer buffer = new StringBuffer(128);
char ch = ' ';
int count = 0;
String s = null;
try
while (ready() && Character.isWhitespace(ch))
ch = (char)myInFile.read();
while (ready() && !Character.isWhitespace(ch))
count++;
buffer.append(ch);
myInFile.mark(1);
ch = (char)myInFile.read();
if (count > 0)
myInFile.reset();
s = buffer.toString();
else
myErrorFlags |= EOF;
catch (IOException e)
if (myFileName != null)
System.err.println("Error reading " + myFileName + "\n");
myErrorFlags |= READERROR;
return s;
* Reads the next integer (without validating its format)
* @return the integer read or 0 if trying to read beyond the EOF
public int readInt()
String s = readWord();
if (s != null)
return Integer.parseInt(s);
else
return 0;
* Reads the next double (without validating its format)
* @return the number read or 0 if trying to read beyond the EOF
public double readDouble()
String s = readWord();
if (s != null)
return Double.parseDouble(s);
// in Java 1, use: return Double.valueOf(s).doubleValue();
else
return 0.0;
}same with this:
public class p
public static void l(String S)
{ System.out.println(S);}
public static void o(String S)
{System.out.print(S);}
public static void l(int i)
{ System.out.println(i);}
public static void o(int i)
{System.out.print(i);}
public static void l(boolean b)
{ System.out.println(b);}
public static void o(boolean b)
{System.out.print(b);}
public static void l(char c)
{ System.out.println(c);}
public static void o(char c)
{System.out.print(c);}
public static void l(double d)
{ System.out.println(d);}
public static void o(double d)
{System.out.print(d);}
public static void l(Object obj)
{ System.out.println(obj.toString());}
public static void o(Object obj)
{System.out.print(obj.toString());}
public static void l()
{System.out.println();}
} here's my code:
import java.util.*;
public class JMM_Pig
public static void main(String[] args)
int winner=0;
int pts=0;
JMM_Dice player1=new JMM_Dice();
JMM_Dice player2=new JMM_Dice();
p.l("Player 1 rolls the dice...");
player1.rollDice();
player1.updateTotals();
boolean loop=true;
while(loop)
while(player1.numVowels()<=4)
p.l("Player 1 continues his turn...");
player1.rollDice();
player1.updateTotals();
p.l("Player 1 rolled a "+player1.getDie1()+" and a "+player1.getDie2()+" and a '"+player1.getDie3()+"' and a '"+player1.getDie4()+"'");
p.l("Player 1 rolled "+player1.currvowels()+" vowels.");
p.l("Player 1 has "+player1.totalvowels()+" total vowels.");
//if(player1.getMagic()==1)
//player1.totalPoints=(player1.totalPoints+player1.getDie1()+player1.getDie2())*player1.mult;
//pts=(player1.totalPts()+player1.getDie1()+player1.getDie2())*player1.getMult();
//player1.setTpts(pts);
//if(player1.getMagic()!=1)
//player1.totalPoints=player1.totalPoints+player1.getDie1()+player1.getDie2();
//pts=player1.totalPts()+player1.getDie1()+player1.getDie2();
//player1.setTpts(pts);
p.l("Player 1 has "+player1.numSnakes()+" snake eyes.");
p.l("Player 1 earned "+player1.ptsreturn()+" points this turn.");
p.l("Player 1 has "+player1.totalPts()+" total points.");
pts=0;
if(player1.totalPts()>=2000)
winner=1;
player1.setNv(4);loop=false;
if((player1.isavowel(player1.getadice()))&&player1.isavowel(player1.getadice2()))
player1.setTpts(0);player1.setNv(0);player1.setNv(4);
p.l("Player 1's turn has ended...");
player1.setNv(0);
p.l("Player 2 rolls the dice...");
player2.rollDice();
player2.setTpts(player2.totalPts()+player2.getDie1()+player2.getDie2());
while(player2.numVowels()<=4)
p.l("Player 2 continues his turn...");
player2.rollDice();
player2.updateTotals();
p.l("Player 2 rolled a "+player2.getDie1()+" and a "+player2.getDie2()+" and a '"+player2.getDie3()+"' and a '"+player2.getDie4()+"'");
p.l("Player 2 rolled "+player2.currvowels()+" vowels.");
p.l("Player 2 has "+player2.totalvowels()+" total vowels.");
//if(player1.getMagic()==1)
//player1.totalPoints=(player1.totalPoints+player1.getDie1()+player1.getDie2())*player1.mult;
//pts=(player1.totalPts()+player1.getDie1()+player1.getDie2())*player1.getMult();
//player1.setTpts(pts);
//if(player1.getMagic()!=1)
//player1.totalPoints=player1.totalPoints+player1.getDie1()+player1.getDie2();
//pts=player1.totalPts()+player1.getDie1()+player1.getDie2();
//player1.setTpts(pts);
p.l("Player 2 has "+player2.numSnakes()+" snake eyes.");
p.l("Player 2 earned "+player2.ptsreturn()+" points this turn.");
p.l("Player 2 has "+player2.totalPts()+" total points.");
pts=0;
if(player2.totalPts()>=2000)
winner=2;
player2.setNv(4);loop=false;
if((player2.isavowel(player2.getadice()))&&player2.isavowel(player2.getadice2()))
player2.setTpts(0);player2.setNv(0);player2.setNv(4);
p.l("Player 2's turn has ended...");
player2.setNv(0);
if(player1.totalPts()>=2000)
winner=1;
loop=false;
if(player2.totalPts()>=2000)
winner=2;
loop=false;
} //main loop
if(winner==1)
p.l("It ended with the following statistics...");
p.l("Player 1's score was: "+player1.totalPts()+" and Player 2's score was: "+player2.totalPts());
p.l("Player 1 had: "+player1.numSnakes()+" snake eye(s) and Player 2 had: "+player2.numSnakes()+" snake eye(s)");
p.l("Player 1 wins, oink oink!");
if(winner==2)
p.l("It ended with the following statistics...");
p.l("Player 1's score was: "+player1.totalPts()+" and Player 2's score was: "+player2.totalPts());
p.l("Player 1 had: "+player1.numSnakes()+" snake eye(s) and Player 2 had: "+player2.numSnakes()+" snake eye(s)");
p.l("Player 2 wins, oink oink!");
and dice class:
import java.util.*;
public class JMM_Dice {
private static Random gen = new Random();
private final static int NUM_SIDES = 21;
private int die1, die2, numSnakeEyes, numVowels, totalPoints;
private char die3, die4;
private int dice=0;
//dice=
private int dice2=0;
//dice2=;
private String adice="";
//adice=;
private String adice2="";
//adice2;
private int magic=0;
private int mult=0;
private int currvowels=0;
private int totalvowels=0;
public static EasyReader key = new EasyReader();
public JMM_Dice()
dice=0;dice2=0;
String alpha="abcdefghijklmnopqrstuvwxyz";
adice="";adice2="";
rollDice();
numSnakeEyes=0;numVowels=0;totalPoints=0;
public void setTpts(int tpts)
this.totalPoints=tpts;
public void setNv(int nv)
this.numVowels=nv;
public int getDie1()
return dice;
public int getDie2()
return dice2;
public String getDie3()
return adice;
public String getDie4()
return adice2;
public int numSnakes()
return numSnakeEyes;
public void setSnakes(int s)
this.numSnakeEyes=s;
public String getadice()
return this.adice;
public String getadice2()
return this.adice2;
public int numVowels()
return numVowels;
public int getMagic()
return this.magic;
public int getNv()
return this.numVowels;
public void setMagic(int mag)
this.magic=mag;
public int getMult()
return this.mult;
public void setMult(int m)
this.mult=m;
public int totalPts()
return totalPoints;
public String toString()
return dice+""+dice2+""+adice+""+adice2;
public boolean isavowel(String str)
if(str.equals("a")||str.equals("e")||str.equals("i")||str.equals("o")||str.equals("u"))
return true;
else
return false;
public int ptsreturn()
return dice+dice2;
public int currvowels()
int tmp=currvowels;
currvowels=0;
return tmp;
public int totalvowels()
return numVowels;
public void updateTotals()
if(adice.equalsIgnoreCase("a")||adice.equalsIgnoreCase("e")||adice.equalsIgnoreCase("i")||adice.equalsIgnoreCase("o")||adice.equalsIgnoreCase("u")||adice2.equalsIgnoreCase("a")||adice2.equalsIgnoreCase("e")||adice2.equalsIgnoreCase("i")||adice2.equalsIgnoreCase("o")||adice2.equalsIgnoreCase("u"))
numVowels++;currvowels++;
if((isavowel(adice))&&isavowel(adice2))
totalPoints=0;numVowels=0;
if(dice==1||dice2==1)
numSnakeEyes++;
int fd=dice;
int sd=dice2;
int sum=fd+sd;
totalPoints+=sum*(numSnakeEyes+1);
public void rollDice()
dice=gen.nextInt(20)+1;
dice2=gen.nextInt(20)+1;
String alpha="abcdefghijklmnopqrstuvwxyz";
adice=String.valueOf(alpha.charAt(gen.nextInt(26)));
adice2=String.valueOf(alpha.charAt(gen.nextInt(26)));
public static void sleep (int wait)
{ long timeToQuit = System.currentTimeMillis() + wait;
while (System.currentTimeMillis() < timeToQuit)
; // take no action
}the program works fine except it's supposed to terminate when one of the two AIs get a score of 2000, right now it terminates no matter what score the AIs get and no matter what I've tried to do it keeps doing that...can someone please tell me why it's terminating so oddly? Thanks! :)Here's how my code works in a nutshell, the main program starts with the boolean loop=true;
while(loop)
{then comes the loops for the two AIs, first the player 1 AI goes with this loop: while(player1.numVowels()<=4)
{there the player 1 roles the dice and it keeps going until player 1 gets a total of 2000 points at which time this is supposed to execute: if(player1.totalPts()>=2000)
winner=1;
player1.setNv(4);loop=false;
}, player1.setNv(4); sets numVowels to 4 so that the inner loop exits, loop=false exits the other loop and winner=1; specifies that player 1 won which is used outside of the loops here: if(winner==1)
p.l("It ended with the following statistics...");
p.l("Player 1's score was: "+player1.totalPts()+" and Player 2's score was: "+player2.totalPts());
p.l("Player 1 had: "+player1.numSnakes()+" snake eye(s) and Player 2 had: "+player2.numSnakes()+" snake eye(s)");
p.l("Player 1 wins, oink oink!");
if(winner==2)
p.l("It ended with the following statistics...");
p.l("Player 1's score was: "+player1.totalPts()+" and Player 2's score was: "+player2.totalPts());
p.l("Player 1 had: "+player1.numSnakes()+" snake eye(s) and Player 2 had: "+player2.numSnakes()+" snake eye(s)");
p.l("Player 2 wins, oink oink!");
} the same thing happens for player 2 if player 1 didn't already get 2000 points...but the if statement despite everything pointing to the variables containing the right values don't seem to be working, as shown by the example program output I posted it just ends at any random number...hopefully this helps make figuring out what's wrong easier :) ...so can anyone please help me out? thanks! :) -
Urgent please help, this program should work
Urgent please help.
I need to solve or I will be in big trouble.
This program works at my home computer which is not networked.
The hard disk was put onto another computer at another location whihc is networked. Here my program worked on Monday 14 october but since for the last two days it is not working without me changing any code. Why do I receive this error message???
Error: 500
Location: /myJSPs/jsp/portal-project2/processviewfiles_dir.jsp
Internal Servlet Error:
javax.servlet.ServletException
at org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:460)
at jsp.portal_0002dproject2.processviewfiles_dir_1._jspService(processviewfiles_dir_1.java:162)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:119)
at javax.servlet.http.HttpServlet.service(HttpServlet.java)
at org.apache.tomcat.facade.ServletHandler.doService(ServletHandler.java:574)
at org.apache.tomcat.core.Handler.invoke(Handler.java:322)
at org.apache.tomcat.core.Handler.service(Handler.java:235)
at org.apache.tomcat.facade.ServletHandler.service(ServletHandler.java:485)
at org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:917)
at org.apache.tomcat.core.ContextManager.service(ContextManager.java:833)
at org.apache.tomcat.modules.server.Http10Interceptor.processConnection(Http10Interceptor.java:176)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:494)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:516)
at java.lang.Thread.run(Thread.java:536)
Root cause:
java.lang.NullPointerException
at jsp.portal_0002dproject2.processviewfiles_dir_1._jspService(processviewfiles_dir_1.java:132)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:119)
at javax.servlet.http.HttpServlet.service(HttpServlet.java)
at org.apache.tomcat.facade.ServletHandler.doService(ServletHandler.java:574)
at org.apache.tomcat.core.Handler.invoke(Handler.java:322)
at org.apache.tomcat.core.Handler.service(Handler.java:235)
at org.apache.tomcat.facade.ServletHandler.service(ServletHandler.java:485)
at org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:917)
at org.apache.tomcat.core.ContextManager.service(ContextManager.java:833)
at org.apache.tomcat.modules.server.Http10Interceptor.processConnection(Http10Interceptor.java:176)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:494)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:516)
at java.lang.Thread.run(Thread.java:536)foolishmatt,
The code is quit large.
to understand the program I think all the code needs to be examined.
I would need to send to you in an email.
Here is my e-mail
[email protected]
if you contact me than I can send the code to you.
Thank you in advance. -
Need help with program for Inner join
Hello Experts,
I need to create a list from table sbook containing booking number (sbook-bookid), customer number (sbook-customid), customer name (scustom-name) , customer class (sbook-class) and ticket price (sflight-price). I am new to ABAP and am very confused I tried reading up some examples and came up with the attached program
Attached is my program for inner join
Kindly Help
Thanks SuHi Su K
You May use key fields , Foreign keys for joining , Here
SELECT SBOOK~BOOKID SBOOK~CUSTOMID SBOOK~CLASS
SCUSTOM~ID SCUSTOM~NAME FROM SFILGHT
INNER JOIN SBOOK ON SBOOK~CARRID EQ SFILGHT~CARRID
SBOOK~CONNID EQ SFILGHT~CONNID
SBOOK~FLDATE EQ SFILGHT~FLDATE
INNER JOIN SCUSTOM ON SCUSTOM~ID = SBOOK~ID -
Hi everybody,
I designed a calculator, and I need help with the rest of the scientific actions. I know I need to use the different Math methods, but what exactly? Also, it needs to work as an applet and application, and in the applet, the buttons don't appear in order, how can I fix that?
I will really appreciate your help with this program, I need to finish it ASAP. Please e-mail me at [email protected].
Below is the code for the calcualtor.
Thanks in advance,
-Maria
// calculator
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;
public class calculator extends JApplet implements
ActionListener
private JButton one, two, three, four, five, six, seven,
eight, nine, zero, dec, eq, plus, minus, mult, div, clear,
mem, mrc, sin, cos, tan, asin, acos, atan, x2, sqrt, exp, pi, percent;
private JLabel output, blank;
private Container container;
private String operation;
private double number1, number2, result;
private boolean clear = false;
//GUI
public void init()
container = getContentPane();
//Title
//super("Calculator");
JPanel container = new JPanel();
container.setLayout( new FlowLayout( FlowLayout.CENTER
output = new JLabel("");
output.setBorder(new MatteBorder(2,2,2,2,Color.gray));
output.setPreferredSize(new Dimension(1,26));
getContentPane().setBackground(Color.white);
getContentPane().add( "North",output );
getContentPane().add( "Center",container );
//blank
blank = new JLabel( " " );
container.add( blank );
//clear
clear = new JButton( "CE" );
clear.addActionListener(this);
container.add( clear );
//seven
seven = new JButton( "7" );
seven.addActionListener(this);
container.add( seven );
//eight
eight = new JButton( "8" );
eight.addActionListener(this);
container.add( eight );
//nine
nine = new JButton( "9" );
nine.addActionListener(this);
container.add( nine );
//div
div = new JButton( "/" );
div.addActionListener(this);
container.add( div );
//four
four = new JButton( "4" );
four.addActionListener(this);
container.add( four );
//five
five = new JButton( "5" );
five.addActionListener(this);
container.add( five );
//six
six = new JButton( "6" );
six.addActionListener(this);
container.add( six );
//mult
mult = new JButton( "*" );
mult.addActionListener(this);
container.add( mult );
//one
one = new JButton( "1" );
one.addActionListener(this);
container.add( one );
//two
two = new JButton( "2" );
two.addActionListener(this);
container.add( two );
//three
three = new JButton( "3" );
three.addActionListener(this);
container.add( three );
//minus
minus = new JButton( "-" );
minus.addActionListener(this);
container.add( minus );
//zero
zero = new JButton( "0" );
zero.addActionListener(this);
container.add( zero );
//dec
dec = new JButton( "." );
dec.addActionListener(this);
container.add( dec );
//plus
plus = new JButton( "+" );
plus.addActionListener(this);
container.add( plus );
//mem
mem = new JButton( "MEM" );
mem.addActionListener(this);
container.add( mem );
//mrc
mrc = new JButton( "MRC" );
mrc.addActionListener(this);
container.add( mrc );
//sin
sin = new JButton( "SIN" );
sin.addActionListener(this);
container.add( sin );
//cos
cos = new JButton( "COS" );
cos.addActionListener(this);
container.add( cos );
//tan
tan = new JButton( "TAN" );
tan.addActionListener(this);
container.add( tan );
//asin
asin = new JButton( "ASIN" );
asin.addActionListener(this);
container.add( asin );
//acos
acos = new JButton( "ACOS" );
cos.addActionListener(this);
container.add( cos );
//atan
atan = new JButton( "ATAN" );
atan.addActionListener(this);
container.add( atan );
//x2
x2 = new JButton( "X2" );
x2.addActionListener(this);
container.add( x2 );
//sqrt
sqrt = new JButton( "SQRT" );
sqrt.addActionListener(this);
container.add( sqrt );
//exp
exp = new JButton( "EXP" );
exp.addActionListener(this);
container.add( exp );
//pi
pi = new JButton( "PI" );
pi.addActionListener(this);
container.add( pi );
//percent
percent = new JButton( "%" );
percent.addActionListener(this);
container.add( percent );
//eq
eq = new JButton( "=" );
eq.addActionListener(this);
container.add( eq );
//Set size and visible
setSize( 190, 285 );
setVisible( true );
public static void main(String args[]){
//execute applet as application
//applet's window
JFrame applicationWindow = new JFrame("calculator");
applicationWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//applet instance
calculator appletObject = new calculator();
//init and start methods
appletObject.init();
appletObject.start();
} // end main
public void actionPerformed(ActionEvent ae)
JButton but = ( JButton )ae.getSource();
//dec action
if( but.getText() == "." )
//if dec is pressed, first check to make shure there
is not already a decimal
String temp = output.getText();
if( temp.indexOf( '.' ) == -1 )
output.setText( output.getText() + but.getText() );
//clear action
else if( but.getText() == "CE" )
output.setText( "" );
operation = "";
number1 = 0.0;
number2 = 0.0;
//plus action
else if( but.getText() == "+" )
operation = "+";
number1 = Double.parseDouble( output.getText() );
clear = true;
//output.setText( "" );
//minus action
else if( but.getText() == "-" )
operation = "-";
number1 = Double.parseDouble( output.getText() );
clear = true;
//output.setText( "" );
//mult action
else if( but.getText() == "*" )
operation = "*";
number1 = Double.parseDouble( output.getText() );
clear = true;
//output.setText( "" );
//div action
else if( but.getText() == "/" )
operation = "/";
number1 = Double.parseDouble( output.getText() );
clear = true;
//output.setText( "" );
//eq action
else if( but.getText() == "=" )
number2 = Double.parseDouble( output.getText() );
if( operation == "+" )
result = number1 + number2;
else if( operation == "-" )
result = number1 - number2;
else if( operation == "*" )
result = number1 * number2;
else if( operation == "/" )
result = number1 / number2;
//output result
output.setText( String.valueOf( result ) );
clear = true;
operation = "";
//default action
else
if( clear == true )
output.setText( "" );
clear = false;
output.setText( output.getText() + but.getText() );Multiple post:
http://forum.java.sun.com/thread.jsp?forum=31&thread=474370&tstart=0&trange=30
Maybe you are looking for
-
How do i make an mp3 cd with iTunes?
I have a CD player in my car that plays mp3 files burnt to CDs. I used to use Realplayer to burn mp3 cds, but in order to do that you have to subscribe to their service (you can always burn a CD that has maybe 20 files on it, but the mp3 CDs I woul
-
Why are my images coming out of CS5 Photoshop granulated and pixelated after saving?
I am new to CS5 Design Premium. I use a Canon 50D and shoot in RAW format. I upload my pictures into Bridge and do most of my editing in Camera Raw, then I open the object into Photoshop where I save the image into a folder. I save each image as a .p
-
Dear all, r12.0.4. solaris 5.10 bash-3.00$ which pdf2ps /usr/bin/pdf2ps I can able to print text files in the printer properly. When am printing PDF files am getting the error : PDF Files not printed 128mb Of Memory Is Required To Enable Direct Print
-
I use mobility pack visual designer. When I create a string item in visual screen designer it looks like that: Title <text> but after i run my app it looks different Title <text> Why there's no line break? When I try to add the line break manually it
-
In CS3, making layer in still photo
Which technique works best to cut an image from a photo to build a layer for animation? If Photoshop which tool cuts the image and which function turn it into layer? If AE, then same question. I can't find topic in training video.