javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

If you decide how the interface would be written try this and tell me:

public interface ComplexNum {

public int getReal();
public int getComplex();

public void setReal(int r);
public void setComplex(int c);

public String add(ComplexNum a, ComplexNum b);
public String subtract(ComplexNum a, ComplexNum b);
public String multiply(ComplexNum a, ComplexNum b);

public void display(ComplexNum a, ComplexNum b);
}

Also I believe that the last methods: (add, ..., display), should be static. Because you don't use any of the attributes and they do nothing to change or display the state of the instance. They just take objects as parameters and use them.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Hi thank you very much for your help it worked. Just another thing, if you can point me in the right direction if I want to print each string on a separate line in a text file. Am I on the right lines with this code.


PrintWriter pw = new PrintWriter("outfile.txt");
pw.println(result);

the txt file outfile.txt is in the same folder as the code.

really appreciate your help.

Create a new class with a main method. In that method put the above code and test it. Once you get it to work, use it in your program, or post the code and ask questions.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

If you look at the API, there is a basic example on how to use it. You can search for tutorials about the subject, or read the methods of the API and see what they do.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

The same thing I told you about the display method applies to all:
These method(int i); and method(); are not the same methods.
So you must implement exactly the same method at the class.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

The interface has this method: void display() The class has this method: void display(ComplexNumb a, ComplexNumb b) So you don't implement the void display() method. You just declared another method that happens to have the same name, but it is not the same method.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

If you are talking about the void display() then no you haven't implemented it.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

The shorthand method returns a String. So call it with argument the line given and print what it returns:

String result = shorthand(s);
System.out.println(result);
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Then why did you asked source code. Maybe we misunderstood your intentions, but no one can give you something that costs that much. What exactly do you want?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

There are other loops as well. Not only the for loop. And check the API. How on earth did you came up with this: sc.length . You cannot just call whatever methods you imagine. That is why you have the API. To see which methods each class has.

Scanner sc = new Scanner(System.in);
boolean cont = true;

while (cont) {
   System.out.println("Enter value:");
   String s = sc.nextLine();

   if ("*".equals(s)) {
     cont = false;
  } else {
     // do stuff with the 's'
  }

}
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Are you referring to a commercial telecom billing system that costs tens of thousands of dollars and a group of many people have worked on that for many months?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

How about JFileChooser class

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

A 2 arg constructor has 2 arguments. Like this:
public CashRegister(ArgType1 arg1, ARGType2 arg2) {..}

Examples:
public CashRegister(double d, int i) {..}
or

public CashRegister(RetailItem rItem, int q) {
  myRetail = rItem;
  quantity = q;
}

Call it like you call any other constructor with the appropriate arguments

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I'm having the same problem. i have printed the SQL string and the syntax seems correct to me. Could the problem be located outside of Java maybe in the database driver?

A new thread by you, with your code and the error merssage, would be helpful

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

"When you are finished, just change the html of that div tag with the results. "

How do I do that? (I'm newbie..)

When the alogorithm at the jsp that you run it finishes, use javascript to change the "innerHTML" attribute if that tag:

document.getElementById("results").innerHTML="";

Or something. I don't remember the exact coding, but you'd better check the w3schools site for javascript tutorials.
Also for the above, I use jquery. It is easier to use AJAX with jquery

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster
public class Dice {
        
    public static void main(String[] args) {

    // Welcome message.

        System.out.println ("Welcome to The Dice Roller Game!");
        
   // Roll the dice.
    	
    		int die1, die2;
    		int rollcount;
    		rollcount = 0;
		int wins = 0;	

Scanner keyboard = new Scanner(System.in);
int userinput=-1;

		do {
			die1 = (int)(Math.random()*6) + 1;
            die2 = (int)(Math.random()*6) + 1;
            rollcount++;
            if (die1 == die2) {
                  System.out.println("You won in " + rollcount + " rolls.");
                  rollcount = 0;
                 wins++;
                 System.out.println("Would you like to play again?");
                  userinput=keyboard.nextInt();
            } else {
                 System.out.println("You didn't roll pairs.");
                System.out.println("Try Again?");
		userinput=keyboard.nextInt();
            }
		}	while ( userinput==1 );

System.out.println("Wins: "+wins);
	}
}

You can change the above code according to your needs

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

The best way would be to use AJAX. When you click the submit button display the message "Please wait" in a <div> tag:

<div id="results">
Please Wait for the operation to finish
</div>

using javascript. The submit button will actually be an "AJAX" submit so you will not be redirected to another page. When you are finished, just change the html of that div tag with the results.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Post more of your code

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

What code did you use?
If I understood correctly, you need to know how to do this: a^b

double a = 8.0;
double b = 1.0/3.0;

double r = Math.pow(a,b);

System.out.println(r);

Check the API for the class: java.lang.Math for more.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Asking others to do your homework is against the rules.
Asking others to do your homework for money is an insult to the people here.
Asking others to do your homework for that small amount (20-40) of money is an insult to the professionals of this forum that get paid thousands of dollars and offer their help here for free!

What I also find insulting is the fact that you said:

You need to have an understanding of UML as well

as If, if someone wishes to do your work for you, you will turn him down for not knowing UML.

Salem commented: Well said! +20
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Even if we wanted to give hints in order to get you started, the description you posted is impossible you understand:

Construct a dissimilarity matrix ‘d’
using the measurement in definition2.

What is this suppose to mean?! Don't assume that we are in your class and know what you are talking about.

And don't post your email, it is against the forum rules. Also if you want some help start by showing what you have so far.

Salem commented: We aren't in their class - unfortunately, they're not in their class either ;) +20
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

