javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Inside the overridden method use code that checks the color. If it is purple, don't change it

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Assuming that you are using java 1.5 or later then:

public class SomeObject implements Comparable<SomeObject> {
    

     public boolean equals(Object obj) {
         if (obj==null) return false;
         if (obj instanceof SomeObject) {
               SomeObject so = (SomeObject)obj;
               // write your code here that compares the values of the so attributes with the attributes of this class.
         }
         return false;
     }

     public int compareTo(SomeObject o) {
          // look at the API of the Comparable interface. It explains how this method should be implemented.
     }
}
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I believe the set and get methods are used for code reusability...?

This is what happens when I try to run the program.

Please enter radius of circle:4
The radius of the circle is
Exception in thread "main" java.util.IllegalFormatConversionException: d != java
.lang.Double
at java.util.Formatter$FormatSpecifier.failConversion(Formatter.java:399
2)
at java.util.Formatter$FormatSpecifier.printInteger(Formatter.java:2708)
at java.util.Formatter$FormatSpecifier.print(Formatter.java:2660)
at java.util.Formatter.format(Formatter.java:2432)
at java.io.PrintStream.format(PrintStream.java:920)
at java.io.PrintStream.printf(PrintStream.java:821)
at Circles.displayMessage(Circles.java:29)
at CirclesTest.main(CirclesTest.java:23)
Press any key to continue...

The stack trace tells you exactly where the error is. It would be helpful next time to read it and if you can't fix it, to point where that line is at the code you posted.

Exception in thread "main" java.util.IllegalFormatConversionException: d != java
.lang.Double

at java.util.Formatter$FormatSpecifier.failConversion(Formatter.java:399
2)
at java.util.Formatter$FormatSpecifier.printInteger(Formatter.java:2708)
at java.util.Formatter$FormatSpecifier.print(Formatter.java:2660)
at java.util.Formatter.format(Formatter.java:2432)
at java.io.PrintStream.format(PrintStream.java:920)
at java.io.PrintStream.printf(PrintStream.java:821)
at Circles.displayMessage(Circles.java:29)
at CirclesTest.main(CirclesTest.java:23)

The error is at the displayMessage method of the Circles.java file at line 29.

The getRadius method returns Double, which is an object. The printf method: "The radius of the circle is \n%d!\n"
expects a double primitive type.

So I think that if you change the return type of the getRadius method to double should correct your problem.
It is better, when you create get/set methods, to have the argument of the "set" and the return type of the "get" to be exactly the same type as the variable used.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

You are using something which is null. The error tells you the line where that happened. Also you are trying to close the 'stmt' variable but you are using the 'pstmt' to execute the query.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Actually you need to convert String to int. If this: emarks_txt is a JTextFiled then this: emarks_txt.getText() returns String. But your Enrollment constructor takes as argument an int:
Enrollment(String student_id,String subject_code,String Grade, int Marks)

So you can do this:

int Marks = Integer.parseInt(emarks_txt.getText());

Enrollment e = new Enrollment(eid_txt.getText(),ecode_txt.getText(),egrade_txt.getText() , Marks );

Or better:

try {
     int Marks = Integer.parseInt(emarks_txt.getText());

     Enrollment e = new Enrollment(eid_txt.getText(),ecode_txt.getText(),egrade_txt.getText() , Marks );

     e.SaveEnrollment();
} catch (NumberFormatException nfe) {
      System.out.println("Error. Mark entered not a number: " + nfe.getMessage());
       // OR
     JOptionPane.showMessageDialog(null, "Mark entered not a number")
}
scratchwiz commented: thanks :) scrathwiz.. +1
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Hi I have designed the food part but I dont understand the machine part, is it possible u can send me ur email in a private message, then I can show u the scenario. Thanks.

No this is a forum and people post their questions here.

Also the machine method will take as argument a food, process it and return another class.
What the method will do is up to you to decide. I don't know what kind of processing is required, that is up to you. You have been told to write something that processes food. Well ask whoever gave you the assignment how the food will be processed and what they want the result to be. Maybe it will be a class called "PackagedFood".

