JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

No.
People here will help you if you want to learn. Nobody will do it for you.
If you are willing to show effort start a new thread and show what you have done.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Simple example of formatting a float into a String:
String s = String.format("Pi = %7.4f", Math.PI);
formats the value of PI as 7 digits wide, 4 dec places (the % character signals a format specification), so s contains
Pi = 3.1416

Slightly more interesting example:
String s = String.format("Pi = %7.4f, e= %5.2f", Math.PI, Math.E);
gives
Pi = 3.1416, e= 2.72

You can do the same thing when printing by using printf instead of println
There's a complete description of all the formatting codes at
https://docs.oracle.com/javase/8/docs/api/java/util/Formatter.html
(plus lots of examples and tutorials on the web)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

required: ArrayList<String> found: ArrayList<Object>

You delare your method as returning a list of <Object>, but the receiving variable is a list of <String>. You can't assign Objects to Strings.

readAllLines returns a List<String> to that's how you should declare your return type and your receiving variable.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I always loose the stack sequence.. I don't really know how to improve this

There's no magic answer. Just step through the code one line at a time and keep a note of what gets called and when. That's what I do (see above for example!)
J

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You just need to get a pencil and paper and work through the order of execution. Something like...

doAnagram(4) calls doAnagram(3) (line 27) before it can call rotate (line 32)
doAnagram(3) calls doAnagram(2) (line 27) before it can call rotate (line 32)
doAnagram(2) calls doAnagram(1) (line 27) before it can call rotate (line 32)
doAnagram(1) immediately returns to doAnagram(2)
doAnagram(2) continues execution and arrives at rotate (line 32)
doAnagram(2) completes and returns to doAnagram(3)
doAnagram(3) continues execution and arrives at rotate (line 32)
doAnagram(3) completes and returns to doAnagram(4)
doAnagram(4) continues execution and arrives at rotate (line 32)

ddanbe commented: Well explained! +15
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

If the term you are searching for can be anywhere in the sentence, then sorting isn't going to relevant, and binary search won't help. If you will always be searchng for whole words, then maybe you could parse out all the words in each sentence and build some kind of map, but it's prpbably not worth the effort. You are stuck witha simple exhauastive search.

If your dataset is small enough to fit in memory the all you need is to loop through all the entries using something like contains(String searchString)to check each entry - just a few lines of code and execution times well within "amost instant".

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You need an InputStreamReader to read and decode text using UTF-16 encoding. You specify the charset when creating the InputStreamReader, eg
InputStreamReader in = new InputStreamReader(myInputStream, StandardCharsets.UTF_16);
Anything you read from that stream will now be interpreted as UTF-16. Depending on your file's byte ordering you may need to use UTF_16BE or UTF_16LE instead.

So: create an FileInputStream for your file, create an InputStreamReader from the FileInputStream, and optionally, wrap that in a BufferedReader for efficiency, then simply read the lines from the file.

ps: I tagged this 'java' so the right people will see it.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

That makes no sense.
In Java a string is an internal data item that holds a single sequence of chars
A table is either a 2 dimensional GUI component or database table
They are completely different things. You can't replace one with the other.

Maybe it's an English problem? Give an example of what you want to do so we can understand.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Sorry, I don't understand what help you need - you have created your classes, you have created various methods, including overridden methods, so now all you need is a bit more of the same. You already know how to do it all.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Your FinalProjectQuestions class is written as if it's a first Java project, not a final.
For a final project then you are probably expected to define a class that holds all the information for a face. You create a new instance using the input that you get from the user, then pass that instance to the class/method where it is needed.

AgentOxegen commented: I kind of understand what you are syaing, but how would I go about doing that. I havent done that stuff before +0
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

If the program uses the value (and if it doesn't then why have it?) then the program must contain some encoded version of the value and some code to decode it for use. In other words there must be enough information in the program to retrieve the value. So a cracker with enough patience can always retrieve that information and thus get the original value.
The only way round that would be to ensure the program does not itself contain enough information - eg by interacting with a server that contains information inaccessible to the cracker.

Aeonix commented: Clear, direct and perfect answer. The only next thing I could wish for, was 5 billion bucks. +4
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

What have you tried so far? Have you created the subclasses like the tutorial I linked?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

OK, some small errors there but it's on the right tracks. What help do you need?

If you are having problems declaring subclasses this tutorial may help:
http://docs.oracle.com/javase/tutorial/java/javaOO/classes.html

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

.java is a source code file so you can't execute it. Yo have to compile it first
Compiled java programs that can be executed come in .class files or .jar files

If you have a .class file, eg myprog.class, then it's executed by javaw myprog
If you have a.jar file, eg myprog.jar, then it's javaw -jar myprog.jar
Full details are here: http://docs.oracle.com/javase/7/docs/technotes/tools/windows/java.html

I don't speak php, so I can't go any further, but if you know how to invoke an executable; (javaw.exe) with a parameter (myprog) then that's what you need.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Please don't be upset by jwenting - he's notoriously grumpy.

There are many tutorials on how to parse XML in Java - just Google for them.
As always, Oracle's own tutorials are probably the most definitive, although not necessarily the easiest:
http://docs.oracle.com/javase/tutorial/jaxp/index.html

diafol commented: I thought his English was adequate :) +15
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