There are 2 Date objects:
the java.util.Date and the java.sql.Date. The sql.Date doesn't have a Date() constructor. Only the util.Date has.

If you need both try:

java.util.Date d = new java.util.Date();
java.sql.Date dout = new java.sql.Date(.....);

check their APIs

Although your whole logic is not the best approach. Don't use servlet, for displaying. Forward an object to a jsp page through the request and do the rendering in that jsp page. Don't put html code in a servlet.

Search for some tutorials

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

How about this:

String s = "::::::::::::::::::::::";
        String [] tok = s.split(":");
        System.out.println(tok.length);
        for (int i=0;i<tok.length;i++) {
            System.out.println(">"+tok[i]+"<");
        }

Notice that the length of the 'tok' is zero. But when you do this: String s = "::::::::::::::::::a::::"; The length is not 0.

I think that you can use regular expressions as well with split method. Check the API of the String class

Also I would suggest for you to use the trim method as well:

String s = "    :::::::::::::::::    ";
        s = s.trim();
        String [] tok = s.split(":");
        System.out.println(tok.length);
        for (int i=0;i<tok.length;i++) {
            System.out.println(">"+tok[i]+"<");
        }

When parsing the lines, just to be sure.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Can somebody tell me WTF is "type object pattern" ? :)

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Need java sample code of type object pattern

Thanks

What is a "type object pattern" ?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

The problem that I had was with the settings of the AntiVirus that I was using. Somehow it was set so that it would block Mozila.
You can check that as well.

If you don't have any, you can check also the Vista Firewall.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

post the code you use for editing the single new cell.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Well does it compile?
Do you get any errors?
What is the problem?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Then you can use the method split:

String line = "1,2,3,4,5,6";
String [] tokens = line.split(",");
// tokens now has as elements: {1,2,3,4,5,6}

The split method creates an array with elements the "elements" of the String separated by the delimiter chosen. In this case the ','

After you read the line, get the array with numbers that you need into an array.
Create an int array of equal size with the Stirng tokens array and convert the elements of the String array to ints and put them into the int array:

int [] array = ...
for-loop {
   array[i] = Integer.parseInt(tokens[i]);
}
// sort the int array.
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

From your first post, you say that the notepad has this line:
// this is what the notepad file reads 8,9,7,6,5,4,10,3,2,1
Is it true that the file will have only one line with all the numbers?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I used those terms at yahoo and got lots of info. I combined them with java:
>mutual exclusion java
>atomicity java
>wait set java

The links seem to have lots of info. I don't know any more in order to help you.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Are you sure you are posting your question to the right forum?
Have you tried searching the net for those terms?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Actually what was the problem with the original code was this:

if (a < 0)[B];[/B]
{

}

Semicolon are used to terminate commands. So when you put that semicolon, you terminated the if statement, and rest was printed anyway.
This code is acceptable:

{
 // commands;
}
{
// other commands;
}

Meaning that you can open and close brackets without having to add 'if' or 'while'.
So the ';' terminated the if (); and rest code was outside the if and it was executed anyway.
What you wrote:

if (a < 0);
{
}

Was like writing this:

if (a<0) {}
System.out.println(a);

Or this:

if (a<0) {}
{System.out.println(a);}

When in fact you needed this:

if (a<0) {
   System.out.println(a);
}

or

if (a<0)
   System.out.println(a);
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

When you create a new post, at the first row of the tools, there is a "smiley" icon where you can add smileys.
Next there is another button and next there is a left arrow.
Click the button that is between them.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Reading from a file:

File file = new File("filename");
        BufferedReader reader = null;
        
        try {
            reader = new BufferedReader(new FileReader(file));
            
            String line = reader.readLine();
            int lineNum = 0;
            while (line!=null) {
                lineNum++;
                // DO THINGS WITH LINE
                System.out.println("Line "+lineNum+"="+line);
                
                
                // ALWAYS READ THE NEXT LINE AS THE LAST COMMAND OF THE LOOP
                line = reader.readLine();
            }
        } catch (IOException e) {
            System.out.println(e.getMessage());
        } finally {
            if (reader!=null) reader.close();
        }

