JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Three things
1. You can't test your Strings with == (are exactly the same object). You have to use String's equals method (have the same sequence of characters in them)
2. If you delete entries from one array but not the others they will get out of step and your data will be garbled. You need to test all three, decide whether to delete, then delete from all three together.
3. It's not enough just to move one entry down, you need a loop moving all the following entries in the array.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Thats null, not NULL, of course.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

What did you try? All you have shown is return 0;
You just need a loop that goes through the array checking each entry to see if it matches the patterns, and deleting it if it matches.
You can't just "delete" an entry in an array like that - you have to move all the entries after it down one position, then update the size variable to match.
eg if you have an array with values
1, 2, 3, 4, 5, 0, 0, 0, 0, 0 size = 5
and you want to delete the "3" entry, then after deletion you should have
1, 2, 4, 5, 0, 0, 0, 0, 0, 0 size = 4

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I tried this in NetBeans, latest Java 7. Just printed the allocation/1000. Ran it 100 times in a loop... I Got

memory used by allocation (k):1958
memory used by allocation (k):16
memory used by allocation (k):16
memory used by allocation (k):663
memory used by allocation (k):663
memory used by allocation (k):663
... the 663 same for the rest of the 100 iterations

I'm just going to add Java Garbage Collection to the long list of things I don't (need to?) understand!

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You also seem to be reversing the original number, whereas the "right" answer reverses the doubled value.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I believe that each and every instance has a minimum 8 byte fixed overhead and is aligned on an 8 byte boundary in the current Oracle JVMs (obviously this can and will vary with versions of the JVM). On that basis I would expect 16 bytes per instance.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Also note that Integer is a class, so you are creating 1000 new instances of that class. That's not the same as 1000 ints (primitives) that would be just 4 bytes each

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Changing the println on line 4 to a print will eliminate the newline that your automated test dislikes.

I have no idea how you are expected to get the right result if you haven't been told the input value that was used.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

That is totally ridiculous. The "error" seems to be that your output is on 2 lines instead of one (although two lines is better IMHO). What is the celsius temp that was input? - the output doesn't show it.

ps: You must read kal_crazy's post. It's essential.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Please post the exact complete error message(s).

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

In Java when you enter a floating point literal like 9.0 the compiler creates a double value, not a float. That's where ypur doubles are coming from. So when you then assign that value to a float you have a possible loss of precision - hence the warnings. Either make your literals floats (eg 9.0f) or, better, make your variables doubles.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Did you read my previous post? I explained why you get precision-related errors, and how to fix them, but you seem to have ignored it.

<M/> commented: sorry +9
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You have to import java.util.Scanner; to use the class name "Scanner" without fully-qualifying the name.

The constant 9.0 is a double value (that's how the language is defined), so the calculation is done in double, with a theoretical possible loss of precision when you assign that result to a float. If this bothers you either make all your variables doubles, or change your constants to float (eg 9.0f).

Apart from that there's nothing wrong with your code.

<M/> commented: thanks :D +9
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

That code (with a Scanner declaration for kbinput, aqnd placed inside a method) compiles without any errors or warning in NetBeans, and gives the right answers when executed. Maybe the problem is not in that code but caused by something in the rest of the class?

<M/> commented: :D +0
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

No.
What are you trying to do?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

That's right - the jar file (etc if needed) is placed in the dist folder when you build & clean, replacing anything that may have been there before (so don't put anything in here yourself!).
Mark this "solved"?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You could play with something like this, which is just those simple rules:

        String regex = "(0|\\+33|0033)[1-9][0-9]{8}";
        String data = "0512345678";
        System.out.println(data + " is " + Pattern.matches(regex, data));
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