The message is saying:
Your iprint and preprint methods have been defined to require a parameter of type Node1, but when you call those methods you call them with no parameters.

It's aboslutely pointless trying to execute a program that has compile errors like that.

ps: Oxiegen: Where is the no-args instantiation of Node1 you referred to?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You need to delete the local table variable and make sure the real table variable is accessible in the ButtonListener class

Ayoub_1 commented: fixded thanks for the pointer +0
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

the variable table is declared in the listener class but never initialised, so it's null.

Ayoub_1 commented: ther is a nother class that fil the table or i am rong can you pleas point a way +0
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Unless you can tell me the eaxct line where the null pointer exception happened I can't help.

Ayoub_1 commented: line 108 table.getModel().setValueAt(icon, this.row, 5); +0
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Why didn't you post that error message with your first post?

You have a null pointer (unitialised variable) in your button handler. To diagnose it further we need to know which variable that was.
The line number (107) does not correspond to the numbering of the code as you posted it, so exactly which line is that?

Ayoub_1 commented: not shure still pretty new to java plus the code above is not the full version +0
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Yes, you said that already.
Please explain exactly what is wrong - do you get an error message or exception? What happens when you try to run that code?
The more info you give us the easier it is to help

Ayoub_1 commented: Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException at t.Buttone$ButtonListener.actionPerformed(Buttone.java:107) at javax.swing.A +0
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

That's a lot of code to look through with no idea what you are looking for.
Please explain exactly what is wrong - do you get an error message or exception? What happens when you try to run that code?
The more info you give us the easier it is to help

Ayoub_1 commented: i am trying to pute a imag in a cell in the same row after cliking the button in the column "Age" +0
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

OK, what eaxctly is your question?

Ayoub_1 commented: can you pleas look ate my code and tell me were did i go rong +0
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Previous papers are irrelevant. It doesn't matter how many other papers number the root as level 0. In the paper where that statement is made the root is defined as level 1. That's the explanation.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Come on now, loop i from 1 to N? That's the simplest, most common type of loop known to man. You have one on line 27 to use as an example.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

what should the vaule of loop years be if i dont know what the user is going to enter

I don't understand that question!

You have obtained and validated a value for Numyears from the user (lines 11-20).
Now all you need to on line 23 is to loop with i going from 1 to Numyears. You almost have that right a the moment, except that you are changing Numyears when you should be changing iin the loop.

Mark_42 commented: How do i loop i going from 1 to Numyears. Sorry about the confusion ,i have been looking at this for hours.Thanks for your help +0
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Line 23
You are incrementing the final value Numyears when you should be incrementing the loop variable i

ddanbe commented: Great eyesight! +15
Mark_42 commented: what should the vaule of loop years be if i dont know what the user is going to enter. +0
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Yes

Right click in the editor
Insert Code...
Constructor...
click the fields you want to include as parameters

peter_budo commented: Obvious ;) +16
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Lines 1-4 of your code set up the random data.
Lines 7-21 do the sort and report the timing

So repeat lines 7-21, but don't repeat lines 1-4

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

rproffitt: Is this better?

int[] noOfPeopleWithThisBirthday = new int[366];
loop i=0 to number of tries
   noOfPeopleWithThisBirthday[random.nextInt(
    (i%4==0)?365:366)]++
now check array for number of >1 entries etc

(not valid for people over 115 years old; will cease to be valid in 2100)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

With exactly 365 possibilities, why not keep it really simple and use an array

int[] noOfPeopleWithThisBirthday = new int[365];

loop  number of tries
   noOfPeopleWithThisBirthday[random.nextInt(365)]++

now check array for number of >1 entries etc
rproffitt commented: Leap year? +6
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Interesting...
This exact requirement can be handled without storing all the input values, so it doesn't need an array (or list). What's interesting is what happens when the next exercise says "... and print all the values that are more than 2 standard deviations from the mean" (or any other output that requires you to know the total/average/whatever before processing each value)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Yes, but tag it UML as well. (I'm a huge fan of sequence diagrams as a tool for allocating responsibilities to classes, especially as a group activity around a whiteboard).

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Never used it myself. GridBagLayout does everything I need, and I have a strong dislike of using third-party anythings unless I have to.

Doogledude123 commented: Thanks for the feedback :) +3
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

the recursive one run in O(log(n)) and use O(log(n)) memory because you keep push high and low into the stack.