Using the lines of the file

// The first 2 lines will give you the size of the array:
int row = 0;
int col = 0;
int lineNum = 0;
int [][] array = null;

while (...) {
    lineNum++;
   if (lineNum==1) {
     // take the first line and put it into the row:
     row = Integer.parseInt(line);
   } else if (lineNum==2) {
     // take the second line and put it into the col:
      col = Integer.parseInt(line);
      array = new int[row][col];
   } else {
        String [] tokens = line.split(",");
        for-loop the tokens array {
            array[..][..] = tokens[..];
        }
   }

// READ THE NEXT LINE
}

The split method takes the line and returns an array with elements the values of the String separated by the ',':

String s = "1,2,3,4";
String [] tokens = s.split(",");
// tokens now has: {1, 2, 3, 4}

So at the else statement, use a for-loop to take the elements of each row and put them into the 2D array. Each row of the 2D array will have the elements of the tokens array. …

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Does the file has to be like that? I mean is it you that decides how the data will be saved?

If you cannot change the way the data are saved then try this:

From what I see you know how to read line by line a file:

while (( line = bf.readLine()) != null)
{
   System.out.println("Line read: "+line);       
}

Create a class Photo like this:

class Photo {

 private String subject = null;
 private String location = null;
 private String date = null;
 private String path = null;

 public Photo() {

 }

// add get/set methods
}

If the file will always have correct data then:
Read until you find the number of photos:

int numOfPh = 0;
Photo [] photos = null;

while () {
 if (line.startsWith("Number of Photos:")) {
     numOfPh = ... ; //get the number.
     photos = new Photo[numOfPh];
 }
}

Then read until you find the line with the "Subject:" . Assuming that the file will always has those 4 attributes with that order then, after you find the line with the "Subject" read the next 4 lines:

int index = 0;
while () {
  if (line.startsWith("Subject")) {
      String subj = line; // get the subject from the line;
      String loc = bf.readLine(); // get the location from the line
      String date = bf.readLine(); // get the date from the line
      String path = bf.readLine(); // get the path from the line

      photos[index] = new Photo();
      // set …
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

hello,
i am making a project on search engine but i want to search link from database and i dont know how to make it can you help me?

Start a new thread explaining where are having problems. Your project seems to consist of many steps. Where are you having problems?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Oh right ok, so how do i decleare the method to return the array1

Why return an array. Do you use that array that you return? To you pass it to a variable.

char [] method() {

}
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

You have declared the method to return a char, but you return a char array. That is the problem.
The method is declared to return a char.

Not to mention that when you call these methods you don't use what they return, so why do you have them to return anything?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

You have been told how to fix it:
static char bookseat(char array1[][])

the methods should return a variable of type 'char'
but you are returning array1 which is of type 'char[][]'

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Given that code the only thing I can think of is when you click the mouse, to get the coordinates of the mouse cursor and to see if those coordinates are inside in any of those images.

Also after seeing your code, and I am not saying that it is wrong, but you'd better try to read some decent tutorials on how to create GUI using the javax.swing.
Try the sun tutorials, or search the net

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Start be declaring the method with the right arguments and return type.
In your math book there should be a parametrized formula with i,j,k indexes for multiplying matrixes. Use that formula, or search the net

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

determineWinner is not static, So call it like the other methods:

Race myRace = new Race();
myRace.determineWinner(..);

You can have it take as parameter 4 Cars and inside based on their attributes decide which one would be the winner. It is also best to have it take as parameter a Car array:

...
Car [] cars = {myCar, newCar, newCar3, finalCar};
myRace.determineWinner(cars );
public Car determineWinner(Car [] cars) {

// returns the winner car.
}

You can have one extra method that compares only 2 Cars and determines which one will win and call that method in the determineWinner, in a loop that iterates the array.

private boolean isCar1FasterCar2(Car cr1, Car cr2) {
   return ....;
}

public Car determineWinner(Car [] cars) {
    for-loop{
       // use known algorithms with the use of the isCar1FasterCar2(cars[i], cars[j])
   }
}
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I need my vector to look something like this:

v1 = {
{att1, att2, att3, att4, att5, att6},
{att1, att2, att3, att4, att5, att6},
{att1, att2, att3, att4, att5, att6}
};

Then why don't you put the "att1, att2, att3, att4, att5, att6" is a class?

Also your hotel class is not quite right:

private Vector roomTypes;
private Vector roomRates;
private Vector roomDisc;

What is the point of having Vector with roomTypes and others? How is it going to be useful if you put all the roomTypes in one Vector? But if you say that each element of those Vectors are a room then try this:

private Vector rooms;

And have each room have those as attributes (roomType, ...)

I suppose that the database has many hotels. But your query is this:

SELECT * FROM hotelrooms WHERE hotelID = '"+hotelID+"'"

So assuming that your database is designed correct then each row of the hotelrooms table will have info of ONE room. That is what the query returns. So why don't you use a HotelRoom object as suggested. Even if: Each hotel has multiple roomTypes, and each roomType has one roomRate, discountRate, ect. as you said, each ROOM will have ONE: {roomType, roomRate, discountRate, ....}

If your database is structured in a way where in one table you have all the roomtypes with their description(roomRate, discountRate, roomTypeId), and another table for the hotelRooms with foreign keys to that table, then your query …

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

(Can i get the class name of Class1 using c)??

BestJewSinceJC's answer was not wrong.

But the answer to the above question, is no. After taking the 'c' instance you cannot programmatic-ally know in which class it was created.
Unless you make some changes.

As BestJewSinceJC said inside method1 you know that you are inside the Class1. So change the Class2 constructor that takes as argument an object. And whenever you create a 'Class2' pass as parameter the object in which Class2 was created. Or better pass the Class of that object.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

What is wrong with creating a class on your own? Like I suggested in one of your previous posts?

Anyway, even though it is wrong, you can do this:

Vector hotel = ....;
for - loop {
  Vector rmDet = (Vector)hotel.get(i);
  // now iterate the rmDet Vector.
}
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

What you described consists of many steps:
1) submit form, send data to the second jsp page and retrieve the "purpose"
2) Call the method that executes the query with argument the "purpose" and returns the appropriate rows from the DB
3) Display the results.

