javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Sorry but my browser is telling me that this thread resides in:

DaniWeb Home > Forums > Web Development > JavaScript / DHTML / AJAX

That is: JavaScript, DHTML & AJAX! -No JAVA here...
-Regards.

My reply was to the first post where kishor_agrawal posted a javascript question to a java forum and the post was moved

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

What is your code

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

It is not wrong, but instead of all those arrays use one that will contain objects. And each object will have the attributes I told you. Use the example I wrote.

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

This is a java forum not a javascript forum

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Create a product class that holds the item number, the name of the product, the number
of units in stock, and the price of each unit.

int dvdNumber[] = new int[arrayLength];
String dvdName[] = new String[] {"Sweet Home Alabama", "How to Loose a Guy in 10 Days", 
"Ps I love You", "Freedom Writters", "Hannah Montana"};
int dvdUnits[] = {5, 3, 2, 2, 3};
double dvdPrice[] = {19.95, 19.95, 15.95, 15.95, 19.95};
double dvdValue[] = new double[arrayLength];

The idea of OOP is to use objects. You should create one class named DVD with attributes:
dvdNumber, dvdName, dvdUnits, dvdPrice, dvdValue. Then have methods inside the class that manipulate the above values.
ex: When you change the dvdUnits for one instance the dvdValue should change automatically:

public void setDvdUnits(int units) {
dvdUnits = units;
dvdValue = dvdUnits * dvdPrice;
}

Then have an array of DVDs:

DVD dvds = new DVD[5]; 
// this is an [B]array[/B]
//the dvds array is NOT null [B]but[/B]
//the dvds[0], dvds[1], ... , DVD objects ARE null

dvds[0] = new DVD(1, "Name of the dvd", 3, 25.00); // inside the constructor calculate the 
//dvdValue = dvdUnits * dvdPrice; (3*25.00)

for (int i=0;i<dvds.length;i++) {
System.out.println(dvds[i].getDvdNumber() +" "+dvds[i].getDvdName() +" "+ .......);
}
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

to java addict:

i have tried your suggestion..unfortunately,it doesnt display the third array or array C that will display the product of the contents of arrays A and B...

The result in not an array, but the sum of the A*B
So I told you that you can omit the third array and instead of doing this:


C[i] = A[i]*B[i];
//..........
sum+=C[i];

You can do this:

sum+=A[i]*B[i];

That is the result you will get from ejosiah 's code. He doesn't use a third array.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

to java addict:

have you tried maing a running program for this???

What do you mean by that?

Also, I am not going to send the entire program like ejosiah did. You already have complete program as you posted on 2 Days Ago 12:52 3rd post. All you have to do is change where you calculate the result with my suggestion. Actually ejosiah told you the same algorithm (sum += a * b) but he wrote a new program version. Since you have the solution then use it to alter the code you have: 2 Days Ago 12:52 3rd post.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

