BestJewSinceJC 700 Posting Maven

The correct way to do it is:

public WordSort(String sentence)
{
	wordArray = sentence.split(" ");
	
}

Your code was the following, which creates a completely different variable called wordArray than the variable you declared at the top of your class. If you don't get that then go read about variable scope.

public WordSort(String sentence)
{
	String[] wordArray = sentence.split(" ");
	
}

Saying String[] wordArray = new String[sentence.length()]; doesn't make sense because sentence.length() is the number of characters in the String, not the number of words. So potentially the user could enter "ghjskdfghgjfhddhfgjh" and your code would create a String[] with a ton of space that wasn't ever used.

BestJewSinceJC 700 Posting Maven

I'll look at your code but in the future use code tags.

BestJewSinceJC 700 Posting Maven

That depends on what 'this' is, what 'point' is, what code is in the method, and what the error message actually says. Post the code for the method and post the full error message.

BestJewSinceJC 700 Posting Maven

Lol. That girl is a lunatic. Thankfully, my gf will not play any video games that aren't Mario Kart or Kingdom Hearts, and she rarely plays those.

BestJewSinceJC 700 Posting Maven

And.. ? Read the rules

BestJewSinceJC 700 Posting Maven

http://java.sun.com/docs/books/tutorial/uiswing/components/button.html

You can make JButtons with images, text, or both images and text on them. You can add these to a JPanel that uses the GridLayout layout manager. For example

//Creates a panel with a layout that has 10 rows and 10 columns.
JPanel panel = new JPanel(new GridLayout(10, 10));
BestJewSinceJC 700 Posting Maven

The definition above is a better definition for multiprogramming, not multitasking. Multitasking is defined by my OS book as requiring multiple uses - i.e. multiple users get a seamless experience because it appears that all of the CPU resources are dedicated to their use, when in fact this is not the case.

BestJewSinceJC 700 Posting Maven

In both cases, the String is still created in O(n) time, so the choice of which to use is unimportant. The only time when a developer should bother with something like this is when using one method over another becomes a bottleneck, which in almost all cases, it will not.

Oh, and when I say O(n) here I'm referring to the fact that the operation's completion time is dependent on the number of characters that need to be copied, I'm not referring to the N value from your program.

BestJewSinceJC 700 Posting Maven
Object obj = ois.readObject();
 allRequests = (ArrayList) ois.readObject();

should be?

allRequests = (ArrayList<Type>) ois.readObject();

Por ejemplo, esto es mejor:

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.ArrayList;


public class SerializationTest implements Serializable{

	private static final long serialVersionUID = 196385420706158250L;
	static ArrayList<String> list = new ArrayList<String>();
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		list.add(new String("WOOT"));
		list.add(new String("IT'S THE"));
		list.add(new String("Serialization Test!"));

		try{
			FileOutputStream fileOut = new FileOutputStream("stuff.txt");
			ObjectOutputStream oos = new ObjectOutputStream (fileOut);
			oos.writeObject (list);
		}catch(Exception e){
			System.out.println("Stuff went wrong! NOOOOOO!!!");
		}
		
		try{
			FileInputStream fileIn = new FileInputStream("stuff.txt");
			ObjectInputStream ois = new ObjectInputStream (fileIn);
			list = (ArrayList<String>) ois.readObject();
			ois.close();
		} catch(Exception e){
			System.out.println("Best error checking ever!");
		}
		
		for (String s: list) System.out.println(s);
		
	}

}
BestJewSinceJC 700 Posting Maven

Above your methods you should add standard Javadoc comments:

/**
* bodilyFunctionsMethod
* This method makes the program more gross and its purpose
* is to demonstrate bodily functions. This is the description.
* @param farts they make this method stink
* @param poop it makes this method gooey
*/

public void someMethod (String farts, String poop){
//some code here! Woo!
}

See this guide from Java Sun (now Oracle but whatever!) on how to use Javadoc comments.

BestJewSinceJC 700 Posting Maven

Mosaic: the storyline is more likely based on Pocahontas than whatever it is you are suggesting. Regardless, the movie was pretty good. It had a lot of interesting action scenes and the cinematography was beautiful.

BestJewSinceJC 700 Posting Maven

If you wanted to show all of the results you'd have to do

showResult= showResult + "Found Names: "+found+ "Similarity: " +compare+"Path: "+file.getName();

or, equivalently,

showResult +="Found Names: "+found+ "Similarity: " +compare+"Path: "+file.getName();
BestJewSinceJC 700 Posting Maven

