BestJewSinceJC 700 Posting Maven

I got my Dell custom built and shipped and it took less than 2 weeks .. I guess area may have something to do with it.

BestJewSinceJC 700 Posting Maven

I hope you don't expect anyone to do your homework for you.

BestJewSinceJC 700 Posting Maven

Spam - hate it

ritas?

BestJewSinceJC 700 Posting Maven

I don't know if this helps or not but check out Ezzaral's example on post #3 http://www.daniweb.com/forums/thread187103.html

BestJewSinceJC 700 Posting Maven

So what was the regex that worked? And mark solved threads solved!

BestJewSinceJC 700 Posting Maven

Your regex isn't complicated enough. The first part is correct (although I'd wrap it in parenthesis), but you need a mechanism to read in the text after the word 'Title:' which can be accomplished by saying (.*) and you also need to make sure the (.*) doesn't read in the newline which I'm pretty sure (but not positive) can be done by altering it to "(.*)?(\n)". You might also need a double backslash instead of the single one as an escape character, but I don't really remember.

Those are all guesses but to the best of my knowledge they are correct; I have worked with regexes somewhat in the past but I admit I tend to forget things and look them up. Give it a try and experiment a little.

BestJewSinceJC 700 Posting Maven

Haha. I view most of the threads posted in this forum, and I have to admit, I am usually guilty of telling the member 'use code tags' but I rarely hit the report bad post button. I'll do it in the future if it'll make you that happy.

:)

Nick Evan commented: Thanks! +12
BestJewSinceJC 700 Posting Maven

Hi Alex, as a software engineer you have a responsibility to learn how to use the internet. (Make your own thread :) )

BestJewSinceJC 700 Posting Maven

Which is exactly what I was talking about...
A LOT of parents know full well that their children are engaged in criminal activity yet take no action to correct that.

The parents who see their children come home every few days with new clothes they couldn't possibly have bought from their allowance or weekend job yet don't ask where those came from are the mildest example.
Parents getting complaints from neighbours and/or police about their children acting like neighbourhood thugs and vandalising property are a major problem here.
I've personally witnessed parents telling their children to shoplift in supermarkets, to put things in their pockets but make sure noone is watching first.