illegal start of expression if (artistText.getText(.equals("")) {
if (artistText.getText().equals("")) {

C:\Documents and Settings\Tammy\My Documents\NetBeansProjects\Stock\src\stock\StockGui.java:374: ')' expected
int MESSAGE(); What are you trying to do here? Declare an int or call MESSAGE()

C:\Documents and Settings\Tammy\My Documents\NetBeansProjects\Stock\src\stock\StockGui.java:446: not a statement
temp == (FeeQtyProduct)stockInput.getFeeQtyProduct(index);
Try with 1 '=' the above is used to return boolean

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I think there is something called: "instance of". I don't remember by heart how to use so might want to search it, but I do know that it works almost like this:

Rectangle r = new Rectangle();
if ( r instance of Rectangle ) {
}

But you'd better search it on the web to make sure.

Also you can try to do: r.getClass().toString() and then compare the String with the String Rectangle. Keep in mind that the above method also returns the package:

r.getClass().toString() returns packagename.Rectangle

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Several steps: one way:

Need to identify the card first
Need scanning device and analyze the acct number is right
then interface to type the pin

--
there should be a server program that can handle request from the ATMs. ATMs will create a socket connection to the server and communicate messages
--
First connect to server [can use Java socket classes for the purpose]
scan card and send the text to the server
Server sends response OK/Failed
Collect PIN then send to the Server using the socket
server will respond with fail/success.
[A local ATM database and asociated server program can also does the verification, may be insecure]

May use encryption for data communication
---
can keep a DB in the server side to keep information.
Each sent records can be matched with the db.

For the purpose, you need your logic to verify, DB connection logic is required and then query and verify is required. Decryption may be required if you use encryption

balances can be kept in db then you need to deduct the withdrawn amount

you should also, use the transaction management concept

So you see lots of issues to consider.

smslive2, asked for a simple program. I doubt it that if this is a school assignment they would want something that complex. Of course I don't blame you, since smslive2 didn't specify what was his problem you can give any solution you …

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

You said that you wantd help, not someone to do your program from scratch. There are a lot of solutions fro this problem, so don't expect someone just to hand you the complete code. You need to show us how you want to implement it in order to point you to the right direction.
Because such program could consist of only one file, or thousands of different classes depending on the level of complexity you want to add.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

If you are using Unix use this, to redirect the output to a file:

$javac ClassToCompile.java>file.txt

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

What do you mean capture?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

After putting numbers in both tables and calculating the third table

Instead of this:

System.out.print("\t[A]\t[b]\t[C]\n");
for(int i=0; i<length; i++)
{
System.out.println("\t" + arrayA[i] + "\t" + arrayB[i] + "\t" + arrayC[i]);
}

You will need this:

int sum=0;
for(int i=0; i<length; i++)
{
sum = sum + arrayC[i];
}

Or without the third array:

int sum=0;
for(int i=0; i<length; i++)
{
sum = sum + arrayA[i]*arrayB[i];
}
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Use a for loop that takes the values of the arrays and do this:

sum = sum + a*b;

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Actually you need the argument as input in the method.

public class Grades
{
	public static void main(String[]args)
	{
		Instructor grades = new Instructor();
		
		char grade = args[0].charAt(0);

                grades.congratulateStudent( grade  ); 
               
	}
}

Of you will need to check if the user has given an argument:

if (args.length>0) {
                Instructor grades = new Instructor();
		
		char grade = args[0].charAt(0);

                grades.congratulateStudent( grade  ); 
} else {
    System.out.println("No argument given");
}
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

In a separate class write a method that takes two arguments (username, password). That method should query the database using these two arguments, in order to check if there is such record. If the above combination (username, password) exists then the method should return true, otherwise false.
Then create a gui where the user inputs username, password. Take these values, call the above method and if it returns true, then the user should login.

As for creating a new member, in the above class create a method that takes two arguments (username, password) and performs an INSERT in the database.
Then create a gui where the user inputs username, password. Take these values and call the above method.

And you don't specify what will you use for the login form. (.jsp or swing)

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Use the Arrays class: Arrays

Signature:
public static void sort(Object[] a)

String [] arr=new String[5];
//put stuff into the array.

Arrays.sort(arr);

The sort will take any array with Objects as long they implement the Comparable interface and they can be compared with each other.
The String object does implement the Comparable interface. It is better the array you use as input to have objects of the same type.

You can also sort integers:

A) as primitive types:

int [] arr=new int[5];
//put stuff into the array.

Arrays.sort(arr);

A) as objects:

Integer [] arr=new Integer[5];
//put stuff into the array.

Arrays.sort(arr);

The Integer object does implement the Comparable interface.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Then I will assist you by giving you this advice: You'd better get started because you've got only 17 days to complete this assignment.
What; you thought that we were going to do this for you? Not in this forum.

If you trully need assisance, start coding and we will help you with any problem you might have, after we see some effort from your side. Ask specific questions about specific problems.

Start by creating the classes, that you might need. Think of the logic that will be involved.
When you start designing the database, use seperate classes that you can "call" and handle the database.

When this project was given to you?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

There are many ways to implement this, so if it works don't worry about it. In my idea I was thinking of creating an array 5x5, and put the values in it before printing them. I think that it would have been simpler because with the array I could start putting things at the end of the array:
arr[0][4] = 1
arr[0][3] = 2 . . .
So instead of while inside the first for-loop, I would have the outside loop counting the line of the array, and the inside loop counting backwards and start putting the values at the end of the array.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

You will need a database, if you are doing a more advanced course.
If you need to store the data somewhere, so the next time you run the application you will have them back. then you could use a database.
But if you want to keep thinks simple, you could save the information in .txt files, and write a class that reads/writes from that file.

If you don't want to save anything then the above are not necessary. But you will need an ArrayList or Vector

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

As you can see for each line, you have a start, then increase each element by 1 and when you reach 5, if you didn't insert 5 elements in the line start reducing.

5 4 3 2 1(start)

4 5(reached 5, will decrease until the line is filled) 4 3 2(start)

3 4 5(reached 5, will decrease until the line is filled) 4 3(start)

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

You say that the rate argument in any version of your computeCommission is measured in % .

Since in both cases you divide the input by 100 means that you assume if you
input 3 you mean 3% --> 0.03
input 3.0 you mean 3.0% --> 0.03
input 4.5 you mean 4.5% --> 0.045

So if you want the rate to be 0.45 (45/100 --> 45%) then the input should be:
computeCommission(double s, 45) or computeCommission(double s, 45.00)

So if you want the rate to be 0.06 (6/100 --> 6%) then the input should be:
computeCommission(double s, 6) or computeCommission(double s, 6.00)

So if you want the rate to be 0.053 (5.3/100 --> 5.3%) then the input should be:
computeCommission(double s, 5.3)

You say:

if i put int= .075 which would be 7.5%

If you want 7.5% (0.075) then you should input: computeCommission(double s, 7.5)

You get the error because int rate is an int variable and you cannot store non integer values. In int rate you must put only ints. If you do int rate=0.99999, the the rate will have value 0 in the end.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

What errors do you get? Does the program compile, run? Do you get the desired results?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

And we are supposed to understand what needs to be put in line 500?
Post the code that you are having problems with specific questions. Preferably in code tags stating the line where you get the error, and some description of what you are trying to do.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I will have to take a better look on your code then for your last question:

my devices for calculating the number of characters, words and lines don't work as they should, or at least, as I thought they would. Any suggestions on that part?

Try to use files with one word and one line and see if it works.
Then files with one line and many words.

Try to test simple cases first and see how they behave.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Then create a method in the class that loops the two arrays and checks one by one the elements.

static boolean areEqual(int [] arr1, int [] arr2) {

if (arr1==arr2) return true; 
// if (arr1 != arr2) don't return false. Their elements might be the same

if (arr1.length != arr2.length) return false;
//No need to compare their elements if the arrays don't have the same length

/*
loop through the arrays (don't worry, they have the same length as checked above)
if one of the elements  of one array, 
is not equal with the other's array element then immediately return false 
if the loop finished and false was not returned then all the elements are equal, 
so return true at the end of the method 
*/
}

Use the above method when you want to compare the arrays

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

You can put the System.out.println() inside the while-loop:

while (more)
      {
        try
        {
            System.out.print("Please enter the file name: ");

            String input = console.next();
            FileReader reader = new FileReader(input);
            Scanner in = new Scanner(reader);
            counter.read(in);
            
        }
        catch (FileNotFoundException exception)
        {
            more = false;
            System.out.println("Characters: " + counter.getCharacterCount());
            System.out.println("Words: " + counter.getWordCount());
            System.out.println("Lines: " + counter.getLineCount());
        }       
      }

And then after the line: counter.read(in) , you should print the results. So when the while-loop repeats itself, you will be asked for a new file, and the results of the new file will be printed before the while tries to do another loop. And if you want to stop just enter a file that does not exist.

I don't think that you entered in an infinite loop. The program was just waiting for you to enter something, but since you didn't have any message before the console.next() , you didn't know that the program had stopped at that line and was waiting for your input.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Go ahead then

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

You are calling the method wrong. The compiler tells you EXACTLY what is the problem. If you can't figure out such a simple message, what are you doing with GUIs and not learning the basics of java?

proj.java:101:
showDialog(java.awt.Component,java.lang.String,java.awt.Color)
in javax.swing.JColorChooser cannot be applied to
(javax.swing.JPanel,java.lang.String,javax.swing.JColorChooser)

As you can see you are not calling the method with the right arguments.

Check the API: JColorChooser

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

You get the error because process1 is null. At the if you check if it is null or not, but regardless the result you call this process1.getCurrentNode(); anyway. The idea is to call it only when it is not null.
So if this is true

if (process1==null) {

then what is inside the '} else { ... }' will not executed.
If it is false meaning that process1 is not null then the else will be executed.
Since you have process1.getCurrentNode() inside the else, it will executed only when process1 is not null.

With the first case, you check if proccess1 is null, but then you go and use it anyway.

if (process1 == null) {
....
}
//this will execute no matter 'if' is true or false.
NodeEntity currentNode = process1.getCurrentNode();


if (process1 == null) {
....
} else {
//this will execute only when if is false (proccess1 is not null)
NodeEntity currentNode = process1.getCurrentNode();
}
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

If you run by hand both for-loops, you will see that the x,y take value from 0 to 5.
They go: 0, 1, 2, 3, 4, 5. You correctly insert data in the arrays. When the index reaches value 5, then this statement is false:
( y=0; y<Arr2.length; y++ ), So the loop correctly stops:

Array[0] = 5
Array[1] = 5
Array[2] = 5
Array[3] = 5
Array[4] = 5
Then x or y becomes 5 and the loop stops

BUT then you do this:

if (Arr1[x]==Arr2[y])

. The x, y have value 5 and it tries to access the 5 element of the array. But the array can have as index only 0 to 4.

Don't '==' to compare arrays. Use this: Arr1.equals(Arr2). Or create another for-loop that compares each element with each other

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

What kind of information are you looking for in the CD Rom?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Hello all,
for (int i = 0; i < count; i++)
System.out.print(studentScores + " ");

// Declare and initialize output

JOptionPane.showMessageDialog(null, "Student Name: " + studentName,
"\nScores: " + studentScores + " ",
"\nAverage: " + average,
"\nHigh Score: " + studentHighScore,
"\nLetter Grade: " + studentLetter);
}
}