If you want a Warrior to have a starting strength of 50, then in the Warrior class put int strength = 50; and do similarly for the other variables. By default, Warrior will inherit 'strength' and your other variables from Human. But in the Human class, you do not have 'strength' or any other variables set to a default value. I'd also recommend making a setStrength() method and a getStrength() method, and similar get and set methods for the other variables in your Human class. That way when you want to set a Warrior's strength, you can say WObject.setStrength(50);

BestJewSinceJC 700 Posting Maven

That's because for your WObject you never called MyChar() which is the only place I can see where you could have set the strength to 50.

BestJewSinceJC 700 Posting Maven
System.out.println("My Strength is " + (strength +20) + " my Health is " + (health +50));

doesn't change the value of strength. On a separate line, write strength = strength + 20; and it will change the value of strength. Is that what you were asking?

BestJewSinceJC 700 Posting Maven

I don't know but if you wait another 3-5 years I'll up this thread with an unrelated question for solidarity's sake.

jonsca commented: Too good +2
BestJewSinceJC 700 Posting Maven

Ok, here is a quick example for you. As you can see, I created a new SwingComponent (which adds a Swing JButton into the SWT Composite) from within the ViewPart class. But you can call new SwingComponent from anywhere and it will work the same. Again, keep in mind the things I've told you earlier in the thread though: if the View isn't currently showing, you will have to call showView in order to see anything.

package testpluginproj;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.part.ViewPart;

public class ViewPart1 extends ViewPart {
static Composite parent = null;
	public ViewPart1() {
		// TODO Auto-generated constructor stub
	}
	
	@Override
	public void createPartControl(Composite parent) {
		// TODO Auto-generated method stu
		Button ok = new Button (parent, SWT.PUSH);
		this.parent = parent;
		ok.setText ("Push to show the view!");
		ok.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent e) {
				new SwingComponent();
			}
		});
		
		parent.layout(true);

	}

	
	public static Composite getComposite(){
		return parent;
	}
	
	@Override
	public void setFocus() {
		// TODO Auto-generated method stub

	}

}
package testpluginproj;

import java.awt.Frame;

import javax.swing.JButton;

import org.eclipse.swt.SWT;
import org.eclipse.swt.awt.SWT_AWT;
import org.eclipse.swt.widgets.Composite;

public class SwingComponent {

	public SwingComponent(){
		Composite parent = ViewPart1.getComposite();
		Composite composite = new Composite(parent, SWT.EMBEDDED | SWT.NO_BACKGROUND);
		Frame frame = SWT_AWT.new_Frame(composite);
		frame.add(new JButton("STUFF"));
		frame.validate();
		parent.layout(true);
	}

}
BestJewSinceJC 700 Posting Maven

Even if I create a separate class like the one you have written and call the createPartControl(parent) method from outside the function what should the argument "parent" be?

You should never call createPartControl. Eclipse handles calling that method for you. If you want to make modifications to the View, like I have already suggested, make a getter method in your ViewPart class.

public Composite getComposite(){
return parent; //where parent is what I have in my prev. ex.
}

Then you can add your Swing components to the Composite as is detailed in the article I just linked you to. You can then call the layout(true) method as I told you earlier, causing your changes to be visible. If you give me a few minutes, I will give you a full example if this doesn't make sense.

BestJewSinceJC 700 Posting Maven

I find it hard to believe that none of my suggestions thus far have helped, but additionally, you can check out this article on Swing/SWT Interactions. However, if as you said you want to "show the Swing table in the Eclipse window" you're still going to need to use the suggestions I gave you about how to find the view and how to show the view.

BestJewSinceJC 700 Posting Maven

If you want to show something on an Eclipse Workbench Window like you said a bunch of posts ago, then that something will have to be shown in a View, which in turn, will have to extend ViewPart.

Oh, and if you use the showView method by just replacing that code I showed you earlier by changing findView to showView, then it will make the view appear. Isn't that what you wanted to do this whole time?

BestJewSinceJC 700 Posting Maven

Sorry, I was a lot more rusty with commands than I thought I was. Nevertheless the code I gave you before works. I used this class and it works fine for me. (Excuse the goofiness/bad programming practice with making the Composite a static member... )

package testpluginproj;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.part.ViewPart;

public class ViewPart1 extends ViewPart {
static Composite parent = null;
	public ViewPart1() {
		// TODO Auto-generated constructor stub
	}
	
