211 Posted Topics
Re: [B]Normal class:[/B] Normal class has definition of methods and variables and their declaration as well. [B]Abstract class: [/B] Abstract class has methods and variables with definition and declaration as well like the normal classes. Hoewever it must have at least one method with no implementation, which hence is called abstract … | |
Re: Some error in your code: line 5 should be [B]S[/B]ystem.out.println(...) line 4 should be float number = r.[B]nextFloat[/B](); If the range of current random is [0,1] then [CODE][B]float[/B] number = -1 + 2*r.nextFloat();[/CODE] the random number varies in the range of [-1,1] | |
Re: Calling [B]String toString() method[/B] shows that the JVM would dynamically identify the objects of cat, Dog, Duck, and Cow since the array stores their references respectively. Therefore neither [B]casting[/B] nor the [B]instanceof operator[/B] is needed. An Object array may store a reference of any kind of type. [CODE]public class Part5{ … | |
Re: Note: order of execution in loop body has been altered. Use psuedo code to express the algorithm: • set sum to 0 • set number_counter to 1 • while number counter <= 100 do the following loop: [I] sum = sum + number_counter add 2 to the number_counter[/I] • Print … | |
Re: Some google search result: strictfp is a keyword in the Java programming language that restricts floating-point calculations to ensure portability. It was introduced into Java with the Java virtual machine (JVM) version 1.2. [URL="http://en.wikipedia.org/wiki/Strictfp"]http://en.wikipedia.org/wiki/Strictfp[/URL] [URL="http://www.java-samples.com/showtutorial.php?tutorialid=333"]Frankly, most programmers never need to use strictfp, because it affects only a very small class … | |
Re: Should we modify the formula ? selection menu : 1.Area of a Circle ----(3.14 * (r*r)) 2.Area of a Trapezoid ---- (height * (base1+base2) / 2) 3.Volume of a Sphere ---- ( 3.14 *(radius*radius*radius)/.75) 4.Volume of a Cylinder ---- (3.14 * (radius * radius) * height) | |
Re: [QUOTE]how to do the displaying of objects in array program using an interactive console/gui [/QUOTE] If the Object array is ObjectArray where the elements are of various types the following traversal loop may be useful. [CODE]for (Object o: ObjectArray) System.ou.ptinrln(o);[/CODE] If you are going to add/delete an element into/from an … | |
Re: I have no solution for this thread, but I have a comment on above coding. class b extends a. The following line of code leads to a compiling error. [CODE]b obj = new a();// The instance of a super class cann't always be the one of its sub class.[/CODE] The … | |
Re: Is the array your teacher asks you to create a type of Object, or a concrete type defined by you, or a primitive data type? If an object is added, is it added before the first element or after the last element, or somewhere expected? Please provide certain specification. | |
Re: Use StringTokenizer in java.util.* to get each word as a token. The delimiters include space character, and other interpunction。 | |
Re: As JavaAddict points out, it is the checking issue that makes Katana24's method does not work perfectly. Therefore, some code has to be modified as: [CODE] for( int i = 0; i < myArray.length; i++ ) { try { int currentValue = Integer.parseInt( sT.nextToken().trim() ); myArray[i] = currentValue; }catch(NumberFormatException e){ … | |
Re: Learn from [URL="http://www.javafaq.nu/java-example-code-796.html"]code example[/URL] | |
Re: Please have a look at [URL="http://www.daniweb.com/forums/thread300029.html"]the post[/URL] for your reference. In this project a statistics has been made on the words in a text file. | |
Re: One error: In line 7 you define name as String instead of String array. Suggestion: (1) Should we just use the argument of the main method so that the body of the main method will be: [CODE] sortStringBubble (args); for ( String s: args ) System.out.print( s + " " … | |
Re: Megha SR Even you have corrected all the errors accordingly you are still unable to run this program. If you run it, the following error will be printed: Exception in thread "main" java.lang.NoSuchMethodError: main You should define a proper main method which requests only one argument: a String array: String … | |
Re: See [URL="http://www.javaworld.com/javaworld/javaqa/1999-08/01-qa-static2.html?page=1"]Static class declarations by InfoWord-JavaWord[/URL] “You declare a top-level class at the top level as a member of a package. Each top-level class corresponds to its own java file sporting the same name as the class name. A top-level class is by definition already top-level, so there is no … | |
Re: An array is a container object that holds a fixed number of values of [URL="http://download.oracle.com/javase/tutorial/java/nutsandbolts/arrays.html"]a single type.[/URL]” (true for some cases only) [URL="http://download.oracle.com/javase/tutorial/java/nutsandbolts/arrays.html"]http://download.oracle.com/javase/tutorial/java/nutsandbolts/arrays.html[/URL] In broad sense, I would say: “An array is a container object that holds a fixed number of values of either a single type or different types/multi-types.” … | |
Re: One may replace peter_budo's code 38-44 with the following c-style code: [CODE] System.out.printf("max=%2d", max); for (String s: adjective) for(String n: noun) System.out.printf("\n%s as %s",s , n);[/CODE] I also tried to use this style in initiating the string array noun, e.g. replace : [CODE]for (int i=0; i<cNoun; i++) noun[i] = scan.next(); … | |
Re: One byte of menory is requested for storage of a value/variable of boolean data type | |
Re: You may replace the code in line 24 where the error occurs by the following two lines of code: [CODE] int va = this.statVect[i].getValor(); va += otroVect[i].getValor(); this.statVect[i].set(va);[/CODE] Can you answer me Why we should modify in this way? | |
Re: The reason is: the loop body still needs i. the (i=cis.read(cipherTextBytes)) is consider as the returning value. If the value returned is not -1 the loop continues. | |
Re: Over one month ago there was a thread discussing the similar project which might help you: How to extract columns of coordinate values from text file (in java) ? [URL="http://www.daniweb.com/forums/thread294844-1.html"]http://www.daniweb.com/forums/thread294844-1.html [/URL] | |
Re: (1) In void actionPerformed(ActionEvent e)method body there are missing code blocks for two cases: if (e.getSource() == displayBtn){...} and if (e.getSource() == resetBtn){...} (2) in void actionPerformed(ActionEvent e)method body one curly bracket '}' is missing in line 178 That's why, I guess, the buttons do not work properly. | |
Re: I do not understand your question. Anyway, I am nocited that to capture the output in DOS window one may use pipe: java ABC > data.dat so that the output by intepreting ABC will be captured/stored in the file data.dat | |
Re: Yes, provided i,j are withing the ranges of the 2D array. | |
Re: boolean variable "stop" is a sentinel flag. If "stop" is true the "while loop" must terminate immediately. So you should check the empName to see if it is "stop" or not. Therefore, the lines of code starting for checking the name would be: [CODE]if( empName.equalsIgnoreCase("stop")) stop=true; // stop becomes true … | |
Re: skyzer, Is the n an instance of Node or that of String? I think some things in jemz declare of the method "remove" should be altered as : public boolean remove(String n) {...} provided the definition of the class Node is wirtten as : [CODE]class Node { String item; Node … | |
Re: This thread seems to come from the same thread in [URL="http://www.daniweb.com/forums/thread304961.html"]http://www.daniweb.com/forums/thread304961.html[/URL] | |
Re: In Unix/Linux/DOS windows the commands for compiling and runing java program are the same provided the environmental variable is set up properly. javac Hello.java java Hello If you develop an applet application, you may use appletviewer Hello.html to open the html file Hello.html to run the applet. | |
Re: static methods/variables are associated with class-wide situation which has one copy only while non-static, i.e. member methods/variables belong to each instance. Each instance/object has its own copy of its methods/variable. You may use super's class name to replace the handle "super": [CODE]one.show(); [/CODE] to meet your purpose. In other word, … | |
Re: According to NormR1's suggestion, (1) Add one space character as an extra delimiter into the sDelim string in line 8: String sDelim = ".? !"; (2)Insert the following line of code after line 14 if (s1.compareTo("do")!=0) so that the "do" will not be printed on DOS | |
Re: May I suggest you write a program to open and read a file, and the file name is the first String argument ( args[0]) for the main method : public static void main(String args[]) {...} so that each time your command should simply be : java XML input1.txt | |
Re: The for loop body shows that after assignments are made to every elements of the array diveScore the guard starts to check the "input variable element". (It's too late). Actually no assignment has been made to the variable element. If only the values varying from 0 to 10 are acceptable … | |
Re: The data type of choice is int. So you should define each case by a constant of type int. Therefore the case bady should be: [CODE]case 1: howKilometers(meters); break; case 2 : showInches(meters); break; case 3 : showFeet(meters); break; case 4 : System.exit(0); default: JOptionPane.showMessageDialog(null, "Invalid number");[/CODE] | |
Re: Please go to C forum. The code you presented is not in Java. | |
Re: Should we first establish the input channel properly? (1) In line 20 the "input= " is missing. The corrected code would be: input = JOptionPane.showInputDialog("Enter the next number"); (2) lines 15, 16 are deleted. (3) before comming into the while loop the variable number should be initiated, e.g., as 0. … | |
Re: The method name should always be starting with lower case conventionally speaking. the code should be: [CODE]ch=value.charAt(i);[/CODE] | |
Re: If you use the image file in your own computer to create a ImageIcon instance, e.g. img1, the code in the first post you made will work well. You may simply replace the URL in line 11: "http://calindragan.files.wordpress.com/2010/06/pictura_muzica.jpg" by "/home/noon/workspace/eclipse/Applets/src/images/ima1.jpg" Try it. | |
Re: You may learn how to write Psuedo code from web sites, such as [URL="http://www.unf.edu/~broggio/cop2221/2221pseu.htm"]http://www.unf.edu/~broggio/cop2221/2221pseu.htm[/URL] Following the samples overthere we may write as follows: create an input channel ask client to type in score convert the input into int variable if ..... | |
Re: I added a main method so that the program runs. [CODE]public static void main(String args[]){ Display dis=new Display(); dis.setVisible(true); dis.setSize(500,150); dis.setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); }[/CODE] I put an icon.png in the same folder. both the program and the button works. The problem is that the icon will be located before the text rather … | |
Re: The line 23 should be replaced by [CODE] if ((suit !='C') || (suit !='D') || (suit !='H') || (suit !='S')) [/CODE] If your intention is logical OR. Probably, your intention is logical AND as javaAddict indicated(?). | |
Re: Due to Java security reason if a class extends Applet it cann't: save any records on a file open and read a file, and alter a file. However it may record scores in an array. As long as the program runs, one may access the data. If the program terminates … | |
Re: code line 17 is not correct: BufferedReader br = new BufferedReader(new BufferedWriter((System.in))); The argument should be a Writer object. I have modified the program by Java source code example for your reference. [url]http://www.javadb.com/write-to-file-using-bufferedwriter[/url] The data you typed in will be stored in myFile.txt In one line type in "end" only … | |
Re: Default constructor is the constructor with no arguments requested. It is called implicitly when creating an instance. [CODE]import java.io.*; public class DefaultConstructor { public DefaultConstructor() { System.out.println("I am Default with no arguments."); } public static void main(String[] args) { DefaultConstructor d = new DefaultConstructor(); } }[/CODE] output: I am Default … | |
Re: [CODE]class Node { // The definition of the class Node String value; // data member Node next; // self referencing: referring to itself }[/CODE] Self-reference occurs in natural or formal languages when a sentence or formula refers to itself. [URL="http://en.wikipedia.org/wiki/Self-reference"]http://en.wikipedia.org/wiki/Self-reference[/URL] | |
Re: Match in size (the same width and height) or Match in the ratio of width over height, or by other criteria? | |
Re: [LIST=1] [*]Animation in Java [*]Data Structure in Java [*]JDBC [*]Natworking programing in Java [*]Statistics on words in text file by Java [/LIST] | |
Re: (1) May I ask: Why only press "return key" to do something? You may do something when receiving other input string. (2) One class may implement the interface KeyListener to listening to the keyboard. (3) I have written a simple program using KeyAdapter to monitor the keyboard for your reference. … | |
Re: You have incorrectly placed these lines of code outside of methods. This means that you are declaring attributes for your class. When you declare an array, you may initiate the String array with the corresponding values at the same time. However you wrote assignments' code during declaration, which is wrong. … |
The End.