The variable i is declare at: for (int i = 0; i < count; i++). But since you don't have "{" and "}" the for loop only repeats: System.out.print(studentScores + " ") ;
The rest are outside of the for-loop hence the i variable is not declared nad cannot be seen.

As for the second, make sure if you are using the right syntaxe for the method JOptionPane

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Start by posting what you have written so far

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Then the specifications of the exercise tell you exactly waht you need to do. And I told you to start by creating the objects that you will need.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Assume that you want to represent a human being as an Object. Most people have name, lastname, age, ... . So your object wiould be like this:

class Person {
  private String name;
  private String lastName;

 public Person() {
 }
 
 public Person(String na, String la) {
  name = na;
  lastName = la;
 }

  public String getName() {
    return name;
  }

  public String getLastName() {
    return lastName;
  }

  public void setName(String na) {
    name = na;
  }

  public void setLastName(String la) {
    lastName = la;
  }
}

Do the same for the objects requested by the assignment (Objects Descriptions, Carton Descriptions )

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

For this project you must learn how to use while, for loops.
You will also need a way to read input from the keyboard. If you search the forum there are many examples on how to create a menu using a while loop and the Scanner class (this clas is used to read from the keyboard).
You must also learn how to create objects and store them into a Vector or an ArrayList.

Examples of the above will follow. How much time do you have before you must deleiver this?

