Tarek_2 26 Light Poster

Hi,

  1. This algorithme will have a O(n) complexity : you will check all the tree, so the "binary" particularity doesn't change things.
  2. cout excutes :
    1+3+6+10+15+21+...
    Sum of (1+m)(m/2) and m changes from 1 to n
    To simplify, it will b a O(n³) (I think)
Tarek_2 26 Light Poster

Hi,

The first code seems correct, not really pretty, but correct. I would write :

    public boolean addIfAbsent(UserBean userBean) {
            if (users.stream().anyMatch(x -> x.getUsername().equals(userBean.getUsername()))) {
                return false;
            } else {
                users.add(userBean);
                return true;
            }
        }
    }

And I would call it in the if statement.

The second code seems to present two problems :
The first one is on the line 23 :
You have created a DepartmentBean called dp on line 14 and you have used it in the if condition on line 25, but the call on line 23 uses another object. dp is never used so its "f" is always false.

The second one is on line 25, you must use "==" to check equality, or just put dp.f because it's a boolean.

Good Luck.

Tarek_2 26 Light Poster

Hi,

You have two characters here :

The 0A (10) is the "new line" character,
The 0D (13) is the "return to start" character.

You're not in a binary file, you're in a text file so you must check the ASCII code to know which charcter has the displayed value :

http://www.asciitable.com/

Good Luck.

Tarek_2 26 Light Poster

Hi,
You must check your CSS selector here : img.resize means the tag img with the class name .resize somthing like :

<img src="/path/to/image" class="resize" />

Otherwise it won't work.

Check this course

Tarek_2 26 Light Poster

Hi,

It's a parsing code, and as Venkat Subramaniam said : "don't show your parsing code to any one, it is always ugly" :)

So, start by looking in "seminar.txt".

Tarek_2 26 Light Poster

Hi,

I'm not really sur but isn't there a "public" directory or this is something usual in JNode.
Also, you may add Javascript tag instead of Java tag.

Tarek_2 26 Light Poster

Hi,

I highly doubt it's possible. If we don't know the class structure than we can't use it after parsing.

I have seen (in Groovy) examples where the JSON object is converted into a map and you can, after that, get all keys and values easily.

I have found some examples with Jackson here.

Good luck.

Tarek_2 26 Light Poster

Both answers (one table, many tables) are correct but you must choose the right one. So, you must answer this question :

"Does Category have any useful additional information ?"

If Yes then you must create it as a table.
If No then you must keep it simple and use one table.

A table that contains one column (the auto increment id is not a usefull additional information) can be ignored.

Tarek_2 26 Light Poster

I will assume that this is your first try and you are new to this so let's start together :

StrongTEETH4U is a private dental clinic that is well known and has an excellent reputation in the area. All patients in the clinic have their details stored in a ClinicBook database. This database is used by the dentists and secretaries in the clinic to contact the patients for their routine checking and remind them of their appointment dates.

All this part is a simple description of the system, we can understand that there are patients and dentists. Let's see farther.

A patient has a patient number (a unique value), first name, surname, house/flat number, street, city, P.O. Box, telephone number, a first admission date to the clinic, the date of next appointment (if any!), and the dentist ID that has treated the patient.

Patient and his attributs, one Entity. A unique value means it's the primary key.

Patients have to register when they first attend by calling in to the clinic and provide a secretary with their details.

I don't see any additional data in this part.

Patients have to have appointments created for them by dentists and secretaries in the clinic before they can be seen or treated, and the date of the appointment along with the other required details is stored into the ClinicBook database.

Some tricky parts : is the appointment a Relationship or an Entity, it does not have a proper primary key, it …

Tarek_2 26 Light Poster

In addition to what stultuske has said, you can use t and c directly because they are the content of the JTable row.

Tarek_2 26 Light Poster

Two methods in the same class :

JOptionPane.showInputDialog()
JOptionPane.showMessageDialog()