And those (thought the last I've witnessed rarely, presumably because most such parents are more careful) aren't incidents, they're endemic especially in specific racial/social/national groups at least in this country.
In fact there's a strong sentiment in some groups that vandalising and thuggery if aimed at certain other groups is quite correct behaviour and is actively encouraged by parents and neighbourhoods as a whole.

I see, I misunderstood you earlier. And I'd add that a parent who encourages a child's illegal behavior, such as stealing, should face a stiffer penalty than the child. Earlier I thought we were talking about bad parenting without some sort of "malicious intent" or willful ignorance (such as your example with seeing their kids come home with stolen items, etc).

BestJewSinceJC 700 Posting Maven

Calling a String 'charArray' is pretty confusing to say the least. Anyway, here is an example to clear things up. This puts the first rows of chars into the variable temp.

char[][] chars = new char[10][10];
		
		//Put some stuff in the 2d array
		for (int i = 0; i < 10; i++)
			for (int j = 0; j < 10; j++)
				chars[i][j] = (char) (i*j);
		
		// 0 is the row, i is the column
		String temp = "";
		for (int i = 0; i < 10; i++) temp+=chars[0][i];
BestJewSinceJC 700 Posting Maven

Thanks guys, you just caused me to open the C++ thread and read 10 pages of Narue and Jwenting schooling Richard West 5 years ago. What a productive night I was supposed to spend writing javascript .... *sigh*

BestJewSinceJC 700 Posting Maven

I never stay logged in either, but I also never get that popup window before I've managed to log myself in when I return to the site.

BestJewSinceJC 700 Posting Maven

Then why don't you do the obvious thing and put print statements in each of those functions, run the example, and see how many things get printed. This hardly looks like rocket science.

Rashakil Fol commented: maybe he's dumb +7
BestJewSinceJC 700 Posting Maven

Moutanna:

My example is legal Java code. It's more robust than your example because my example makes use of Java's autoboxing features. Number being an abstract class doesn't matter because I never tried to instantiate 'Number'. The example instantiates some class in Number's inheritance hierarchy.

Number n = -2.9;
System.out.println(n.getClass());
char[] chars = (n + "").toCharArray();
for (Character c: chars) System.out.print(c);

Sammich: Mark solved threads as solved.

BestJewSinceJC 700 Posting Maven

Absolutely not.

kvprajapati commented: Aye. +9
BestJewSinceJC 700 Posting Maven

Use string.split(","); then use a for loop to iterate over the array it returns. Use the Integer.parseInt(string) method to convert each String in the array into an int.

BestJewSinceJC 700 Posting Maven

probably the same as a binary search tree

just a guess though, since I've never heard of a decision tree before and it looks like a binary search tree to me

BestJewSinceJC 700 Posting Maven

Jwenting: liability for damages and responsibility for criminal charges are completely different things. A parent might be liable for damages caused by a child (in certain circumstances), however, a parent is not criminally responsible for a child's actions unless they are involved in the child's actions:

1. Aiding or encouraging the behavior
2. Neglect of whatever the behavior is

Even if a child shoots someone, the parent is not necessarily legally responsible. You guys are acting like if a child went and robbed someone, the parent will have to serve jail time, which is simply not how it is. In that specific example, the parent might be legally responsible for payments to the person whose property was stolen, but they are not criminally held accountable for the theft. And even if the parent is found intentionally neglectful of the behavior, they will not be charged with the child's crime, they will be charged with a lesser crime (since they aren't the one who committed the child's crime!)

Poor parenting is impossible to measure, especially legally by people who don't know the parents. And poor parenting, again, is subjective. There are plenty of examples that you would call poor parenting which are not illegal whatsoever; so you're [ardav] arguing that after the sum of those examples, if the child commits some crime, the parent should then be criminally prosecuted?

BestJewSinceJC 700 Posting Maven

To be honest, I thought you were well above the skill level that you are at. The project your teacher has given you implies that you should be familiar with classes and methods; both using other class methods and implementing your own methods. That said, the suggestions I gave you previously are probably way too complex. I'll continue to explain them if you're still interested, but I won't be offended if you don't want to continue, so let me know.

You can't put a constructor called Word in a class called Scrabble. You must either implement a separate class called Word, or you must use an inner class called Word. See inner classes. I put together a little example to demonstrate what I mean. I left implementing the Comparable interface up to you; notice that it says the class implements Comparable, but I left the compareTo method blank (you need to provide the code for it). This link explains pretty thoroughly how to implement the Comparable interface.

import java.util.ArrayList;

public class OuterClass {	
	
	ArrayList<Word> list = new ArrayList<Word>();
	
	public static void main(String[] args){
		OuterClass c = new OuterClass();
		Word wrd = c.new Word("Something", 10);
		c.list.add(wrd);
		System.out.println(c.list.get(0).toString());
	}

	public class Word implements Comparable{
		String theWord;
		int pointValue;
		
		public Word(String word, int val){
			theWord = word;
			pointValue = val;
		}
		
		public String toString(){
			return theWord;
		}

		@Override
		public int compareTo(Object arg0) {
			//You need to implement this method!
			return 0;
		}
	}
	
}

You should also …

BestJewSinceJC 700 Posting Maven

In the End, we will remember not the words of our enemies, but the silence of our friends. -Martin Luther King Jr.

Opportunity is missed by most people because it is dressed in overalls and looks like work. -Thomas Edison

BestJewSinceJC 700 Posting Maven

Go to the directory where HelloWorld.java is located, then use the simpler command. From the command prompt, You can use cd directoryName to change directories on linux and (I think) Windows as well.

BestJewSinceJC 700 Posting Maven

What part of the exercise are you having trouble with?

BestJewSinceJC 700 Posting Maven

Start by doing step 1. Then step 2. Continue until you're done step 7. Let us know what you've tried and what you don't understand.

BestJewSinceJC 700 Posting Maven

It doesn't change anything I said except that in step 4 you should use your teacher's class to read stuff.

BestJewSinceJC 700 Posting Maven

Why don't you post all of your relevant code. In the code you provided above, you never created a Scanner, hence you cannot invoke the Scanner class's nextLine() method. Besides which, the example I gave you in post #2 can be easily modified to print the line out to a File instead of adding the line to the ArrayList.

BestJewSinceJC 700 Posting Maven

The Scrabble file should extend Echo, in the standard way we've indicated (it can also extend the LineReader class from Chapter 11 of the text).

Java classes can only extend one other class, there is no multiple inheritance (some might argue about interfaces but meh). Anyway, what I would do is the following:

  1. Write a Word class that has two variables - the String for the word itself and an integer for the word's point value.
  2. In your Word class, implement the Comparable interface and write your implementation of the compareTo method so that it sorts according to point value.
  3. Create an ArrayList of Word Objects, ArrayList<Word>
  4. Read in your file using Scanner (or whatever Reader your teacher suggested)
  5. Create a Word Object for each word in the file, add Word to the ArrayList
  6. Sort the ArrayList using Collections.sort(yourList);
  7. Get the user's input, see what it is asking, then use your sorted list to answer the question. For example, if it asks what the highest point value is for a 7 letter word, then start at the end of the list (since it is already sorted by point value) and find the first 7 letter word. That is your answer.

Hope that helps. If you're only allowed to write one file called Scrabble.java then implement the Word class as an inner class. Chances are your teacher wants you to manually sort the list, and have two lists (one for the word and one for its point value). …

BestJewSinceJC 700 Posting Maven

I no I need to set up another scanner to read in the users choice but Im not sure how. Please help.

/*
An example that's been given hundreds of times
*/
Scanner keyboard = new Scanner(System.in);
System.out.println("Enter one word:");
String input = keyboard.next();

And you should use two HashMaps, not one TreeMap. If you read the documentation on TreeMap you'll see that it takes log(n) time for get and put operations (the operations you'll be doing the most since you'll be putting things into the Map and looking them up a lot) whereas HashMap takes constant time. Of course there are a couple issues with HashMaps that can cause the time to not stay constant, but you needn't worry about that. The thing is it doesn't make sense to use a TreeMap if you don't provide a Comparator - read the Javadoc for TreeMap, it makes a huge deal about how it is always sorted, but your Map doesn't need to be sorted so why bother? Also, you'll need two Maps because Maps are looked up by Key, not by Value. You will need one Map that has the telephone number as the Key and the Name as the value, and you'll need another Map with the Name as the key and the telephone number as the value.

BestJewSinceJC 700 Posting Maven

so my question is...
how can i make it possible to like write 2x^2+3x-1 and then make it possible for me(through the program) to separate all the parts..

sorry didnt write that the language im using is JAVA...thats kind of vital to know ;)