Link for the java API

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Should the capacity of the cartons be measured in Volume (liters) rather than mass (kg)?

We will not do this project for you, but we will help with YOUR code and give you hints. Let me read carefully the specifications and let me see what I can do.

In the mean time, start studying and try to start writing small programs. I believe you have a book, and inside it there are simple exercises and examples. Try to solve on your own all the examples and exercises in each chapter after studying each chapter first of course.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Actually the subject that I am doing the thesis has nothing to do with programming or software. The subject is called something like: Environmental Protection. And the application will have to be a system that monitors the materials that Industries use and the wastes that they produce. Since one industry's waste could be used by another industry for material, there should be a network with all the industries and I will have to deterine which one needs what from whom.
It is easy to be done in java, but since the lab that the professor runs consists mostly of chemists, the only thing they know is VB and access.
So he wants it to be done in VB in order for the application to run with the other programs they have.
Besides I shouldn't have a problem learning a new language. I just wanted a good book to get me started, based on my java background.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I think:

MySubType mytype = null;
//instead of MySuperType mytype = null;

if (sub_type) {
     mytype = new MySubType ();
     mytype.setD(4);    
     mytype.setE(5);
} else {
     mytype = new MySuperType ();
}

mytype.setA(1);
mytype.setB(2);
mytype.setC(3);