	@Override
	public void createPartControl(Composite parent) {
		// TODO Auto-generated method stu
		Button ok = new Button (parent, SWT.PUSH);
		this.parent = parent;
		ok.setText ("Push to show the view!");
		ok.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent e) {
				ViewPart yourView = (ViewPart)PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView("TestPluginProj.myview");  
				Label label = new Label(ViewPart1.parent,SWT.NONE);
				label.setText(yourView.getPartName());
				ViewPart1.parent.layout(true);
			}
		});
		
		parent.layout(true);

	}

	@Override
	public void setFocus() {
		// TODO Auto-generated method stub

	}

}

Anyway, the above works for me and modifies the View so that it says "Kyle's View" which is the name of it.

BestJewSinceJC 700 Posting Maven

That's fine. Eclipse RCP says Galileo on it when it runs anyway. It is just a question of having more functionality than "normal Eclipse". As long as you can call PlatformUI.getWorkbench() without problems, you should have the required libraries.

edit:

Another thing I just remembered: if you haven't properly set up the view (so that it actually shows up when your application launches) then calling findView() is not going to work and that might be why it is returning null. You should try running that other piece of code I gave you (the one that prints out all of the view IDs) and show me what it says. My bet is that your view ID is not one of the ones there...

BestJewSinceJC 700 Posting Maven

My main method is empty now but don´t know what you mean with rewriting the brackets :-)

BTW Thanks to both of you for your help i really apprechiate it...

He was just repeating what I said. Anyway, it would be helpful to have your main driver in another class... the TestHuman class is a good idea. Just make sure to define your variables as class variables by putting them like this in your Human class:

public class Human{
//Your variable declarations go up here if they're class variables!
}
BestJewSinceJC 700 Posting Maven

Hmm, that is interesting. I don't even have Eclipse RCP on my computer right now but I'll download it and make a project real quick and get back to you. Like I said, all of this has been from memory but it has been a while. So give me ten minutes and I'll reply back. .

BestJewSinceJC 700 Posting Maven

fend

BestJewSinceJC 700 Posting Maven

Read my previous post. We posted at the same time.

BestJewSinceJC 700 Posting Maven

you have name = CharSet.next()
perhaps what you need is CharSet.nextInt()

No; that would result in an error because name is a String and nextInt() obviously returns an int. He might want to say name = CharSet.nextLine() but that is not the source of his compiler error. His compiler error is a result of trying to define two methods, MyChar() and Reveal(), inside of the main method. You can't define one method inside of another method like that. Moving the two methods outside of main will get rid of one error, but introduce another. In order to use the variables name, strength, health, intelligence, and agility in MyChar() and Reveal(), they should be declared as class variables. The other alternative would be to pass them as parameters into the MyChar and Reveal methods.

BestJewSinceJC 700 Posting Maven

You have to give it the correct viewID where I put "viewID". It is the number associated with your view. If you give it an invalid ID (such as my example) it won't be able to find your view, and thus, will return null, ultimately leading to a NullPointerException. You already defined the View ID when you filled out the form in RCP for your view. But anyway, you can also list all of your view ID numbers like this:

IViewReference[] refs = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getViewReferences();
for (IViewReference ref: refs) System.out.println(ref.getID());