Maybe the idea is for you to think some processing ways. It is not difficult to say this:

Food tomato = new Food();
Food ketcup = process(tomato);

Now come up with other examples like this and think what attributes are required. Maybe instead of Food you will use subclasses of that class.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster
{
// piggy is NULL
this.piggy.setColour(Colour.PINK); // error

// piggy is NULL
this.piggy.setPosition(0); // error

// now you give piggy value.
this.piggy = aPig;
}

First you give value to an object or create it and then you use its methods

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

First of all always use {} brackets. Look what you wrote:

if(arg == "Exit")
 System.out.println("Program Terminated.");
 System.exit(0);

And what I wrote:

if(arg == "Exit") {
 System.out.println("Program Terminated.");
 System.exit(0);
}

In your first code, if the if statement is true it will execute only the System.out.println("Program Terminated.") and the System.exit(0) will always be executed, because you didn't put ant brackets.

And I would suggest not to use this:

String arg = e.getActionCommand();

 if(arg == "NewGrades") {

}

But this:

public void actionPerformed(ActionEvent e)
{ 
   Object src = e.getSource();

   if (mnuFileNewGrades == src) {
      // ....
  } else if (mnuFileExit == src) {
     System.out.println("Program Terminated.");
     System.exit(0);
  }
}
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

In a separate class or in one of the ones you already have, put that method:

public static void main(String [] args) {
   // instantiate objects and call their methods
}

Inside it you will put the code that you want executed. Then you will run the file that has the main method inside:
> java MainClass

Also in the constructor you do not use the arguments and the variables you do use (NUM_COLUMNS) have value 0. Shouldn't you be assigning the arguments to the local variables?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

i think you have not extended the taxpayer class from other main method class and also the both classes shud be in same package

You couldn't be more wrong. Please don't give wrong advices if you don't know what you are talking about.

Do all Social-Security-Numbers(SSN) need to be like this: (111...111, 222....222, ...) ?
Since you can have 999999999 different combinations, why do you want to limit yourself by using only those, when you can do this:

for (x = 0; x < 10; ++x)
	{
	somePayer[x] = new Taxpayer((x+1), 0.0);

}

The above will print:
1
2
3
4
....

If you want them to be:
000000001
000000002
000000003
000000004
Then don't use an int variable, use a String. Ints are used for calculations and you are not going to do any addittions with the SSN.
So this is my suggestion:

//Date: 3/18/2010

public class Taxpayer 
{
	private String socSec;
	private double yearlyGross;
	
	public Taxpayer(int taxPayer, double income) 
	{
		convertToString(taxPayer);
		yearlyGross = income;
	}
	public String getSocSec()
	{
		return socSec;
	}
	public double getYearlyGross()
	{
		return yearlyGross;
	}

       private convertToString(int i) {
           socSec = String.valueOf(i);

           while (socSec.length()<9) {
                   socSec = "0"+socSec;
           }
       }
}

In that wat when you call the constructor with an int: 1, then it will become the Stirng "0000000001"

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Since this is your exam it means that you attended a whole semester of your java course. Surely you would know how to create classes with attributes.

Well the instructions are pretty clear:

Create a Class
.....
EmployeePay (parent)
define: attribute: salary(net), gross, rate, no of hours worked, tax=20%
constructor: (2)

You would advise you to follow them

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Inside the cases of the do-while you set goOn to false. So you will exit the while-loop:

..
case 1:
  myAccount.deposit();
  goOn = false;
  break;
..

} while (goOn == true);
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

In case you haven't found it:

String [][] menuInput ={{"File", "Edit", "Windows", "Help"},{"Open","Cut","First","About"},{"Close","Paste","Second", null},{"Exit","Copy",null, null},{null, "Select All", null, null[B],[/B]}};

I think it is the extra ',' you have at the end:
{null, "Select All", null, null,}

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

i dont want any reply from big peoples lik u... i expected it frm person who willing to help to anybody..