That presumably works because you called the renderer yourself in order to initialise it (normally there's no reason to do that).
If your renderer is for all the cells in the table it's easier to just to call setDefaultRenderer for your JTable once, as in
myTable.setDefaultRenderer(new CustomRenderer());

ps I'm very happily married, so your love must remain unrequited. Sorry. :)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I suppose you did remember to call setDefaultRenderer or setCellRenderer (for the relevant columns)?

And did you setOpaque(true)? because the default renderer is a JLabel, which is opaque(false) by default, so it never shows its background colour.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Are you looking for a Java-specific solution or something more general, eg a regular expression.
Are you just looking for the following rules:
( "0" OR "+33" OR "0033" ) followed by a non-zero digit, followed by exactly 8 digits, blanks to be ignored?
... if so it's the same pretty simple regex, whether you use that in Java or somewhere else.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

A. Develop a working application that implements an interface.

So far you have no interface in your code. If only to meet the requirements of the exercise you could make Lootable an interface - it already sounds more like an interface (it's an adjective) not a class (its's not a noun).

If you look at primary sources, like Oracle's own documentation, you will see that it refers to "implementing" an interface by implementing its methods. Your tutor's use of "overriding" in point 2 seems to be a mistake; I would assume they mean "implement" - but as always if your tutor is wrong it's safer to stick with their version at least until yur paper has been marked!

StephenopolousINC commented: Thank you you are correct I did not have and interface. I have rewritten the code to use and interface just to check and see if the various containers are lootable. I could still use some help with adding some overriding to my app. I will post the code be +0
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Java binds instance methods at run time, so when it executes objecty.playMusic(); it looks at the actual object that refers to, and uses its methods as appropriate. The type of the reference vaiable is not relevant at run time, it's just used at compile time to ensure that any object referred to by that variabke will have a playMusic() method.

(static methods, on the other hand, are bound at compile time)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You're welcome!
J

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You have the info, now that's for you to decide. Nobody else can decide that for you.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Try sitting down with papaer and pen. Do a test case or two by hand. Then you'll know exactly how it works.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

That's right.
You can build a simple web server in Java SE quite easily - just a page or two of code, but if you want anything more sophisticated you need to go to Java EE (servlets / JSP) or a third-party environment.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

There you go! The Text class has a variable called "text" that presumably holds the "humpty" or "dumpty" or whatever. That's what you can return from toString, so one of those values is what you will see when you print a Text object

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Yes, that's the kind of thing. The programming style is a bit C-like, and the three almost-identical code blocks are in need of rationalisation, but overall the logic is exactly what I expected.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You haven't posted the Text class, but I'm guessing that has an instance variable with the word/text for each instance? It like my Person example - the Person class has givenName and familyName vaiables, so that's what its toString() returns.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

OK.

Every class has a toString() method. If you don't provide it then you inherit one from the Object class. The one you inherit gives you those strings like "Text@44ac8dff".

toString() is automatically used by print to get a String version of anything you want to print. If you want something more friendly than Text@44ac8dff then you provide your own toString() for your class.

Take another look at the example I gave earler for a Person class. You need to add a method like that (exactly the same name and return type) for your Text class. In it you should return somnething that makes sense to you - eg if the Text class has a variable that holds the word, then that's what you should return.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I guess you didn't bother to read my previous post...

Every Java class inherits a toString() method from the Object class, so methods like println use that to convert the object you want to print into a String. The inherited method prints the class name and the object's hash (normally the same as its address). If you want to display something more helpful, override the toString method in your Text class to return a useful string.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Did you create your own toString() method in the Text class?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Text@44ac8dff appears 1 times - what's that Text@44ac8dff about?

Every Java class inherits a toString() method from the Object class, so methods like println use that to convert the object you want to print into a String. The inherited method prints the class name and the object's hash (normally the same as its address). If you want to display something more helpful, override the toString method in your Text class to return a useful string. Eg

class Person {
    private String givenName, familyName;
    ...
    @Override
    public String toString() {
        return "Person: " + givenName + " " + familyName;
    }

You should do this for every class you create so when you print an instance you get useful output.

ps: enhanced for loops - really a lot easier and safer than the old-style loops -- definitely a thing you should learn. Eg see http://www.deknight.com/java/enhanced-for-loop-in-java-5-0.html

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Helpmeplease123:
This is not a "we do your homework" service. Try to solve your problems yourself before asking for help. For example, 30 seconds with Google will give you all kinds of information and examples of using ArrayLists. Before asking for any more help, show that you have made some effort yourself first.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

stultuske: its totally obvious that this is a task that he has been set. Yes, it makes no real sense, but as a programming exercise he has no choice but to program it as specified.

Necrozze: One way is to loop through the strings taking one character (ie digit) at a time starting at the right hand end, add those, carrying a 1 forward if necessary, and build the result string.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

What's the context for this? Are you extending Hashtable for your own purposes? Is this a complete new implementation of a hash table?

Did you see that Hashtable is obsolete? "If a thread-safe implementation is not needed, it is recommended to use HashMap in place of Hashtable. If a thread-safe highly-concurrent implementation is desired, then it is recommended to use ConcurrentHashMap in place of Hashtable." (Hashtable API doc)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

That link is just for controlling layout by automatically inserting blanks - it is not a solution for using italics.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

How about writing your text as an HTML file. That's really easy.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I use that code in many programs without problems. Can you show the actual contents of your jar file (use any zip utility to open it)?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

returnString = " " + ((Item)iter.next()).getDescription();
discards any orevious data in returnString.
How about
returnString = returnString + " " + ((Item)iter.next()).getDescription();
top keep the existing values

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Line 69 ypu declare a new newEnergy boolean - looks like that may be masking class-level variable of the same name?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Post what you have done here and someone will help. Explain where you are getting stuck - more more info you give the better we can help.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Hi Pob, welcome back!
You can use something along the lines of

BufferedImage image = 
     ImageIO.read(getClass().getResource("/images/xxx.png"));
myMainWindow.setIconImage(image);

wher /images is a folder in the same jar that the current class was loaded from

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

That's just an example of the kind of code you should use to print the variables at the point where you get the NPE. You were supposed to understand it, then apply what you have learned. It sounds like you copy/pasted it to some random part of your code.
That's it from me tonight.
J

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Not brain surgery, just like any other print. eg

System.out.println("anItem = " + anItem + " getName returned + "anItem.getName());
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Step 1:
Find out which variable or method return value is null on that line by printing each of them out. In particlual check whether anItem.getName() is returning null.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You just copy/pasted your assignment without even a moment taken to explain what help you need. That's highly disrepestectful to the many people who give their time to help others here.

There are lots of people here who will freely give their time to help you become the best Java programmer you can be. There's nobody here who is interested in helping you cheat or doing your homework for you.

DaniWeb Member Rules (which you agreed to when you signed up) include:
"Do provide evidence of having done some work yourself if posting questions from school or work assignments"
http://www.daniweb.com/community/rules

Post what you have done so far and someone will help you from there.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You probably have got confused about how to use generics.
You have defined type parameters for your class and named them "String" and "Integer". These names are hiding the classes with the same name, so on line 2 and 7 "Integer" is a type variable, not the Integer class.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Postscript:

Yes, String s1 = "asdf"; is the way to do it. The other form is useless.

But if you look on the web you will find one justification for new String, which is based on taking a small substring from a very large string. That was valid up to Java 1.6.20-ish, but after that the internal implementation of substring was changed to always create a new string. So if you are using any current version of Java the substring justification is no longer valid.