As for not knowing your view ID, remember this screen from when you originally created your view? It contains your view ID field. (Note: this image is taken from Vogella's Eclipse RCP tutorials)

BestJewSinceJC 700 Posting Maven

Ok, so here's the deal. I was able to connect to your server using telnet which, to me, indicates that your server is working more than you thought. All I did was compile & run your server, then say telnet localhost 21111. I compiled with just "gcc server.c", ran the executable, then issued the telnet command.

edit:
I also ran both of your programs like so:
gcc -o Server server.c
gcc -o Client client.c
Server
(in other terminal now)
Client localhost

Running it as I did above gave me output "My TCP port is (some number here)" then it seg faulted. Not what you'd want but better than not running at all I guess.

BestJewSinceJC 700 Posting Maven

You should post the code in code tags (unless it is actually too big to reasonably view on a normal size screen) instead of attaching it. I'm assuming that it is pretty small from your project description. Anyway I'll take a look at it since I recently did a similar project. Note that I'm not really much of a C developer so take any advice at your own risk or wait for someone else to respond. Here is his code for anyone interested.

Server.c:

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <arpa/inet.h>
#include <time.h>

#define SERVERPORT "21111" 
#define MAXLEN 100


void *get_in_addr(struct sockaddr *sa)
{
  if (sa->sa_family == AF_INET) {
    return &(((struct sockaddr_in*)sa)->sin_addr);
  }

  return &(((struct sockaddr_in6*)sa)->sin6_addr);
}


main() 
{ 
	int sockfd, newfd;    // listen on sockfd, new connection on newfd
	unsigned int len;
	socklen_t sin_size;
	char msg[80];
	char buf[MAXLEN];
	int st, rv;
	struct addrinfo hints, *serverinfo, *p; 
	struct sockaddr_storage client;
	char s[INET6_ADDRSTRLEN];
	time_t rawtime;

	
	
	
  //zero struct	
  memset(&hints,0,sizeof(hints));
  hints.ai_family = AF_UNSPEC;
  hints.ai_socktype = SOCK_STREAM;
  hints.ai_flags = AI_PASSIVE;

  if((rv = getaddrinfo("localhost", SERVERPORT, &hints, &serverinfo ) != 0)){
    perror("getaddrinfo");
    exit(-1);
  }

   // loop through all the results and bind to the first we can
  for( p = serverinfo; p != NULL; p = p->ai_next){
    if( (sockfd = socket( p->ai_family, p->ai_socktype, p->ai_protocol )) == -1 ) {
      perror("socket");
      continue;
    }
    
    if(bind(sockfd, p->ai_addr, p->ai_addrlen) == -1){
      close(sockfd);
      perror("bind");
      continue;
    }
    
    break;
  }

  if( p == NULL ){
    perror("Fail to bind"); …
BestJewSinceJC 700 Posting Maven

You should change your getHighestInRow method to take two parameters: The row number that you want to get the highest value of, and the array itself. Then in your main method you can use a for loop to loop over each row of the array, getting the highest of each row. You could do a similar thing for the lowest method. That would also enabled you to get rid of the print statements in the methods and relegate those print statements to your main method.

BestJewSinceJC 700 Posting Maven
ViewPart yourView = (ViewPart)PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView("viewID");

You might have read through the API and gotten confused because the findView() method is defined as returning an IViewPart. IViewPart is an interface, not a class. ViewPart is a class that implements the IViewPart interface. ViewPart defines the view that you see on your screen, so casting to a ViewPart, like I did above, will be safe. Once you do what I did above to get a handle on your Eclipse RCP view, you can then modify the Composite (which is an SWT widget). I don't remember how to get the Composite with an "out of the box" method, but you can simply define your own getter method in the class. After you modify the Composite to put your diagram on the screen, you're going to want to do the following:

// .. add stuff to the Composite up here
yourComposite.layout(true);

Calling the layout() method causes the Composite to re-display all of its contents. So basically you're telling it you made changes. As for calling SWT from AWT, as far as I know it makes no difference where you call these methods from. As long as you are in an Eclipse RCP built application, you can call all the methods that I have shown you. And as long as you can call all of the methods that I have shown you, you are good to go. Do you get errors when you try to call PlatformUI.getWorkbench()?

BestJewSinceJC 700 Posting Maven

You can make two static variables: numeratorValue and denominatorValue. After the first time you calculate your numerator and your denominator, save the results into numeratorValue and denominatorValue. Every time you calculate your numerator and denominator after that,

newNumerator = numeratorValue * x;
newDenominator = denominatorValue * i;
numeratorValue = newNumerator;
denominatorValue = newDenominator;
BestJewSinceJC 700 Posting Maven

Ok, then you are going to need another array. You have your jobs array and your blocks array, but currently, there is no way for you to tell if a block is already allocated to a job. I suggest using an array of booleans, true to represent "block already taken" and false to represent "block not already taken". In the code below I used BLOCKS_SIZE as a constant - that way, if you need to change the size of your block array, everything else changes with it. I hope this example makes sense. You can use a method to assign one job. Then, by calling that method on every job, you can successfully assign every job. Of course, not all jobs can be assigned, which is why the method returns true (successfully assigned the job) or false (there was no spot for the job, it has to stay in waiting queue).

// .. code up here for class
private static int BLOCKS_SIZE = 4;
public static void main(String[] args){
int[] blocks = new int[BLOCKS_SIZE];
boolean[] blocksUsed = new boolean[BLOCKS_SIZE];

// .. code for getting user input 

for (int i = 0; i < jobs.length; i++){
boolean wasAssigned = assignJob(jobs[i]);
//  Check wasAssigned variable. If wasAssigned is true then
// the job can be taken out of the waiting queue, otherwise,
// no spot was found for the job in blocks, so it should stay.
}

public static boolean assignJob(int job, int[] block, boolean[] blocksUsed){
//I'll leave writing this code …
BestJewSinceJC 700 Posting Maven

Where are you getting stuck, what do you need help with, etc...

BestJewSinceJC 700 Posting Maven

You can declare and initialize your arrays all at once like this:

int[] jobs = new int[4];

When you read input using Scanner, you should ensure that your program does not crash by using:

if (keyboard.hasNextInt()){
myInt = keyboard.nextInt();
}

Calling Arrays.sort() on line 24 in your code doesn't do anything. Sorting an array with only one element, which is already in the first position of the array, does nothing. Combine the loop (notice that you can declare a variable inside of the for statement like so:

System.out.println("Enter 3 jobs");
for(int index = 0; index < 3; index++){
if (keyboard.hasNextInt()) jobs[index] = keyboard.nextInt();
}

Anyway, I was actually just giving you that advice as I went through, but I got to the end of your code and I don't understand what you are trying to do. Is your jobs array supposed to be some sort of queue? Saying it is a queue implies there is some order to the elements, i.e., that they are in some sort of a line and there is an order in which they come out .. but I don't see you using it like that anywhere. Can you copy/paste me your assignment statement (if this is a school assignment) or explain further? I don't understand what the relationship between blocks and jobs is supposed to be.

BestJewSinceJC 700 Posting Maven

No problem Claire (I'll take credit for any good information, hehe). Welcome to the site!

BestJewSinceJC 700 Posting Maven

Hoe i can solve this type of error?

What did you call me?

;)

jephthah commented: okay, i lol'd +6
BestJewSinceJC 700 Posting Maven

References for OS Scheduling algorithm would be welcome..... and also for kernel programming please ......... I am thinking of programming a small kernel with limited features and having Non preemptive scheduling algorithm........So any kind of help or reference material is welcome....!

And thanks everyone for the ideas!

Read... an OS textbook.

BestJewSinceJC 700 Posting Maven

How so? Please post your solution so that if someone comes across your thread in a search (or is just reading the thread like I am) they can see it.

BestJewSinceJC 700 Posting Maven

I've never used the valueOf() method. Just use the '+' operator. The + operator creates a new String in the background anyway. The valueOf() method returns a new String so it does the same. Neither method has a time advantage that anyone cares about; although I don't claim to know the details, to create a new String you basically have to copy every character into an array which is O(n) so both methods are O(n).

BestJewSinceJC 700 Posting Maven
BestJewSinceJC 700 Posting Maven

Please don't give working code, give advice instead, if possible. To the OP, keep in mind that when running a program with command line arguments, those arguments are stored into the args array. So args[0] would be the first command line argument, args[1] the second, etc. Combined with the code you were given above you should be able to figure it out.

BestJewSinceJC 700 Posting Maven

As long as one brain is on a different CPU...

lol

BestJewSinceJC 700 Posting Maven

Do people who use these API's even know how to program? Ive never used XNA before, but it seems like the average Joe can download it, copy past from some tutorials and make some triple A game title. It kinda pisses me off. If anyone here begs to differ, let me know and why I'm wrong. Like I said Ive never used XNA before or anything similar to it. What if you asked an XNA programmer what try throw catch is, would they be able to answer?

Right, and anyone can be a doctor since modern medicine has CAT scans. Maybe not the best example, but the rationale is the same. Good tools enable programmers to be more efficient, but you still need to know how to understand and apply those tools. Better programmers will be more efficient at using the tools correctly. And being able to use one or two APIs does not make someone a good programmer.

BestJewSinceJC 700 Posting Maven

define the array as a char array instead of as an int array.

char[][] mychars = new char[10][10];
mychars[0][0] = 'x';

And if you're going to make new threads about the same topic, mark your other thread solved. Otherwise just keep posting in the other thread.

BestJewSinceJC 700 Posting Maven

Do you really want to truncate the value, or do you actually want to print out a value up to three decimal places?

http://java.sun.com/docs/books/tutorial/java/data/numberformat.html
Look at the DecimalFormat example there. You can also use a C-style printf statement if you want to.
You could also use DecimalFormat to truncate the value, btw - I don't know if it is the most efficient way to do so, but it will work.

DecimalFormat f = new DecimalFormat("#.##");
		System.out.println("Enter a double");
		Scanner in = new Scanner(System.in);
		System.out.println(f.format(in.nextDouble()));
BestJewSinceJC 700 Posting Maven

Assigning x = board does nothing. The variable x goes out of scope as soon as your method call returns. You should be saying board = x. Once you fix that, your program still will not work. You never created & initialized any values in your 2D array. Really, at this point, you need to go read about 2 dimensional arrays, variable scope, and how methods work in Java. Once you read up on all of that information you will be ready to start your project.

BestJewSinceJC 700 Posting Maven
JOptionPane.showMessageDialog(null, "Your message goes here");
BestJewSinceJC 700 Posting Maven

Write a scheduling algorithm for the OS.