And what kind of help would you want? Someone to code it for you? What didn't you like from the previous post?

It is true that we are not obligated to provide solutions immediately the moment someone posts a question. Our lives don't resolve around answering your questions. We are not under your payroll. We also have jobs with deadlines to meet

If no one has answered could mean a million things. I personally don't know how to fix what you want.

And the link provided might help you.
If you didn't understand it then ask a question about it.


PS: Peter can you check the link because I could not open it. I don't know if there is something wrong with me or the link.

peter_budo commented: Well spotted, it had double "http://". Ubuntu doesn't automatically preselect content of the pop-up for URL +12
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

The while takes as "argument" a boolean expression. So why don't you use a boolean.
At first have it to be true, so you will enter the loop. If the user enters correct String that can be converted into a number, meaning that this: Integer.parseInt will execute, make that variable false. That will make the loop exit

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I would suggest to write a method that takes as arguments the array of Students and a Student object:

boolean static int indexOf(Strudent [] array, Strudent st) {
  
}

Loop the array and see if the array contains the Student st. If found, immediately return the index where that student is. If you finish the loop without returning, means that you didn't found the student, so return -1 at the end:

YOUR Code with mine:

//StudentTest
import java.util.Scanner;

public class StudentTest {
	public static void main( String[] args)
	{   
		Student[] students = new Student[2];
		Scanner inputs = new Scanner(System.in);
		for(int i = 0 ; i < students.length; i++)
	    { 
	       
	      System.out.println("Please enter Student Number");
	      String fName = inputs.nextLine(); 
	      System.out.println("Please enter Student First Name");
	      String lName = inputs.nextLine(); 
	      System.out.println("Please enter Student Last Name");
	      String sNumber = inputs.nextLine(); 
 
//        NEW CODE ///////////////
               Student st = new Student(fName, lName, sNumber);

               if (indexOf(students, st)==-1) {
                   // New Student
	           students[i] = new Student(fName, lName, sNumber);                    
              } else {
                    System.out.println("Student: "+st+", already exists");
                    i--;
              }
//        NEW CODE ///////////////

	}
		for(int i = 0 ; i < students.length; i++)
	    { 
		System.out.print(students[i].toString());
	}
	

}

boolean static int indexOf(Strudent [] array, Strudent st) {
    // TODO
}

}

Be careful in that method to make sure that you don't compare any null objects. The array when initialized has null values as elements, so I would suggest something like this: st.equals(array[i]); instead of array[i].equals(st); Also for the above comparison you must use the equals method. For that …

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Sorry About that im new to this website so i thought the down arrow meant to go to the next post and i was trying to undo it but don't know how. if you can let me know how ill undo that. Sorry once again and thank you for your help!

Once someone votes a post they cannot vote again. If that was possible anyone could give thousands of positive or negative votes to anyone. That would cause a lot of mess.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Are you saying that you saved the images to a file, then changed the class and then tried to read? If yes then Yes you will not be able to read them because:
You serialized instances of this: SerializableImage. the files containes this: SerializableImage.
But whan you read them you are trying to pass that to a: myPackage.SerializableImage instance.
This will compile:

myPackage.SerializableImage image = (myPackage.SerializableImage)readObject();

But if the read object doesn't return an myPackage.SerializableImage object the program will crash. And the files contain SerializableImage objects.

So you will have to serialize the images again. Or for a more "professional" solution: Write a prgram that reads all the files and saves them into a SerializableImage. Then use the values of those objects to create mypackage.SerializableImage objects and save those by replacing the old files. you will have to do the above only once and the files will work from now on.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Apparently giving good advices and suggestions on how to solve one's problem is a reason for down voting in this thread.
And I am referring to my previous post

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Suppose you save $100 each month into a savings account with the annual interest rate 5%. So, the monthly interest rate is 0.05/12 = 0.00417. After the first month, the value in the account becomes
100 * (1 + 0.00417) = 100.417

After the second month, the value in the account becomes
(100 + 100.417) * (1+0.00417) = 201.252