You're posting in the Java forum so we assume you want to use Java. As for the input - is your question how can you let the user input the items, or is it how can you parse the input? Parsing in this case means taking something like 2x^2 + 3x + 1 and programmatically separating it into logical parts (so that your program knows to treat it as 2x squared, plus 3x, plus 1).

Anyway, you have a variety of ways that you can have the user enter the input. Like you just showed, you could just let them type in something like 2x^2. Or you could design a GUI that had appropriate buttons on it where the user could enter their expressions. From the standpoint of parsing and error control, having a GUI where the user can enter their expressions would make your job much easier. If you let the user type anything they want, you have a high risk that they will enter something you don't know how to deal with.

BestJewSinceJC 700 Posting Maven

I don't know what the 8 queens problem is. You'd be better off posting this in the Computer Science forum and giving a description of the problem if it is an algorithm question and not strictly a java programming question.

BestJewSinceJC 700 Posting Maven

How can you expect us to help you when you didn't ask anything?

Read your lecture notes. Attempt some answers. Post them here and someone will probably help. I'll usually go out of my way to help someone if they're getting no responses, but if you don't ask a question, no one here is going to waste their time explaining your assignment to you.

edit:

Frick. I didn't realize this thread was so old since it was up at the top. Whoops.

BestJewSinceJC 700 Posting Maven

The article I posted explained how Goldman Sachs has been intentionally and illegally exploiting financial markets for profit. Sure, it goes into a lot of detail and financial speak at points, but the premise is easy to grasp: Goldman intentionally caused the spiking of oil prices, the collapse of the .com bubble, etc. For example, the article explains how Goldman knowingly overstated and 'hyped up' the .com days despite knowing what would happen: consumers would lose tons of money and they'd fill their pockets.