Where are you having problems and what code you have so far?

What are you trying to achieve by repeating other people's posts. Are you trying to get credit for their posts?
Be careful before someone reports you to one of the administrators for spamming.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

What you described consists of many steps:
1) submit form, send data to the second jsp page and retrieve the "purpose"
2) Call the method that executes the query with argument the "purpose" and returns the appropriate rows from the DB
3) Display the results.

Where are you having problems and what code you have so far?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

First of all learn how to read data from the database and proper OOP.
When you copy code you must understand what it does. Not use it blindly:

while(res.next()){
                count ++;
            }

            res.beforeFirst();
..

Where in your code you use the 'count' variable and what is its purpose? Do you understand what that code does? If yes, then why do you use it, since you are already using Vector. When you have vector you don't need the total count.

Also this doesn't do what you think:

while(res.next()){
                roomDetails.add(res.getString("roomType"));
                roomDetails.add(res.getDouble("roomRate"));
                roomDetails.add(res.getDouble("discountRate"));
                roomDetails.add(res.getString("discountValidityStart"));
                roomDetails.add(res.getDouble("discountValidityEnd"));

                hotel.add(roomDetails);

            }

You add data in the roomDetails and then add it to the hotel vector. But at the next loop you add the next row to the same roomDetails instance!!!

After the first loop the roomDetails has: {roomType,roomRate,...,discountValidityEnd}.

After the second loop roomDetails has:
{roomType,roomRate,...,discountValidityEnd, roomType,roomRate,...,discountValidityEnd}.

After the third loop roomDetails has:
{roomType,roomRate,...,discountValidityEnd, roomType,roomRate,...,discountValidityEnd,
roomType,roomRate,...,discountValidityEnd}.

Because you add them at the same instance.

And then you add the same instance to the hotel Vector. That would mean that all the elements of the hotel Vector are the same roomDetails instance, meaning that all the elements of the hotel Vector have something like this:
hotel = {
{roomType,roomRate,...,discountValidityEnd, roomType,roomRate,...,discountValidityEnd,
roomType,roomRate,...,discountValidityEnd,.......},

{roomType,roomRate,...,discountValidityEnd, roomType,roomRate,...,discountValidityEnd,
roomType,roomRate,...,discountValidityEnd,.......},


{roomType,roomRate,...,discountValidityEnd, roomType,roomRate,...,discountValidityEnd,
roomType,roomRate,...,discountValidityEnd,.......},
....
}


The answer:
Declare a class: HotelRoom with attributes: roomType, roomRate, ....
Inside the loop, …

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Ok i changed it, it works thanks......
do you know how or the outline i can use to count prepositions?

What are prepositions?

Anyway, since you have the each line, you can use as "skeleton" the code you have and process the line anyway you want.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

How do you plan to display that image. If you are thinking of using the constructor of the JLabel:

ImageIcon img = new ImageIcon("filename");
JLabel label = new JLabel(img);

Then the JLabel class has an addMouseListener method:

ImageIcon img = new ImageIcon("filename");
JLabel label = new JLabel(img);

label.addMouseListener(mouseListener);

MouseListener

You can put the code that changes the text inside the method mouseClicked of the MouseListener that you implemented, for example.