After the third month, the value in the account becomes,
(100 + 201.252) * (1 + 0.00417) = 302.507
and so on.
Write a program to display the account value after the sixth month.

It seems to me that all you need is a for loop:

(100 + 0) * (1 + 0.00417) = 100.417
(100 + 100.417) * (1 + 0.00417) = 201.252
(100 + 201.252) * (1 + 0.00417) = 302.507

The (1 + 0.00417) repeats itself so you don't have to worry about it. Everything else is the same. The new result would be if you add to the old one the 100 and you multiply it by (1 + 0.00417).

result = (result+100)*a; Where a = (1 + 0.00417)

Just put that in a for loop.

Salem commented: I can fix that :) +19
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

The print method is a pre-defined method in Java. There is the println() method and the print() method. This is a static method of the PrintWriter class. Its better if you change the name of that method and try. If you have to use print() method compulsorily then you have to override that method.

Completely useless information and confusing. Are you really suggesting that he overrides the method of the PrintWriter class????
Or are you saying the name is the problem? That is completely wrong.
And there is NO pre-defined print method in java.
Different classes have print methods, but there is no confusing since in order to call them, you need an instance of their classes.

System.out.println() calls the print method of the System.out PrintStream instance

Don't let this guy confuse you gaya88.

BestJewSinceJC commented: thannnk you. well said. +4
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

3. Modifying data of selective item.

For modifying I suggest that once you call the findItem method, to ask the user for new data from the keyboard and change the item found:

System.out.println("Item found:");
System.out.print(Inventory[i]);
// ask for new data
inventory[i].set...();

return;

4. Deleting existing items.

After you search for the item you want to delete you can set that item to null:

inventory[i] = null;
noOfItems--;

That will change all you implementation of course. Your array will have gaps between the elements with null values.

So when you add instead of simply increasing noOfItems and using it as index, you can loop the array and whenever you find a null value, insert the new item to that spot and increase the noOfItems. Remember that when you initialize the array all its elements are null.

At the findItem method you can have your search to be like this:

if ( (inventory[i]!=null) && (item_name.equalsIgnoreCase(inventory[i].getItem_name()))
)

For counting items and printing them you can print only those that are not null:

System.out.println("Num of items:"+noOfItems);
for(int i=0; i< noOfItems; i++) {
  if (inventory[i]!=null) System.out.println(inventory[i]);
}

For 5 and 6, you need to redesign your class and change your whole implementation:

public class item {

private String item_name;
private String barcode;
private double price;
private int quantity = 0;

public void sellItem() {
  quantity--;
}

public void buyItem() {
   quantity++;
}

public boolean isAvailable() {
  return quantity>0;
}
}

That would mean that whenever you add an …

linx311 commented: brilliant post! great help! lots of info too +0
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I couldn't understand what your problem is so I tried to run it.
It asked me to enter some numbers, but once I entered the first number, it exited without asking for more.

It is because you call this: input = JOptionPane.showInputDialog(null,GET_NUMS,null,JOptionPane.QUESTION_MESSAGE); only once outside the while loop.
Now since you already make that call once, and you enter the loop with input having value, I would suggest that you put it at the end of the loop:

while (goodNum && counter < seriesLength)
{



input = JOptionPane.showInputDialog(null,GET_NUMS,null,JOptionPane.QUESTION_MESSAGE);
} 		// end while goodNum and counter < length

Also , if you run it now you will see that it always displays the lowest to be 0 and the max the last number entered.
It is because:
> you initialize the lowest with 0
> You have those checks outside the loop.

You need to put these checks inside the loop and initialize those variables with the initial input:

while (seriesLength <0 || input.equals(""))
{      
            seriesLength = Double.parseDouble(JOptionPane.showInputDialog(null,SERIES_REQUEST,null,
               											JOptionPane.QUESTION_MESSAGE)); // gets input from user
																      
            input = JOptionPane.showInputDialog(null,GET_NUMS,null,JOptionPane.QUESTION_MESSAGE); // gets input from user
}

largest=inputNum;
smallest=inputNum;

