How about using threads for multiple events or actions that need to occur at the same time.
http://www.javaworld.com/javaworld/jw-04-1996/jw-04-threads.html
http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/Thread.html
How about using threads for multiple events or actions that need to occur at the same time.
http://www.javaworld.com/javaworld/jw-04-1996/jw-04-threads.html
http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/Thread.html
well AFAIK even if you convert the values to double You can't store them in an int variable
my counter is causing the problem
which variable are you talking about?
1. You should have posted in the Java Forum for experienced Java users to see this post
2. Why make a duplicate thread about the same problem with your last thread?
3. Are the suggestions in the other thread not helpful?
my last problem seems to be getting my whole program to work with doubles rather than ints,
Initialize the variables as a double then match the arguments at the printf() statments
while my counter remains an int
if your talking about the variable counter then there's not really a need to make it a double
@jbennet
Shouldn't this be moved in the java forum?
@MichaelCJ10
while (counter<total.length)
{
counter++;
...
When you start your while loop you immediately started with an increment to the counter which caused it to use the next element instead of starting with wages[0]
Next
final int TOTAL_LENGTH=11; //declare constant
The array has only 10 elements
How to we know that there is the error of javac
Is it an error with a program or with you using javac itself?
May I ask where is the Programme class
I'm glad that It's finally solved, congrats ;)
The brackets at line 26 and 27 are not needed
the for loop for printing the value of sumCount should be outside/after the while loop
Can you post your code?
That sounds like I'd be spoon feeding you so sorry but I'll pass
I really do not understand why I do not get the desired output.
Print the values of odd[count] and even[count] in the while loop and you'd see that eventually they'd get the values of:
odd[count] with {1,2,3,4,5,6,7,8,9} and
even[count] with {2,3,4,5,6,7,8,9,10}
so simple iteration won't work
at the odd numbers it should remain as the value of i
and the same at even numbers i+1
then use
sum[count] = odd[count] + even[count];
then after count+=1; , iterate using i+=2;
that should give the right values for the odd and even numbers at your code
Does not work.
what do you mean by this? is there an error or you can't get the desired output?
could you post those errors or output.
hmm.. well I tried the program and did what I suggested and I got it to work...
at the while loop how about you put i++; after count+=1;
where exactly did you put it?
Also I suggest to change your for loop to print the values
something like this
for(int counter = 0;counter <10; counter++){
//print out sum with counter as the index
}
Edit: there's nothing really wrong with the for loop I was just suggesting a better way to view what's going on :)
but nothing is drawn.
the drawing should be done in the paint method, then try to use the values you have in the drawOneCircle method for the coordinates
here's an link for more info about this that might help
http://en.wikibooks.org/wiki/Java_Programming/Graphics/Drawing_shapes
the problem is in your while loop you don't change the value of i
try to iterate i
yes we can help
What have you coded so far?
What part are you having problems with?
the setColor should be in the paint method
pass the arrCam array to calculateTotInvent method
Here's a link that might help
http://www.java2s.com/Code/Java/Swing-JFC/AsimpledemonstrationoftextalignmentinJLabels.htm
@ line 161 you forgot the semicolon [TEX](;)[/TEX]
then declare the variables at line 163-166 before using them like in line 158-161
how about you initialize the value of menu to zero @ line 23
int menu = 0;
im sorry,i dont get it, is this what u mean?
At your last code lines 28-43 are unnecessary
could you post your current code so we may see what you did
remove the printf() at line 32 and put it as a default case and don't forget the break if it's not the last case
also menu can only take an int value
Edit: just use a single switch statement and a single loop on it and put the user input at the beginning of the loop
and this line:
printf("I'm sorry, but you have enter an invalid selection. Please try again.\n\n");
should be the default case
put the user input lines inside the loop otherwise the value of menu will never change
Edit: just noticed that the do while should be in the method
use a loop where the condition is while the user doesn't enter a specific number it will continue to loop and insert it around the user input and switch case
example:
while(menu != 4){
printf("Please choose your menu: ");
scanf("%d", &menu);
switch(menu)
{
case 1: quiz();
break; //don't forget to use break otherwise it will ran through other cases
case 2: calculator();
break;
case 3: optional();
break;
case 4: printf("Goodbye\n");
break;
default: printf("I'm sorry, but you have enter an invalid selection. Please try again.");
break;
}
}
As I can see you might need to import java.lang.Math to make Math.pow and Math.sqrt to work
in your previous code
public CircleComponent(Point2D.Double point)
{
circle = new Circle(200, 200, 100, Color.BLACK);
final double SMALL_RADIUS = 3;
Color color;
if(Circle.isInside() == true)
color = Color.GREEN;
else
color = Color.RED;
smallCircle = new Circle(point.getX(), point.getY(), SMALL_RADIUS, color);
}
@ line 7
Java is case sensitive that would be circle.isInside(/*argument*/) since circle is your new Circle object
plus yoou need an argument that has the same argument type for public boolean isInside(Point2D.Double p)
Is there a finish method in the other codes?
If so put it in this class too or just create a method finish()
It's not really a bug, the modulus is doing whats its suppose to do
are you trying to make the program display 0 when 30 or a similar case is entered?
yes remove it, start at 0 and make the condition less than 10
after that you need to change a few counters with your bubble sort to make it work
At line 9;
An array has elements ranging from 0 up to size-1, you can't start at 1 there and end with 10+1
Is the 5% constant or does it change depending on the current tuition fee?
if it's the latter, you can make use of the first loop and make it loop up to 21 years(if it's allowed) then if it's the 18th year add the current tuition up to the 21st year and store it in a variable, just to be sure of the values
though if it's constant or if you already know the tuition value for the 18th year and your positive that the values up to the 21st year are correct then go ahead if you prefer this
check line 45
...and the number of t's in the filename there ;)
Once you use a character array you need to make specific changes in the program
for example:
scanf ("%i", &password[7])
will be changed to %s for the string input
By changing it to a char array you should be able to make the neccesary changes in the code to make it compatible but if you still need further help with this you could always post all the error messages and their corresponding lines where they're found
P.S. there's no need to downvote WaitP's post, he posted the first step for the solution :)
whoops didn't notice my math error, sorry about the example that's not suppose to be D(9) but D(11) :$
anyway about the recursion you need a base case where the recursion will eventually lead to for all values passed on to it,
in your code if the value of int doesn't equal to 10 it will keep on running, The + n won't apply yet until a value is returned for D(), maybe make a base value where all numbers will eventually lead to like if it becomes less than or equal to 0
the stackoverflow happens because of an infinite recursion
the value 10 is not the base value, you need to have a condition for the values less than 10 or at least less than or equal to 0
for example D(21) will result to D(9)+10 then (D(-1)+10)+10 and so on
at line 39 use .equals() in comparing strings like so
if( accountName.equals("keenan") )
If anyone has a more efficent idea to compare 25 variables than the use of many if statments feel free to post it
Could you post the part of the program where you use those 25 variables so we can have a better idea on how to the program works
anyway I think you should use a 2d array to store those variables then use a loop to compare each element instead of many if statement
up to what topic have you learned so far?
set this at the topmost
package bus;
the package is different than the public class, it doesn't affect the class name only the access to it
check these links for more info
http://docs.oracle.com/javase/tutorial/java/javaOO/accesscontrol.html
http://stackoverflow.com/questions/215497/in-java-whats-the-difference-between-public-default-protected-and-private
PS. if the problem is solved then you can mark this thread as solved, have a nice day :)
1.
int x = findFirstEmpty();
remove this you don't need to find an empty seat
2. use a loop to check the content of the array
3. use public void cause there's no need to return anything
But what do I return?
I think it's better if you use public void so there won't be a need for a return statement cause all you need is to change the value
as for checking if the name is equal, loop through the array then
if (name.equals(names[x]))
delete the contents of that array index
Oh! That made it work a lot better. My notes from class said I had to do that every time. So, when I was trying that, was it just emptying the array over and over again instead of filling it?
It will not overwrite the contents if you use a new variable other than n1, though I think you don't need to in this case
I know there is something wrong with my getOff method.
instead of trying to find an empty seat like,
int x = findFirstEmpty();
I think you just need to find the array index with the name you need to remove,
As for the swap you need to use the array and swap the values in them
SchoolBus n1 = new SchoolBus();
Instantiate only once, like only at line 144 and removes other initializations like
n1 = new SchoolBus();
you need not to create a new object everytime and overwrite the contents