BestJewSinceJC 700 Posting Maven

I am suppose to write a method that checks whether a string is a valid password. The password rules are:
1.) A password must have atleast 8 characters
2.) A password consists of only letters and digits
3.) A password must containt 2 digits

I need to write a test program that will ask the user to enter password and Display "Valid Password" if all the rules are followed othewise display "Invalid Password."

Can anyone help me get started...because i have no idea..
Any help is greatly appreciated.

Write 3 different methods. One to test each of the three rules that you just posted above. For example, method one should check to make sure the password has enough characters. You can use the String class for this; Google for "Java String" and start reading the API. One useful method is the length() method.

For part two you can check out the Character class, especially the isDigit method and the isLetter method. Ditto for part 3.

Salem commented: Nice +20
BestJewSinceJC 700 Posting Maven

Variable scope. Read about it. The "args" array only exists within the main method, since that is where it was declared (in the method header). If you want to use it from within your ReadFile method, then you had better declare ReadFile as taking a String[] as a parameter. But more likely what you actually want to do is this:

public static void main(String[] args)throws IOException
	{
	
        ....

	int sizeN = ReadFile(Onum, Snum, args[0]);
	
       .....
	
	}
 	
	public static int ReadFile( double[] Onum, double[] Snum, String fileName)throws IOException
	{
		Scanner fileScan = new Scanner(new File(fileName));
		....
	}
BestJewSinceJC 700 Posting Maven

It'd be helpful if you showed us the code segment that gave you the compiler error.

BestJewSinceJC 700 Posting Maven

How can I create a semaphore using the above functions that will allow any process access to the semaphore? I've been playing around with global variables for hours thinking I was doing it wrong, but now I believe I was misled. I think the problem is that the other processes I'm running simply don't have permissions to access the semaphore. TBH I don't know how to test if this is really true because the return value of semget just indicates whether it was created properly.

oh, and when I test it, the "key" to the semaphore is identical across all my processes - but access is still only being allowed to the single process which originally called semget.


edit:

Solved, nevermind. And I honestly don't know what I did to solve it, :(

BestJewSinceJC 700 Posting Maven

The next() method doesn't get an entire line of text, it only gets the next token, which by default, matches whitespace. So if you're reading in English sentences, it will have the effect of reading in a word at a time, not an entire sentence. The nextLine() method can be used to get the entire line of text, not including the newline character \n. And you can use the String class's equals() method to test whether or not the user simply clicked enter without typing anything else.

public static void main(String[] args) {
		// TODO Auto-generated method stub
		ArrayList<String> list = new ArrayList<String>();
		Scanner keyboard = new Scanner(System.in);
		while (keyboard.hasNextLine()){
			String s = keyboard.nextLine();
			list.add(s);
			if (s.equals("")) break;
		}
	}
BestJewSinceJC 700 Posting Maven

Just so you know, the switch statement you have might need 'break' statements after each 'case' statement is over. Otherwise it will execute the code in the other case statements as well.

BestJewSinceJC 700 Posting Maven

Similarly, parents of any child unwilling to stop that child comitting criminal acts should be treated as an accomplice to that act even if they were not actively involved in the crime. Parents are responsible for raising their children to be law abiding citizens. If they fail through negligence or deliberate act in achieving that, they should pay the price along with their child.

Being an accomplice means actively contributing to the commission of a crime. It has nothing to do with whether or not someone is a parent. Failing at parenting through negligence is not a crime. Even if it was a crime, it is highly subjective.

BestJewSinceJC 700 Posting Maven
if (divmod >= 0.0 || divmod < 0.1)

One of the above two conditions is always true. You wanted to use the && symbol.

if (divmod >= 0.0 && divmod < 0.1)
WesFox13 commented: Very Helpful +2
BestJewSinceJC 700 Posting Maven

Your teacher's suggestion is incomplete.

Either your teacher is trying to get you to
A. Describe an algorithm for figuring out the best possible letter, and placement, of the blank tile (such that it maximizes the point value of the word)
B. Describe an algorithm for figuring out the best possible letter that should be on a blank tile, given its placement.