while (goodNum && counter < seriesLength)
{



input = JOptionPane.showInputDialog(null,GET_NUMS,null,JOptionPane.QUESTION_MESSAGE);
} 		// end while goodNum and counter < length
BestJewSinceJC commented: :) lot of effort to help this kid. +4
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Never mind I found it. I usually come up with solution after I make posts that ask for more information.

Anyway, you need a way to find the type of a variable. As BestJewSinceJC has mentioned you can do this:

Object.getClass().getName();

But he said that will not work with primitives. Actually with a small trick, it will:

public String [B]type[/B](Object obj) {
   return obj.getClass().getName();
}

Now try to call it like this and see what happens:

Integer intgr = new Integer(10);
int i = 5;

System.out.println(intgr + " is: "+[B]type[/B](intgr));
System.out.println(i + " is: "+[B]type[/B](i));
stephen84s commented: Autoboxing, but honestly your post could be more clear on the fundamentals the solution uses. +5
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Ok, so I was getting my daily dose of Stargate Atlantis then in the final episode atlantis lands in the atlantic ocean.

What is amazing is that you watched that show!

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Of course it returns false, since you do this:

<% 
boolean isCkecked = false;
%>
.....

<%
session.setAttribute("isCkecked",isCkecked); 
%>

The isCkecked is declared false. Then you pass its value which is false at the session.

This:

<input type="radio" name="code1" value="1"   onclick="<%isCkecked = true;%>"

Will not do what you think it does. Every time you run it the value of isCkecked will ALWAYS BE TRUE, because this: isCkecked = true; is executed before the page loads. It doesn't display anything at the page.

When it loads the isCkecked is already true and nothing can change its value. When the page loads the html code that will be rendered is this:

<input type="radio" name="code1" value="1"   onclick=""

This: <%isCkecked = true;%> just executes this code: isCkecked = true; before the page loads

Whenever you click the radio button you CANNOT change the value of any java variable. The java code is executed at the server and javascript is executed at the client. The onlclick executes javascript code and whatever you write there doesn't change any java values.

What you need is to submit a form with the radio button, take the value with request.getParameter, do whatever you want and then redirect back to the page.

This:

<% 
boolean isCkecked = true;
%>

<input type="radio" name="code1" value="1" <%=(isCkecked)?"checked":"" %>   >

First the isCkecked becomes true.
Then this is executed: (isCkecked)?"checked":"" and the result is the String checked.
Then the page loads like this: <input type="radio" name="code1" value="1" [B]checked[/B] > …

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

If it does not contain pure numbers like this:

1 2 3 4
5 6 7 ......

then the file contains a serialized object.

Can you post part of the file's content?
Who gave you this file?
Where you told how it was created?
What object does it have inside?

When you will learn how to create objects, if you have them implement the java.io.Serializable interface, you can save into files and read them like this:
http://java.sun.com/j2se/1.5.0/docs/api/java/io/ObjectInputStream.html
http://java.sun.com/j2se/1.5.0/docs/api/java/io/ObjectOutputStream.html

try {
        FileInputStream fis = new FileInputStream("filename");
        ObjectInputStream ois = new ObjectInputStream(fis);
   
        Object obj = ois.readObject();

         // OR IN YOUR CASE
         // int [][] array = (int [][])ois.readObject();

        ois.close();
} catch (Exception e) {
  System.out.println("Error: "+e.getMessage());
}

But first you need to answer me the above questions.
What kind of file do you have?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

What problems are you having? Your question is very vague. You just posted some unfinished code without any further explanation. Also what you did with the Car class is not the right way to do things:

public class Car {
String make = null;
String model = null;
String year = null;
  
public Car(String make, String model, String year) {
   this.make = make;
   this.model = model;
   this.year = year;
}

// ADD GET/SET METHODS
}
class CarList {

private List<Car> list = new ArrayList<Car>();

public void addCar(Car c) {
   list.add(c);
}

public int size() {
  return list.size();
}

public Car getCar(int i) {
  return list.get(i);
}

}
class AddEntry {
public static void main(String[] args) {
CarList carlist = new CarList();
Scanner s = new Scanner(System.in);
int choice;

System.out.println("\t Welcome to the car  ");

do {
System.out.println("Make a selection ");
System.out.println("1. Add a Car ");
System.out.println("2. View car list ");
System.out.println("3. Delete a car ");
System.out.println("4. Quit ");

System.out.print("Enter your choice plz: ");
choice = s.nextInt();
s.nextLine(); // Discard the rest of the line

if (choice == 1) {
   // use the Scanner to read the data from the keyboard and add the Car
  System.out.print("Enter the make");
   String make = s.nextLine();
   ..
   ..

    carlist.add( new Car(make, ..., ...) );
}
} while (choice != 4);

}
}
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

As I said:

You are not calling it with the right arguments. Check the declaration and call it with the right arguments

When you declare a method you need to call it with the number and type of arguments that was declared.

tactfulsaint commented: thanks for all your help man. +3
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

You declared the method like this:
Scan1(int[] num1)
And you are calling it like this:
Scan1()
Something is missing

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Correct me if I'm wrong, but aren't data in the table first populated by servlet?
If it so then you have some unique IDs you can reuse for creating links with call for servlet plus additional parameter which in this case would be some unique ID, for example book shop would use ISBN as this unique and hyperlink would be as "www.bookshop.com/ServletCall.jsp&itemId=1234"

I am sorry for replying to this, but shouldn't it be like this:
"www.bookshop.com/ServletCall.jsp?itemId=1234"
instead of a '&'

peter_budo commented: Well spotted. Thank you! +12
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

You are calling a constructor that does not exist. It is like calling a method with the wrong number or arguments. You haven't declared that kind of constructor:

Student s1 = new Student("kamal", "kandy", "5678")

Also if you paid attention to the errors that you get, you should be able to figure that on your own.

Also it would be better to rename the method getdetails to toString.

It is inherited from the Object class and is called automatically when you do this:

Student s1 = new Student("kamal", "kandy", "5678");
System.out.println(s1);

Try printing this:
System.out.println(s1) without defining it and then create that method (toString) and try again.

scratchwiz commented: thanks... +0
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Just a small addition to this issue.
We have been having some problems in displaying Greek character at the excel generated and after some tests it was discovered that in order to do that this tag also needed to be added at the <head> of the page.
Without it, it only displayed English characters:

<%@ page contentType="charset=iso-8859-7"%>

<%
response.setContentType("application/vnd.ms-excel;charset=UTF-8");
%>


  <head>
        [B]<meta http-equiv="Content-Type" content="application/vnd.ms-excel;charset=UTF-8" />[/B]
  </head>

In case someone else is having the same problem

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

JavaAddict: Good suggestions but for the one suggestion, it shouldn't matter if he implemented equals() since he is using the removeAll method. Right?

He is not using a removeAll method with no arguments. Perhaps you didn't notice but that method takes as argument a collection and removes those elements that are inside the collection.

BestJewSinceJC commented: Yup, agreed now :) +4
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

how to get it to begin after the index.

Being able to figure that out has nothing to do with your knowledge of java. It has to do with you being able to think.

Everything you didn't know about coding has been said. There is nothing else I can tell you regarding the coding. You know which method to use and what it does.

Now it is time for you to think and show how smart you are.

BestJewSinceJC commented: Ballsy thing to say, however, much more helpful to OP in the long run. +4
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I had a problem at work which I solved, but that raised me another question.
I wanted to export a page to excel, so I used this:

response.setContentType("application/vnd.ms-excel;charset=iso-8859-7");

It worked but while I was searching for an answer I found 3 possible content types for the excel:

> application/vnd.ms-excel
> application/x-msexcel
> application/ms-excel

As well as this: http://stason.org/TULARC/business/spreadsheets/10-19-What-is-the-correct-registered-MIME-Content-Type-for.html

What is the correct, registered MIME Content-Type for Excel files?

application/vnd.ms-excel

see http://www.isi.edu/in-notes/iana/assignments/media-types/application/vnd.ms-excel