Documentation here : https://docs.oracle.com/javase/7/docs/api/javax/swing/JOptionPane.html

But, as others have said, you must be able to : convert from String to int, manipulate arrays (small ones at least) and may be loops to write a proper solution.

Tarek_2 26 Light Poster

In the first loop, you have a block so, I think it must be :

do {
    //
}while( //condition);

In the second loop, I don't get the first line :

mark += ranges.length;

I think you must rethink a good part of the program.

Tarek_2 26 Light Poster

And I will add the following : in the begining, the first version of your code, it is recommanded to not mix actions; separate reading from checking. Read what you need to read then check the result in the while condition even if that means you need to put the same line twice (before and inside the loop block). The code will be easier to read and you can log (print) the content to check if it's correct.

Tarek_2 26 Light Poster

First, choice2 is supposed to be an integer (int) but in the while condition, we can read (choice2=true)
Second, choice2=true is not a comparaison, it is always true. I think you should use choice2==true and here again choice2 is supposed to be compared to an int value not a boolean value.

Tarek_2 26 Light Poster

Good, very good. Now we will all our code inside the main method, but first : remove the lines 1, 2, 3 and 14.
Now lets assume that the gold worth is fixed, lets try some values then return to that point later.

So, lets be :

// double to get the maximum size and precision
double goldWorth = 30000;

Now, we need the calculation, but we can not write 2.5%, this % sign is the problem, so we must take the equivalent value of 0.025 :

double zakat = goldWorth * 0.025;

// Lets print to the screen
System.out.println(String.valueOf(zakat));

Try the previous code with different values of goldWorth.
Then we will proceed from there.

Tarek_2 26 Light Poster

Well, start by creating a new project, kept the "Main class" option checked, open your main class and we will continue from there.

Tarek_2 26 Light Poster

Hi,

I think you're juste starting so let's be simple :

  1. You already have the statement that generates the random number,
  2. All you need to do is an if...else to check if the random number is > 90 && < 100 to display A
  3. Start by one value of the random integer and only one grade letter
  4. Adding some else if should be easy after that
  5. Puting the whole thing in a loop should also be easy.
Tarek_2 26 Light Poster

Hi,

If it must run in a web browser then you must learn (or search codes in) J2EE (Servlets/JSP) not simply Java (J2SE).

Good Luck.

JamesCherrill commented: Not true. SE is perfectly capable of doing a login form (or forum) -3
Tarek_2 26 Light Poster

Hi,

The statement :

printStream = new PrintStream(new FileOutputStream(fileName, append),  autoflush);

Creates the file but does not write into it.
You must write in the file using : printStream.print()

More details

Tarek_2 26 Light Poster

Hi,
If I get it right, your problem is on the front end : how to format the display ?

First, the most used format are XML and JSON because they allow us to use in-built parsers , so you won't be stuck in string processing.
To create a JSON response, you can check this example :
https://www.youtube.com/watch?v=zESNqWcY0pY
Adam Bien is an amazing guy who works with J2EE and Micro web services and here he gives a simple way to build a JSON response. You can see that yu can use "builders" to build the response so there is no need to generate the manually the JSON code.

Second, on the front end, I don't know a largely used API to do so, there is some small APIs like : https://plugins.jquery.com/jsontotable/
But you can easily use built-in parser to create Javascript objects from Json.

Good Luck.

Tarek_2 26 Light Poster

Hi,

In this particular case, personally, I don't use any APIs, I simply generate a csv file which can be opened directy in Excel like any other Excel file.
CSV format is a text format wich means a simple FileWriter can be used without any external APIs.
The generation takes only one loop, the simpliest one whith a :

while(resultSet.next()){
        String line = resultSet.getXXX(1) + "\t" + resultSet.getXXX(2) + "\t" + ...;
        bufferedWriter.write(line);
        bufferedWriter.newLine();
 }

I will other answers about apache's API, I have never used it so I think I will learn something useful.

JamesCherrill commented: Excellent suggestion - keep it simple! +15
rproffitt commented: Cheap, Simple, and Valuable answer. +11
Tarek_2 26 Light Poster

Hi,

I don't think isValidateRoot() means what you think it means; I don't think you need it here. You have two JTextField, one for the inputs, the other for the result, so what's the problem? All buttons will use the same JTextField.

Tarek_2 26 Light Poster

I agree with JamesCherill, it can be a design problem, and the solution you propose is probably false : restarting a server aims to clear the cache or to erase temporary data; disconnecting and reconnecting the client can't guarantee that.

Tarek_2 26 Light Poster

The java code seems correct, check the SQL query in your jrxml file.

Tarek_2 26 Light Poster

Interesting, I see the java famous "import" and "string" is a data type, the main method is almost the java one, but without creating a class to test few lines of code.

Tarek_2 26 Light Poster

Hi,

JamesCherill is right, you must use the size variable not the DEFAULT_SIZE, but you need to initialize it :

public Queue(int capacity)
{
    elements = new int[capacity];
    size = capacity;
} 

Annother probleme : before adding an element you must check if the queue is full or not, and before retreiving an element you must check if the queue is empty or not :

//adds integers
public void enqueue(int v)
{
    if(!isFull()){
        elements[tail] = v;
        tail = (tail + 1) % DEFAULT_CAPACITY;
        count++;
    }
}
//deletes integers
public void dequeue(int t){
    if(!isEmpty()){
        t = elements[head];
        head = (head + 1) % DEFAULT_CAPACITY;
        count--;
    }
} 
Tarek_2 26 Light Poster

Hi,

We can't do your homework, you will learn nothing.
But, some hints may help you ;

  1. It's evident that you need to use a loop inside another one :
    The first loop is to create many lines,
    The second one is to print many stars or dots.

  2. The second loop uses the first loop's index : the number of dots or stars per line is the number of the line itself (the first loop index).

  3. "Alternative" means "boolean" : use a boolean to change between dots and stars, the boolean changes its value in the end of the first loop.

Good Luck.

Tarek_2 26 Light Poster

Hi,

I don't know if I came too late, but there's a simple solution, especially if the exercise concerns loops, you can make successive subtraction of 2 util the value is less than 2, if the final result is 0 then the number is even, otherwise the number is odd.

Tarek_2 26 Light Poster

To resolve this, you must use the try-catch differently : your methods must throw exceptions not catch them, and the try-catch bloc will be in the enterJButtonActionPerformed method.

A simple tutorial here

Tarek_2 26 Light Poster

Hi,

If I understood your request, you're searching how to create and manage advanced data structures in Java.

If that's it, you may look toward "Java Collections" also called "Collection API" :

Offical Doc on Oracle website

Good reading.

Tarek_2 26 Light Poster

Hi,

I agree with all what have been said here.
I want to add a tiny trick : in applications with GUI, the developer might have put some .printStackTrace() from the Exception class.

Click Here

This method uses the console as an output which is invisible from a "double-click" launching, to see those messages, you can try the command line:

java -jar MyApplication.jar
Tarek_2 26 Light Poster

Hi,

private class KellyCoffee<Order> extends Queue implements OrderLineInterface

Otherwise, the declaration seems wrong : a class can't extend herself.

Tarek_2 26 Light Poster

I'm not sure I understand what you want to do here (first of all, the code is not readable"), but what I know, your "perm" array is not a matrix.

Tarek_2 26 Light Poster

If you know Java then you know Eclipse. Eclipse is an IDE which can make your life easier, it helps you when you compile, build and manage your project. It can help you with code completion and refactoring (renaming variables, etc.). It has also some plug-ins to connect to databases, design your GUI and deploy your application on webservers.
So just download Eclipse and start using it.

Tarek_2 26 Light Poster

Hi,

I agree with Ewald, but if you search a simple solution (if there is no message to passe from the first applet to the second) you can make a simple redirection to the html page wich contains the second applet. In this solution, you will have two web pages, each page contains one applet. To realize the redirection, you can use :

getAppletContext().showDocument()

A simple example is given here :

Click Here

Good Luck

Ewald Horn commented: Nice idea. +3
Tarek_2 26 Light Poster

Hi,

To disable or enable a button in java, you can use the setEnabled method :

Click Here

Now, to detect changes in the frame, you must add a listener to the components you want to watch, every component has its own events.

Tarek_2 26 Light Poster

Hi,

And what's the problem, you have the GUI Building tools in Eclipse and NetBeans, a few mouse click and you'll have it done.

Tarek_2 26 Light Poster

Hi,

Yous are applying the style "on the next letter" not "the last letter", and that's why you have the style is "applyed late".

So, you must use the other setCharacterAttributes :

Click Here

Tarek_2 26 Light Poster

Hi,

Yous are applying the style "on the next letter" not "the last letter", and that's why you have the style is "applyed late".

So, you must use the other setCharacterAttributes :

http://docs.oracle.com/javase/7/docs/api/javax/swing/text/DefaultStyledDocument.html#setCharacterAttributes(int,%20int,%20javax.swing.text.AttributeSet,%20boolean)

Tarek_2 26 Light Poster

Hi,

You have to do this on two steps : read lines then extract the 1 and 0 after.

// This code isn't ready to be ran, put it in a method
// Openning the file

FileReader fr = new FileReader("transa.txt");
BufferedReader buffer = new BufferedReader(fr);

int digits[][] = new int[NBR_COLUMNS][NBR_ROWS];
int actualLine = 0;

// Reading the file, line by line
String line = buffer.readLine();

while(line != null && !line.equals("")){

    String theDigits[] = line.split(" ");
    for(int i = 0; i < theDigits.lenght; i++){
        digits[actualLine][i] = Integer.parseInt(theDigits[i]);
    }
    actualLine++;
    line = buffer.readLine();

}
Tarek_2 26 Light Poster

Hi,
I found you this quick tuto, may be it'll help you :
https://blogs.oracle.com/roumen/entry/setting_up_derby_database_in

Tarek_2 26 Light Poster

Hi,

To not complicate things and to avoid adding an if..else you can try to stop the loop before the end of the array :

    for(int i=0 ; i < myArray.length - 1 ; i++){
        System.out.print(myArray[i]+",");
    }

Then, write the last element :

    System.out.print(myArray[myArray.length - 1]);
Tarek_2 26 Light Poster

Hi,

There is my try :

public double calculate(double hours) throws Exception{

    double fees = 0;
    if(hours <= 3){
        fees = 2.00;
    }else{
        if(hours > 3 && hours <= 24){
            fees = 2.00 + (hours - 3) * (0.50);
            if(fees >= 10)
                fees = 10;
        }else{
            if(hours > 24)
                throw new Exception("Max hours is 24");
        }
    }

    return fees;

}

So if hours is greater than 24, the method don't give back any value, instead, it will throw an Exception which can be treated in a try...catch.

Tarek_2 26 Light Poster

Hi,

I'm Tarek, I have a Master Degree in IT, I worked on e-Learning technologies. Currently, I teach programing basics in Pascal, Delphi, C and Java (only the basics :) ) and of course I like to program and to learn new things.

Happy to be with you.

Tarek_2 26 Light Poster

Hello, Siphokazi and Welcome.

Tarek_2 26 Light Poster

Hi,

You can use the "add" method in the ArrayList class :
http://docs.oracle.com/javase/6/docs/api/java/util/ArrayList.html

// Add an exam in the end of the array list
myExams.add(e);

// Add an exam in a specific position in the array list
int position = 3; // Example
myExams.add(position, e);