Which is it? Either way I'm not writing any pseudocode for you, you can do that yourself. Just saying.

BestJewSinceJC 700 Posting Maven
wait(mutex);
...
body of function
...
if (next_count > 0) signal(next);
else signal(mutex);

I think I understand how semaphores work so I understand the wait(mutex) and signal(mutex) operations but despite a couple hours of reading different materials I don't understand the next_count or the signal(next). From my book:

Since a signaling process must wait until the resumed process either leaves or waits, an additional semaphore, next, is introduced, initialized to 0. The signaling processes can use next to suspend themselves. An integer variable next_count is also provided to count the number of processes suspended on next.

The resumed process refers to the one that initially called wait(mutex)? Why does the signaling process have to wait for the resumed process? The whole idea is that only one process at a time can execute the "body of function" code. Once a process calls signal(mutex) it is already out of that section of code, so why should it need to wait for the resumed process?

BestJewSinceJC 700 Posting Maven
number something = 1234;
String s = something + "";
char[] chars = s.toCharArray();

I'm not sure if that will work; you may want to try it though.

BestJewSinceJC 700 Posting Maven

and then have the parent(s)/guardians serve the shortfall of an adult-sized sentence?

If the parent hasn't committed a crime, then they cannot and should not be charged with a crime.

BestJewSinceJC 700 Posting Maven

No problem - mark solved threads as solved

BestJewSinceJC 700 Posting Maven

Use code tags and give better information. What do you mean you "hope that's it"? It is relatively easy to pinpoint a problem to a section of code. Did the code before that point execute properly? Did the code after it ever execute at all?

BestJewSinceJC 700 Posting Maven

You're trying to call the static method as if it is a constructor.

http://leepoint.net/notes-java/flow/methods/50static-methods.html

Read the section on calling static methods.

BestJewSinceJC 700 Posting Maven

You need to use that random number to index the array. So buttons[randomNumber]

BestJewSinceJC 700 Posting Maven
Calendar myCal = Calendar.getInstance();
System.out.println(myCal.getActualMaximum(Calendar.DATE));

That works, I just tested it on my machine. And according to the Javadoc, DATE is a synonym for DAY_OF_MONTH so day of month should work as well. Although it won't mess anything up, you shouldn't use your instance variable (calendar) to refer to a static field (DAY_OF_MONTH). And of course, that method will return the maximum value for the current month (April) so if you are concerned with a different month you'll have to set the Calendar explicitly first.

BestJewSinceJC 700 Posting Maven

Yes! Exactly. You might want to further modify that logic so that if the spot the random number generator is choosing is already taken, then you pick a new spot. You could use a while loop to do that. For example:

Random myRand = new Random();

        int myRow = myRand.nextInt(3);
        int myCol = myRand.nextInt(3);       
            
            while (theBoard[myRow][myCol] == 'X' || theBoard[myRow][myCol]=='O') {
               myRow = myRand.nextInt(3);
               myCol = myRand.nextInt(3);
           }

//At this point, it is guaranteed that theBoard[myRow][myCol] 
//contains neither an 'X' nor an 'O' (it is empty)

....

Keep in mind that if every spot on the board is taken, then the while loop above will never end. So you would also need to add some more logic to keep track of how many times a turn has been taken, and act appropriately (for example, print out 'draw') if the game is over.

BestJewSinceJC 700 Posting Maven

Print out the value that "f.exists()" returns after you create the file. So do

System.out.println(f.exists());

Also, why are you opening two methods of reading from the file? You created a Scanner and a BufferedReader on the same file. Are you sure that doesn't cause a problem? I wouldn't know because I've never had cause to try it. But you need to be much more thorough in your methods of testing for errors and not assume that the root of the problem is any particular thing (unless, of course, you happen to already have evidence or knowledge supporting a particular cause)...

For example, have you tried calling countTokens() on the StringTokenizer you created to see how many tokens it has? Also, for lines 49-54, don't you need to construct another StringTokenizer since you reassigned the 'curLine' variable? Strings in java are immutable, so the info that you originally passed to StringTokenizer isn't going to get "updated". IMO, [I've never used StringTokenizer, so take with a grain of salt] you need to create another StringTokenizer every time after you say "curLine = br.readLine()".