so don't use any of these:
application/ms-excel
application/msexcel
application/excel
application/x-ms-excel
application/x-msexcel
application/x-excel
application/octet-stream

QUESTION:
Why only this: application/vnd.ms-excel is correct and those are not:
> application/x-msexcel
> application/ms-excel

kvprajapati commented: Great! +6
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

It is true that you can put java code inside jsp and it would work. It is not a problem if you have the minimum code (very few lines).

But you cannot put entire logic inside the jsp. All the logic needs to be done outside the jsp and inside the jsp you will simply print the results.

This is the comment I read in a book about java code inside jsp:
"Just because having java code inside jsp works, doesn't mean it is correct. With your logic someone might go and write the entire web application in assembly and it would work. That doesn't make it correct nor efficient."

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

It appears that up until now I am the only one that voted NET Beans. Also at work we use eclipse, but I prefer Net Beans at home.

Also the IDE that I hate the most is JDeveloper.

peter_budo commented: JDeveloper is crap indeed +12
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

GIVEN: patient,doctor,descriptions of doctor,does+medicines,visits,invoice,invoice detail.
1-recognize the given in a table
2-desighn the organized table
3-determine the primary and secondary key
4-describe

We are not a service that does people's homework for free

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

Have you looked the API for JFileChooser?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

When the class is first "executed" the query variable has this value:

String query = "SELECT * FROM PatientTable WHERE Surname='"+ jtffreeQuery.getText()+"'";

The text, I assume is empty, so it like writting:

String query = "SELECT * FROM PatientTable WHERE Surname='' ";

h

But when you click the button, the value at the field has changed, but the value of the query hasn't. You don't change the value of the variable. It cannot change on its own when you change something.

It is better to do something like this:

QueryTable qtable = new QueryTable(jtffreeQuery.getText());
qtable.setSize(700,500);
qtable.setVisible(true);
public QueryTable(String input) {
  String query = "SELECT * FROM PatientTable WHERE Surname='"+ input+"'";

// continue with the rest of the code.
}

In that way, you keep the class parametrized.

PS: Don't forget to close the Connection

JBeginer7891 commented: Thanks JavaAddict! this has been very helpful. +1
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

That means defnitely Statement should implement ResultSet interface methods to return a ResultSet object

No, Statement doesn't need to implement ResultSet:

public interface Resultset {
 // some methods
}


public class SomeResultSet implements ResultSet  {
   // someone has implemented all the methods of the ResultSet
}
public interface Statement {
  public Resultset executeQuery(String s);
}


public class SomeStatement implements Statement {
  public Resultset executeQuery(String s) {
      SomeResultSet srs = new SomeResultSet();
// code to create the Resultset
     return srs;
  }
}

In the same way someone has implemented the Connection interface, so when you call DriverManager to get the Connection the implemented class is returned instead, in which there is the implementation that returns the implemented Statement.
In other words, java has provided only the interfaces and it's up to the database "vendor" to provide the implemented classes.
When you downloaded the mysql java connector jar, what do you think there is inside it?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I haven't tried that before but there is the next() method:
Call the method twice and give 2 numbers as input:

String a = scan.next();
String b = scan.next();
[B]scan.nextLine();[/B]

double num1 = Double.parseDouble(a);
....

The input would be:
>20 30


A small explanation about the addition of the scan.nextLine() command.

When you call the next method you don't change lines. So you can read the 2 numbers. But any other call of the next.... methods will be done at the same line. It will try to read what is after the "30". Which is an empty String.

If after the second next, you press ENTER and try to read the next line with the nextLine or any other nextDouble method it will not read the next line because the "cursor" is still at the line with the first 2 numbers: "20 30". It will read from the last position it was(after the "30") till the end of the line. Which is, as mentioned, the empty String "".

That is why you call the nextLine in order to change lines. Unless of course you want to keep entering numbers

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

For overloading constructor:

private String Jazz;

    public JazzBandsInstruments(String p_Instruments, int p_Members, String p_jazz) {
        super(Instruments, p_Members);
        setJazz(p_jazz)
    }

