|
Blackberry89 wrote: I need help on how i can start
Start with a better question; this one is not very clear.
It's time for a new signature.
|
|
|
|
|
i have got 5 randomly generated numbers in a queue. I want the smallest number in the queue to be displayed. After this another random number will be generated and i want it to be compared against the queue and from that the smallest number be displayed. The code so far is below:
import java.util.ArrayList;
import java.util.Iterator;
public class Assign1 {
private final int MAX_QUEUE_SIZE = 5;
private final int NO_SIMULATIONS_TO_RUN = 7;
private int maxSize;
private double[] queArray;
private int nItems;
public static void main( String args[] ) {
new Assign1().runSimulation();
}
public void runSimulation() {
PriorityQueue queue = new PriorityQueue();
initQueue(queue);
for (int i = 0; i < NO_SIMULATIONS_TO_RUN; i++) {
System.out.println( "The numbers in the queue are: " + queue.toString());
System.out.println( "The current dispatched number is " + queue.poll());
queue.remove();
int item = getRandomNumber();
System.out.println( "The new coming number is " + item );
queue.add(item);
System.out.print( "\n\n" );
}
}
private void initQueue(PriorityQueue queue){
for (int i = 0; i < MAX_QUEUE_SIZE; i++)
queue.add(getRandomNumber());
}
public static int getRandomNumber(){
return 1 + ( int ) ( Math.random() * 100 );
}
private class PriorityQueue extends ArrayList {
public void add(int val){
super.add(new Integer(val));
}
public int poll(){
return ((Integer) iterator().next()).intValue();
}
public String toString(){
StringBuffer buff = new StringBuffer();
Iterator it = iterator();
buff.append("[");
while (it.hasNext()) {
buff.append(it.next());
if (it.hasNext())
buff.append(", ");
}
buff.append("]");
return buff.toString();
}
public void remove(){
if (!isEmpty())
remove(0);
}
}
}
|
|
|
|
|
so your method poll() should give the smallest number in the Array. OKOK.
You need to compare the numbers in your Array, start with first number and compareTo the other numbers - as long as you do not find a smaller number. IF so, use this number as comparsion and continue. When you reach the end of the Array the comparsion should be the number searched for.
shouldn*t be that hard to figure out
Remember to modify the mechanism for the exchange of the found number.
greets
Torsten
I never finish anyth...
|
|
|
|
|
yes, try to define your question. An programm needs more explanation.
Try to make a plan:
- what is your goal?
- which parameter is able to give to an decision on my goal?
- How can i get this parameter?
- which other points must I consider (GUI, special framework, ...) ?
I never finish anyth...
|
|
|
|
|
hi all ! i'm in need of source code (working)in java for encrypting and decrypting an image(be it any format).gif,jpeg,png etc......
or any link directing to the download of the same is also appreciated..
or members can directly mail to my id glinseynew@gmail.com (its preferrable to post it on to group so that others like me are also benifitted )
many thanks for ur help ...
plz do reply @ earliest
thanking u inanticipation..
glinsey
|
|
|
|
|
See here[^], tutorials on all aspects of Java. Also try a Google search.
It's time for a new signature.
|
|
|
|
|
Hello,
I have got two arrays one called NB(number of memory blocks) and the other called NJ(number of Jobs). I want the NB arrays to search through the jobs and find a job that is <= to the block. So for example if i had:
Blocks
800
300
750
200
Jobs
200
720
900
500
The 200 jobs should look the the blocks list and fit memory that best fits it, in this case that would be block 200. And job 720 should look through the list and instead of going to block 800 it should go to memory 750 as it best fits it.
Here is my code below so far:
import java.util.*;
public class BestFit
{
public static final int NJ = 5;
public static final int NB = 5;
public static void main(String[] args) {
int [][] Jobs = new int [NJ][2];
int [][] block = new int [NB][2];
Random random = new Random();
for(int i=0; i<NJ; i++){
Jobs[i][0] = -1;
Jobs[i][1] = 100 + random.nextInt(900);
}
for(int i=0; i<NB; i++){
block[i][0] = -1;
block[i][1] = 100 + random.nextInt(900);
}
for(int i=0; i<NJ;i++){
for(int j=0; j<NB; j++){
if(Jobs[i][1] <= block [j][1] && block[j][0] == -1 && Jobs[i][0] == -1){
block[j][0] = i;
Jobs[i][0] = j;
System.out.println("Job" + Jobs[i][1] + " in memory" + block[j][1]);
}
}
}
for(int i=0; i<NJ; i++){
System.out.println("Job [" + i +"][0] = " + Jobs[i][0]);
System.out.println("Job [" + i +"][1] = " + Jobs[i][1]);
}
for(int i=0; i<NB; i++){
System.out.println("block [" + i +"][0] = " + block[i][0]);
System.out.println("block [" + i +"][1] = " + block[i][1]);
}
}
}
thanks for all help
|
|
|
|
|
You only hit the first possible block. Not ideal but a simple solution is to check each hit if it is smaller than a previous one:
for(int i=0; i<NJ;i++){
int smallest = -1;
for(int j=0; j<NB; j++){
if(Jobs[i][1] <= block [j][1] && block[j][0] == -1 &&
(smallest == -1 || block[j][1] < block[smallest][1]))
{
smallest=j;
}
}
if (smallest >-1) {
block[smallest][0] = i;
Jobs[i][0] = smallest;
System.out.println("Job" + Jobs[i][1] + " in memory" + block[smallest][1]);
}
}
Panic, Chaos, Destruction.
My work here is done.
or "Drink. Get drunk. Fall over." - P O'H
|
|
|
|
|
Thanks a lot..it works perfectly
|
|
|
|
|
hello guys..need ur help yet again..lolzz.....how can i resize buttons in java. Further more how can i make sizes of buttons B1, B2 and B3 according to the size of button B4??...thanx
|
|
|
|
|
|
Hello Friends
I created a Applet viewer in java using java3d sdk.Now I embed it into my site.I have questions:
1)If any user opens the viewer on his browser then how can I find that jre is installed on his machine or not?so that I can provide him link to install.
Regards
Yogesh
|
|
|
|
|
|
Hi,
Can I resize an image of shape diamond using swing?
Can I place a label inside the diamond image?
Label should be editable dynamically.
If it is possible, can you tell how to do this?
Thanks,
Janaki
|
|
|
|
|
Images are always square. You can resize them.
you can put an layer upon the image and place a textfield in there - yes - that's possible:
http://www.java2s.com/Code/Java/Swing-JFC/Panelwithbackgroundimage.htm
http://www.javalobby.org/articles/ultimate-image/
greets
Torsten
I never finish anyth...
|
|
|
|
|
Hi,
Thnx for ur reply.
Dynamically system has to allow to resize the image of shape Diamond.
If I try to resize it from left, it will increase the size of image only in left side and its has to do that side only.
But the shape will be changed right?
What to do in this situation?
Placing a Label inside an image:
Here the diamond shape image has background where the label doesn't.
In this case also is it possible?
Thanks
Janaki
|
|
|
|
|
I install xampp in ubuntu
but when I start the xampp theres an error says that
icotp@icotp-desktop:~$ sudo /opt/lampp/lampp start
Starting XAMPP for Linux 1.7.1...
XAMPP: Starting Apache with SSL (and PHP5)...
XAMPP: Another MySQL daemon is already running.
XAMPP: Starting ProFTPD...
XAMPP for Linux started.
icotp@icotp-desktop:~$
|
|
|
|
|
I think this is in the wrong forum. XAMPP isn't Java. Try the Linux forum or the web development forum instead.
|
|
|
|
|
Hi guys,
I am trying to build Instant Messaging Jabber client using;
-Eclipse IDE
-Smack API(with smack.jar files)
-Openfire(as the server)
I would like an advice on how to build this client using eclipse and am finding difficult on how to build a simple program that sends message from one client to another client using the openfire server provided.
I would appriciate if anyone could help me with this.
Thanks in advance,
Ireland
|
|
|
|
|
I want the colors is a grey scale from black to white.
Example: I have X value is change all the time , max_X = 100, mix_X = 1,but i want to have color base on X value.
Color = X/(max_X – min_X) * (# of shades in scale)
Anyone help me please .....
Thanks
Jenny
|
|
|
|
|
Colour in Java is specified in terms of the proportion of red, green and blue (transparency or alpha comes into it as well but you can ignore that if you want to keep things simple). Each value ranges from 0.0 to 1.0. At either end of the scale you have:
new Color(0.0f, 0.0f, 0.0f);
new Color(1.0f, 1.0f, 1.0f);
As long as the three values (R, G, B) are all the same, you will end up with a shade of grey. So, progressively lighter shades of grey go:
new Color(0.25f, 0.25f, 0.25f);
new Color(0.5f, 0.5f, 0.5f);
new Color(0.75f, 0.75f, 0.75f);
After that it should just be some simple maths to convert your X value to the required float value to pass in to the constructor to get the required colour. As long as you make all three values the same, it will be grey.
|
|
|
|
|
Hi Guys,
This is the error am getting when i start my Tomcat Server.
Several ports (8005, 8080, 8009) required by Tomcat v6.0 Server at localhost are already in use. The server may already be running in another process, or a system process may be using the port. To start this server you will need to stop the other process or change the port number(s).
|
|
|
|
|
Which part of this message are you having trouble understanding? There is not much that can be added to a message that tells you exactly why it cannot start.
txtspeak is the realm of 9 year old children, not developers. Christian Graus
|
|
|
|
|
Another progess has used those ports .
Ctrl+Shift+Del -> process , you will find a process called "java.exe" , just stop it .
|
|
|
|
|
Hi all,
I have also gotten the same error, I used Eclipse and Tomcat Server to create a web dynamic application. As, I run my application by Eclipse is gotten the error. I solved simply, check if Tomcat Server is running in your computer, you should stop it before you run application. This fixed the error. (Because, when Eclipse runs your application in server, default, Tomcat Server is run by Eclipse.)
Best regards,
Nguyen Cong Doan
|
|
|
|