MySuperType mytype = new MySubType ();
No because superType is not a subType. Super type does not have d, e variables.
Sub: has a,b,c,d,e so it does not "fit" in the Super which has a,b,c

MySubType mytype = new MySuperType ();
Yes because SubType is a SuperType. Sub type has a,b,c
MySuperType has a,b,c and it fits into the larger Sub

Try to compile and run both with sub_type true or false and see which one is correct.

Please correct me If I am mistaken because I don't have time to test it

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Sorry for the second post but here is the API for the charAt: String

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

You can for-loop the String using the charAt method and checking each time if the char taken is one of those: '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '.' . Also you should check if the '.' appears more than once

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Let's assume that you use Scanner to read input: Scanner.readLine() I think is the method and you store it into a String variable. There is a method that turns the String into an int:

String s = "10";
int i = Integer.parseInt(s);

The int i variable has the int value 10. If s is not an int number then the Integer.parseInt(s); will throw an Exception:

try {
 String s = "a";

 int i = Integer.parseInt(s); //this line will throw a NumberFormatException. It will also throw it if you use Integer.parseInt to turn into an int the String: "2.35" which is a float number

 System.out.println("The s is the int number: " + s); 

} catch (NumberFormatException nfe) {
 System.out.println("The s is not a number, s: " + s);
}

For more information:
Integer
Double
Float

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Hi ,
I am also interesting in buying a book for VB .NET. I know good java and need a book for my assignment at university. The assignment will include databases and web.
Is Sams Teach Yourself Database Programmng with VB .NET in 21 Days any good?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Hi All,
I am an experienced java programmer for many years. But my problem is that the final assignment that was given to me for my master at the university, has to be written in VB .NET.

Do you know any good books for learning VB .NET for someone like me? I don't want a book that just explains how to use the graphic environment and build GUIs. I have bought one those years ago and it wasn't helpful. It didn't explain much about the programming language ,but only how to create graphics.

I am asking this question here, because I already know java and want to go to VB .NET.

PS: The assignment will be web based. The users will connect to the internet, log in, and then use the application

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I don't think that you can double click a .class file since it is not executable.
As for JCreator there should be an option where you can set the arguments of the main method

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Could someone help java code to read number of lines, words and characrters in paragragh .

You can count how may times the \n appears in the paragraph for lines.
For characters the total length of the paragraph String minus the characters: " ", " ", " ", ...
For words user String.split(" "); and count the length of the array minus the elements where you might an empty String with more than one length.

Or you can use regular expressions.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

First of all no one understood what do you want and what you are trying to accomplish. Some might have an idea what do you mean but your questions are too general. Please rephrase.

how to retrive the text file from database using jsp

You cannot use jsp to retrieve anything from database. You open a connection, you make queries to the DB you get the data using ResultSet. And for all that you have to create a class and write methods that do that.
If you want the results displayed in a jsp, then first call that class and the methods inside a jsp and then display the results you get.