Apart from that does the code compiles?

Make a list of all the requirements and check your code where they are implemented. If there is something you are not doing then post specific questions.

Then in your main just call the constructors and the methods. I would suggest, since you have more than one constructor per class, to make 2 instances of each object:

JazzBandsInstruments j1 = new JazzBandsInstruments();
j1.set...();
j1.set...();
j1.set...();
// print

JazzBandsInstruments j2 = new JazzBandsInstruments("arg1", arg2, "arg3");
// print
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

The thread is still on the server and is open, so anyone can respond. The answer will be helpful to those of the network the solution of that problem. Your comment is not smart.

Respond yes, But give away the answer no. This is not a forum where the memebers do other people's work

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

A few corrections.
Since you do this at the loop: (j=i+1)

for ( int i = 0; i < n; i++ ) {
		  for ( int [B]j = i + 1[/B]; j < n; j++ ) {
			if ( numbers[j].startsWith( numbers[i] ) && [B]i != j[/B] ) {

You don't need to check if the i!=j. It will never happen. You make sure of that by starting j to be "i+1".
Another reason you initialize the j that way is so you will not compare numbers that have already been compared.
Imagine i=1,j=2 and comparing number[1],number[2] and then at the next loop i=2,j=1 and comparing number[2],number[1]
You avoid that

Also don't close the output in the if. Close them at the end of your program.
Also if the "YES" is printed, have a new variable take value true.
With your code, you will print "YES" in the if, but when the loops finish you will also print "NO". Have that variable take value "true" inside the if, and outside the "for-s" print "No" only if the variable is false.

And lastly don't use throws at the main method.:

// declared outside
  BufferedReader input = null;  
  PrintWriter output = null;
try {
   // initialized inside the try
   input = new BufferedReader(new FileReader("telefon.sis"));  
   output = new PrintWriter(new BufferedWriter(new FileWriter("telefon.out")));
  // your code here

  // close them last
  input.close();
  output.close();
} catch (Exception e) {
   // for debuging:
   // e.printStackTrace();

   System.out.println(e.getMessage());
}
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I took a closer look to your code and here is what I suggest.

First you need to read all the values of the array and then check for equality. You do this:

for ( int l = 0; l < n; l++ ) {
        numbrid[l] = sisend.readLine();
	for ( int j = 1; j < numbrid.length - 1; j++ ) {

You read the 1st number but then you loop the entire array. But the rest of the elements of the array are null.

I suggest to do something like this:

for ( int l = 0; l < n; l++ ) {
        numbrid[l] = sisend.readLine();
}

for ( int i = 0; i < n; i++ ) {
   for ( int j = [B](i+1)[/B]; j < n; j++ ) {
       // compare the values
}
}

Also check the index of the second (inner loop) I think that it is more appropriate. Remember that with each loop the first index increases by one. So if you want the second loop to look after that index don't set it to 1 but to i+1.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I thought the char datatype does not support readLine

I didn't look at the API, but you are probably right.

If that is the case then you can use String:

String option="";

....
do {

  option = br.readLine();
} while(option.equals("y"));

Or you can do this:

System.out.println("Do you want to calculate anything else?(y/n)");
  option=(char)br.read();

  [B]br.readLine();[/B]

} while(option=='y');

With that extra call you leave the line where the 'y' was entered.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Check the internet for the definition of a magic square and then post some code

Salem commented: Nice +18
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Inside the for you do this:

BufferedWriter bw = new BufferedWriter(new FileWriter("audits.txt"));

String s = lines[i];
bw.write(s);
bw.flush();
bw.close();
}

Meaning that with each loop open the file, overwrite that was written and you close.

You need to open the file, write whatever you want and when you are done close it:

BufferedWriter bw = new BufferedWriter(new FileWriter("audits.txt"));

for (int i=0;i<lines.length;i++) {
  String s = lines[i];
  bw.write(s);
  bw.newLine();
}

bw.flush();
bw.close();