Not necessarily. This is a case of tail recursion, so there's no need to consume stack for each call. Some compilers will automatically optimise the call/stack allocation out and replace it with effectively a simple goto (although sadly the current Oracle Java compiler isn't one of those).

See http://www.drdobbs.com/jvm/tail-call-optimization-and-java/240167044

invisal commented: Good point for mention about "tail recursion". +9
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

A binary search partitions top/bottom halfs, then does the same for the appropriate half and continues until it's found the result. That is a recursive algorithm.
It would be natural to implement that with recursive code. However, it's possible to write the code without using recursion, ie an iterative version, and there may be technical efficiency reasons why you would do so.

so does it mean for 2nd function it will be low of 4, high of 9 and then mid of 6...?

Yes, you've got right idea. But because [4] wasn't the target value there's no point including it in the next search, so [5] - [9] would be better

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Now you have the Method object you can call it by using Method's invoke

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Yup
That toString() is in the Client class, but its an instance of one of the other classes that's being printed.
You need an appropriate toString() method in each and every one of your classses.
that you want to print.

overwraith commented: Yes, I see his problem now, that's exactly what is going on. +3
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

RegistrationDetails registrationDetails = new RegistrationDetails();
that version is almost certainly a mistake. The name is presumably mandatory. What use is a registration without a name?

So in your Client class you get a name and create a registration using that name. OK

Now in your report class you need to access that same registration, so you can call its getName() method. Exactly how you do that depends on how it's all set up - and I can't tell that from what you have posted. One possibility is that you create a new Report object for each report, and you pass the registration obect as a parameter to the report's constructor.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

OK
Get a grip.
Ask one sensible question, and show some effort if you want help.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

OK Bobby. You posted an entire project requirement doc (I hope you own the copyright to that!). Why? What response do you expect?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

IF you really do have a lot of drawing that is repeated without being changed and if that is consuming a significant amout of resources, then yes, there MAY be an advantage in pre-rendering it.
If so, just create a BufferedImage, and call its createGraphics() to get a Graphics2D that allows you to use your existing drawing code to draw directly to the BufferedImage.

.. but we've spoken before about premature optimisation... ;) J

Doogledude123 commented: yes, we did :P +3
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

First, some notes on your question:
You can't assign a method to an ordinary variable; you assign the result of calling that ethod.
You can't call variables, just methods.
The code you posted is not a constructor, it's jst an instance variable with an initialiser.

Anyway...
The Calculation a is created on line 2, and used on line 15. Between those there is no code that could calculate a total promotion, so at line 15 its not surprising that getTotalPromotion() returns null.

Presumably when you print a.getTotalPromotion() you are doing that somewhere else in the code - at which point the total promotion has been calculated.

ps: You created three Scanners - almost certainly a mistake. Review your notes on how to use a Scanner.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

He's right.
Think about it. What is the result of5/100in integer arithmetic?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Without actual code one can only make wild guesses, for example:
When you copy the populations is that a shallow or a deep copy? Maybe its a shallow copy and subsequent changes to members are affecting both copies?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Maybe the code isn't of the highest professional standard, but honestly it's not particularly messy either. Good enough for an early-stage learner. So what EXACTLY do you need help with?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

No, it was the list that you had in your previous code.

Adding items to a JList goes like this:
JLists keep their data in a ListModel (that's defined as an interface). You can write your own, but Java gives you a sensible one called DefaultListModel. You can add and remove stuff from the ListModel and the JList will update itself accordingly automatically. Use it like this:
Create a list model, create the JList using that model, add stuff to the model

DefaultListModel myListModel = new DefaultListModel();
JList myList = new JList(myListModel);
myListModel.add(new Person(name, age)); // as required

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

It would help if you gave some better info than "it wont let me".
If you have a compiler or runtime error message post the complete message plus the actual code it refers to. If your code is giving an incorrect result explain what result you get and what the correct result should be. If you don't know how to code something explain exactly what it is.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Here's a very simple example. Experiment with somethimg like this:

// container for info about one person
class Person {
   String name;
   int age;
   public person(String name,int age) {
     this,name = name;
     this.age = age;
   }
   public String toString() {
     // controls how a Person will be displayed
     return name + " is " + age;
   }
}

...

// create new person using data from entry fields
// then add the person to a suitable list
String name = nameField.getText();
int age = Integer.parseInt(ageField.getText());
list.add(new Person(name, age));
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

OK
It looks like you should have a class that encapsulates a Parcel with all its data fields. That's how you implement a "storage/container" in Java. You can create an instance of the class from the data in the text fields. (NB: that's the text in those fields, via getText(), maybe converted to ints or whatever,, not the fields themselves.
They can go into a list of Parcel objects.
You can add those Parcel objects to your JList. By default, the JList will call toString() on each object to get the text to display, but you can override that to just display the ID by using a ListCellRenderer (although it may look better to display more info than that, in which case just implement toString in your Parcel class to return a suitable string for display.)