Why don't you just trigger releases when the button on your controller is released?
[QUOTE=joshuadim;45942735]
Ok so for generating random letters for option 1 in my program, would this
--
be correct?
[/quote]
Yes.
[quote]Also, how would I print out all the chars that were randomly generated?[/QUOTE]
You can print the characters as you generate them with [url=http://docs.oracle.com/javase/7/docs/api/java/io/PrintStream.html#print(char)]System.out.print(char c)[/url].
Or you can put them into a char array during your loop, then make a String from that char array, and print that string.
And there are countless other ways.
You should really get a good, in-depth book/tutorial, as well as figure out how to Google this stuff yourself - it's an essential skill for programming.
[QUOTE=DrTaxi;45943251]Why don't you just trigger releases when the button on your controller is released?
...[/QUOTE]
I'm using JoyToKey which maps the controller to the keyboard of my laptop and i'm not sure yet if it makes a separate key press each time or if it actually holds a key.
Probably should have checked that sooner.
[CODE]if (GetAsyncKeyState (VK_UP) & 0x1)
{
// Tell the server to hold the key down until further notice
}
else
{
// Tell the server that the key has been released
}
[/CODE]
Would that be a good way to do it?
I'm a bit confused, what exactly is it you're writing if you already have a keyboard emulator (JoyToKey)?
bump
[QUOTE]
Ok so for generating random letters for option 1 in my program, would this
[code]
if(selectionNumber == 1)
{
for(int generating = 0; generating <= passwordLength; generating++)
{
char random = (char)(rn.nextInt(26) + 'a');
}
System.out.println();
}
[/code]
be correct?
Also, how would I print out all the chars that were randomly generated?[/QUOTE]
[QUOTE=joshuadim;45943794]bump[/QUOTE]
Not a java programmer, but, just after you generate it?
[code]
System.out.print(random);
[/code]
[QUOTE=DrTaxi;45943721]I'm a bit confused, what exactly is it you're writing if you already have a keyboard emulator (JoyToKey)?[/QUOTE]
I wanted to make something so i could hook my ps2 controller to my pc (i'd rather do it myself then buy an adapter).
I had to use my craptop which can't run emulator's (my desktop can).
This is what i got:
-My PS2 controller is hooked to my laptop via the parallel port.
-The driver needs a parallel port with a I/O address so i had to install it on my laptop as well (unless there's a decent way to share that port over lan, but i couldn't find it).
-The driver shows the controller as a game-pad in windows.
-I couldn't find a way to read the controller's buttons in C++ so i mapped them to the keyboard with JoyToKey
-Next i needed to send the buttons to my desktop which i did via a old client-server Raknet program i still had the source of (the code looks bad + there's some stuff i don't use, but it works).
-Then my desktop simulates the key pressed so i can bind them in whatev emulator i wan't to use.
Seems like JoyToKey is giving me seperate key pressed when holding down a button though.
I'm writing a method that will insert to an ordered array of a fixed size, but if the array is at full capacity, it will create a new array with twice the capacity and copy over everything then insert. So I have something like this
[code]if (currentSize == 0) {
arr[0] = x;
currentSize++;
}
else if (currentSize == arr.length) {
//code to copy array
//code to insert
}
else
//code to insert
[/code]
The code to insert is quite lengthy and I'm not allowed to add addition methods, so is my only option to write the same code twice?
[QUOTE=frdrckk;45941078]The university that I attend gave out the sixth edition of Deitel's C: How to program, is this a good book for a complete beginner?
Are there better books that I should read instead?[/QUOTE]
Thats what Im using, except the Seventh Edition. It seems pretty good.
[url=http://facepunch.com/showthread.php?t=1250112&p=45951979#post45951979]asking again here because i think i'll get a quicker response[/url]
how do i get into LaTeX? where do i start?
[QUOTE=wlitsots;45945801]I'm writing a method that will insert to an ordered array of a fixed size, but if the array is at full capacity, it will create a new array with twice the capacity and copy over everything then insert. So I have something like this
[code]if (currentSize == 0) {
arr[0] = x;
currentSize++;
}
else if (currentSize == arr.length) {
//code to copy array
//code to insert
}
else
//code to insert
[/code]
The code to insert is quite lengthy and I'm not allowed to add addition methods, so is my only option to write the same code twice?[/QUOTE]
[code]
if (currentSize == 0) {
arr[0] = x;
currentSize++;
}
else {
if (currentSize == arr.length) {
//code to copy array
}
//code to insert
}
[/code]
Assuming "code to insert" is the same in both cases, that is.
So I'm about to order a bunch of college stuff off Amazon, and before I commit to buying anything I was thinking of getting a book about programming.
I've worked primarily with C writing basic robotics code so I feel most comfortable with the syntax of that, so I was thinking of getting a book for C#. Do you guys have any recommendations?
Also thinking of getting a book for Unity but with Unity 5 coming I might wait a bit
[editline]edit[/editline]
[URL="http://www.amazon.com/The-Players-Guide-RB-Whitaker/dp/0985580100/ref=lh_ni_t?ie=UTF8&psc=1&smid=ATVPDKIKX0DER"]thinking of this[/URL] right now
Hey FP, I'm in my last year of high school and signed up for a computer science course. I really want to learn computer science but I did incredibly poorly on my first unit, despite my best efforts in class. We're currently learning to write Java, are there any resources or advice you guys can offer to help me be less terrible?
[thumb]http://33.media.tumblr.com/de41907dae623b24684d6865f874152f/tumblr_nbrhoybIa81sjt4neo1_500.png[/thumb]
(My grades to indicate how not awesome I've been doing.)
[QUOTE=Lovely Leslie;45956126]Hey FP, I'm in my last year of high school and signed up for a computer science course. I really want to learn computer science but I did incredibly poorly on my first unit, despite my best efforts in class. We're currently learning to write Java, are there any resources or advice you guys can offer to help me be less terrible?
[thumb]http://33.media.tumblr.com/de41907dae623b24684d6865f874152f/tumblr_nbrhoybIa81sjt4neo1_500.png[/thumb]
(My grades to indicate how not awesome I've been doing.)[/QUOTE]
It would be more helpful if you could post the questions you've gotten wrong, cause then we'd know what it is that you're not getting. Like maybe which questions you got wrong on the test?
Can someone explain this?
[code]
public void insert(String s) {
array[currentSize++] = s;
}
[/code]
It adds to the end of the array and increments currentSize at the same time but I don't get how it works.
[QUOTE=wlitsots;45957286]Can someone explain this?
[code]
public void insert(String s) {
array[currentSize++] = s;
}
[/code]
It adds to the end of the array and increments currentSize at the same time but I don't get how it works.[/QUOTE]
Well currentSize++ is a variable which is being used as a counter and I'm going to assume you have it declared as a field outside the method; currentSize will determine the index of the array, aka, the position at which the array is at. s is the parameter you defined in the method and you are assigning it to the current position.
Say we initialize currentSize to 0; we start at position 0 of the array and assign whatever value was passed in insert(string) to that position. Hope it helps ;)
[QUOTE=wlitsots;45957286]Can someone explain this?
[code]
public void insert(String s) {
array[currentSize++] = s;
}
[/code]
It adds to the end of the array and increments currentSize at the same time but I don't get how it works.[/QUOTE]
The ++ operator is applied to currentSize. This will increase the value of currentSize by 1 but the expression as a whole will yield the [B]old[/B] value of currentSize, before it was incremented. This value is then used for the index of the array.
So if we start with an empty array and currentSize with value 0, then calling the function will:
1. Increase currentSize to 1
2. Access array at old index 0
3. Store s at that index
Calling it again will:
1. Increase currentSize to 2
2. Access array at old index 1
3. Store s at that index
And so on.
nope nothing then?
Is it worth virtualizing a copy of windows on my laptop to run the LC-3 simulator?
What's good for vmware?
Just take whatever, VMware has an unattended install feature now so you don't even have to do anything (beyond downloading a sensible browser and turning off "Hide file types for known extensions").
I want to make a creepy screensaver to scare a friend.
It needs to display one image most of the time, and flash another image at random.
Also the second image is a gif.
It would appear I have to write my own screensaver, and Google search has failed me this time.
-snip-
Ok so I'm making a heat index program that calculates the heat index of an area by using data from txt files.
[code]
import java.util.Scanner;
import java.io.File;
import java.io.IOException;
public class HeatIndex
{
public static void main(String[] args) throws IOException
{
//initialize and declare vars
String location = "Key West, Florida";
File fileNameTemp = new File("KeyWestTemp.txt");
File fileNameHumid = new File("KeyWestHumid.txt");
Scanner inFileTemp = new Scanner(fileNameTemp);
Scanner inFileHumid = new Scanner(fileNameHumid);
String [] month = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "Novermber", "December"};
int length = month.length;
double [] temperature = new double[length];
int [] humidity = new int[length];
double [] hI = new double[length];
//INPUT - read in data for temp and humidity from files
int n = 0; //index value for arrays
while( inFileTemp.hasNextDouble() )
{
temperature[n] = inFileTemp.nextDouble( );
//System.out.println (temperature[n]); //debug statement - uncomment to see values assignned to temperature
n++;
}
inFileTemp.close();
n = 0; //reset index to 0
while (inFileHumid.hasNextDouble())
{
humidity[n] = inFileHumid.nextInt( );
//System.out.println (humidity[n]); //debug statement - uncomment to see values assignned to humidity
n++;
}
inFileHumid.close();
//PROCESSING - calculate Heat Index if needed- see lecture notes for details, formula is incomplete
double t = 0.0;
int h = 0;
for(n = 0; n < hI.length; n++)
{
if( temperature[n] >= 80.0 ) //determine if HI should be calculated, complete the condition based on Lecture notes
{
t = temperature[n];
h = humidity[n];
hI[n] = -42.379 + (2.04901523 * t) + (10.14333127 * h) - (0.22475541 * t * h) - (0.00683783 * (t * t)) - (0.05481717 * (h * h)) + (0.00122874 * (t * t) * h) + (0.00086282 * t * (h * h)) - (0.00000199 * (t * t) * (h * h)); //complete formula found in lecture notes
}
else // HI is the temperature value
{
hI[n] = temperature[n];
}
}
//calculate averages for temperature, humidity and HI
double tempSum = 0.0;
int humidSum = 0;
double hISum = 0.0;
for(n = 0; n < temperature.length; n++)
{
tempSum += temperature[n];
}
double tempAvg = tempSum/temperature.length;
//OUTPUT - print table. Use enhanced for loops to print the months, temp, humidity and HI
System.out.printf(" Heat Index: %15s \n ", location);
System.out.println();
System.out.print("Months ");
for(String m : month)
{
System.out.printf(" %3.3s", m);
}
System.out.println(" Avg");
System.out.println("******************************************************************************************");
System.out.print("Temp (F) ");
for(int index = 0; index <= 11; index++)
{
System.out.print(" " + temperature[index]);
//for:each loop to print temperature
}
//print average
System.out.println();
System.out.print("Humidity (%) ");
for(int index = 0; index <= 11; index++)
{
System.out.print(" " + humidity[index] + " ");
//for:each loop to print humidity
}
System.out.println();
System.out.print("HI(F) ");
for(int index = 0; index <= 11; index++)
{
System.out.printf(" " + hI[index]);
//for:each loop to print HI
}
System.out.println();
} //end main()
}//end HeatIndex
[/code]
The output I'm trying to get is this:
[IMG]http://puu.sh/bz16B/3f72621079.png[/IMG]
But I keep getting this:
[IMG]http://puu.sh/bz1b9/d63953ac45.png[/IMG]
It seems like my code for the equation for calculating the Heat Index but I don't know how it's wrong?
Also, I can't for the life of me figure out how to format with printf.
Can someone help me? Thanks
For the HI(F) line, you would want printf formatted something like:
[code]System.out.printf("%8.2lf", hI[index]);[/code]
Where %8.2 is saying you want each number to be printed in a field 8 characters wide, right aligned, with 2 numbers after the decimal point. The type you are formatting is a long float, (double). You'll have to tweak the values to get it to layout right for your program.
[QUOTE=Veers;45979912]For the HI(F) line, you would want printf formatted something like:
[code]System.out.printf("%8.2lf", hI[index]);[/code]
Where %8.2 is saying you want each number to be printed in a field 8 characters wide, right aligned, with 2 numbers after the decimal point. The type you are formatting is a long float, (double). You'll have to tweak the values to get it to layout right for your program.[/QUOTE]
so 8 is for 8 characters wide with .2 being 2 numbers after the deicmal? and lf means long float?
[editline]14th September 2014[/editline]
What does the % mean in printf btw?
[editline]14th September 2014[/editline]
Also how would I convert the current for loops I have for printing out the data to for-each loops?
[QUOTE=joshuadim;45980083]so 8 is for 8 characters wide with .2 being 2 numbers after the deicmal? and lf means long float?
[editline]14th September 2014[/editline]
What does the % mean in printf btw?[/QUOTE]
All that is true. The % is just an indicator that we are going to be placing some variable into the output string.
[QUOTE=joshuadim;45980083]What does the % mean in printf btw?[/QUOTE]
The percentage sign is simply an indicator for a format specification - see [URL="http://docs.oracle.com/javase/tutorial/java/data/numberformat.html"]here.[/URL] For instance, '%d' is for an integer, '%f' for a double or float, etcetera.
Oops, looks like Veers answered this above me.
[QUOTE=joshuadim;45980083]Also how would I convert the current for loops I have for printing out the data to for-each loops?[/QUOTE]
Relatively easily. For example:
[code]
for(int index = 0; index <= 11; index++)
{
System.out.print(" " + temperature[index]);
//for:each loop to print temperature
}
[/code]
...would become...
[code]
for (double currentTemperature : temperature)
{
System.out.print(" " + currentTemperature);
}
[/code]
...and so forth.
thanks guys :)
[editline]14th September 2014[/editline]
Damn.
Well, for the printf, it says that this
[code]System.out.printf(" %8.2lf ", currentTemperature);[/code]
is an error because of unknown format or whatever
[editline]14th September 2014[/editline]
Any ideas why this is happening?
[editline]14th September 2014[/editline]
Never mind I got rid of the l and that seems to work.
[editline]14th September 2014[/editline]
What would the printf statement be for printing our an integer?
Would it be like this?
[code]System.out.printf(" %8.2d", currentHumidity);[/code]
An integer is a whole number. It has no decimal point.
So it should just be "%8d".
[code]System.out.printf(" %,8d", currentHumidity);[/code]
would probably be best, as it automatically adds commas to your text, otherwise, just use
[code]System.out.printf(" % 8d", currentHumidity);[/code]
I'm trying to read a text file filled with customer ID's in java. I want only the ID's in said file. The good news is that the ID is a string of numbers " Customer id=9115584444938613376" so how do I remove everything except the ID's. Some ID's vary in length too. It's over 200 people. Never touched Regex, tried using String.match(), and coming up with ways to do it in Ruby. Any quick way to edit a text file?
Also, cool story, they've stored it in an array outputting it's contents to the text file.
Sorry, you need to Log In to post a reply to this thread.