- Strength to Increase Rep
- +6
- Strength to Decrease Rep
- -1
- Upvotes Received
- 33
- Posts with Upvotes
- 33
- Upvoting Members
- 17
- Downvotes Received
- 5
- Posts with Downvotes
- 5
- Downvoting Members
- 4
Re: [CODE]public class MyPoint { private int x,y; public MyPoint(){ x=0; y=0; } public MyPoint(int x, int y){ this.x=x; this.y=y; } /* now Two get methods for data fields x and y, respectively. */ ..... }[/CODE] | |
Re: You may declare a method (in java we call function as method) as abstract which means no definition is given, e.g. [CODE]void show();[/CODE] You may declare a method with empty body, which isn't an abstract method anymore. [CODE]void show(){};[/CODE] but do nothing when calling it. Or you may define a … | |
Re: The JOptionPane's showMessageDialog is indeed shown, but it is covered by the DOS window. After you move the DOS window away you will be able to see the JOpationPane's showMessageDialog. This is my observation. | |
Re: Your code shown above is correct. I have tested with a known file. The result is correct. AS long as the browsing files is concerned, as jon.kiparsky indicated, it is already available in Swing. For example, the class FileDialog is a candidate for this purpose. Since its constructor requests a … | |
Re: Your forgot to add the component userMessageLabel into container: [CODE]add(userMessageLabel); // this line of code is missing[/CODE] Please use CODE tag to post your code so that one may refer your certain code to a specific line number | |
Re: StringBuffer has an instance method: reverse() to do the reversing job. [CODE]import java.io.*; import javax.swing.JOptionPane; public class Palindrome{ static boolean palindromeCouplet (String s) { StringBuffer s1 = new StringBuffer(s); return ((s.compareTo(new String(s1.reverse()))==0) ? true :false) ; } public static void main(String[] args) { while(true){ String str=JOptionPane.showInputDialog( null, "Type in a … | |
Re: Following javaAddict's code, I have replaced the BufferedWriter and FileWriter with BufferedReader and FileReader. In order to get each integer value back, the method of class String split is given the delimiter of a space " ". Please read the method of String split(...) in API. Therefore, for reading the … | |
Re: Please have a look at the thread: [URL="http://www.daniweb.com/forums/thread299093.html"]array sort of 10 integers in ascending and descending order Bubble sort http://www.daniweb.com/forums/thread299093.html[/URL] | |
Re: To call System.out.print() and use nested loops as well. | |
Re: Animation in Java JDBC application Statistics on English words obtained from a text file Some demonstration on data structure | |
Re: In constructor you redefine the label2,label4,label6, and label8 as local variable of the type JTextField, which is wrong. You have already declared them as attributes. You should thus replace the 8 lines of code in the constructor by the following code: [CODE]JLabel label1 = new JLabel("Enter the price of one … | |
Re: [CODE]import java.io.*; import javax.swing.JOptionPane; public class PalindromeCouplet{ static boolean palindromeCouplet (String s) { StringBuffer s1 = new StringBuffer(s); return ((s.compareTo(new String(s1.reverse()))==0) ? true :false) ; } public static void main(String[] args) { while(true){ String str=JOptionPane.showInputDialog( null, "Type in a string!\nPress Cancel to terminate the program", "Palindrome or Not?", JOptionPane.QUESTION_MESSAGE); if … | |
Re: Thank you, VinC, for sharing the "Covariant". line 22 shows that g is a variable of type Grain. line 25 shows that a variable of type Grain is capable to receive a value of type Wheat. Why? Because Grain is super class of class Wheat. Wheat is a kind of … | |
Re: [CODE]double num = 1001.27124; System.out.printf("%8.2f\n", num);[/CODE] | |
Re: It happends with Chinese characters as well. I think this is probably due to the computer system (windows' config) where your output is printed. | |
Re: A further development of extemer's program leads to the following table showing the furture values of one thousand dolloars investment calculated based on compound interest: a(t) = (1 + i)^t where i is rate while t the number of years [CODE]import java.text.DecimalFormat; import javax.swing.*; import javax.swing.JTextArea.*; class TextAreaDemoB { public … | |
| |
Re: The main method should be written as follows: [CODE]public static void main(String args[])throws IOException { sp obj=new sp(); obj.takenum();obj.showresult(); }[/CODE] | |
Re: If you have already had JDK 1.6 in your machine then download [URL="http://www.oracle.com/technetwork/java/javame/downloads/sdk30-jsp-139759.html"]Java ME SDK 3.0 http://www.oracle.com/technetwork/java/javame/downloads/sdk30-jsp-139759.html[/URL] do some programing in J2ME Then under your working folder : [B]projectName/dist/[/B] you may find the corresponding file ***.jar ready for mobile phone . | |
Re: (1) The code in the line 12 is not correct. The code in line 12 could be: intTotal = intTotal + intCounter; or intTotal += intCounter; (2) The code in line 13 should be moved/inserted into the place between the line 14 and 15. (3) The initial value for the … | |
Re: (1) flyingcurry ,if you have to sort the whole array the second argument “length” is redundant. In fact, the length is the array.length。 (2) The line 13 could be replaced with [CODE]for (j=0; j<length-1-i; j++) //to avoid the unnecessary comparisons made of the stable region.[/CODE] See [URL="http://www.daniweb.com/forums/thread299093.html"]the post on bubble … | |
Re: One should write the following line of code to update the control variable ctr (the ODD numbers less than 10): [CODE]for (;ctr<=10; ctr+=2, ctr2++) {[/CODE] | |
Re: Just for your [URL="http://docs.python.org/tutorial/datastructures.html"]reference.[/URL] In Pyphon the list data type has a method: pop(). list.pop([i]) removes the item at the given position in the list, and return it. If no index is specified, a.pop() removes and returns the last item in the list. (The square brackets around the i in … | |
Re: The difference between two adjacent numbers in the series of numbers increases one each time. Therefore, one has to update the difference by one increment each time: [CODE]difference++[/CODE] Hence one may calculate the next number by the following code: [CODE]num +=difference++;[/CODE] Therefore the for each loop could be written as … | |
Re: (1) You may define the method as the main(). Hence replace the line 8 with [CODE]public static void main(String args[] ){[/CODE] (2) You forgot to create the instance of Scanner: input. Hence insert line 8 the following code: [CODE]Scanner input=new Scanner(System.in);[/CODE] | |
Re: The UML for the class MyPoint could be written as follows: -x : double -y : double +MyPoint() +MyPoint(x:double,y:double) +getX() : double +getY() : double +setX(x:double):void +setY(y:double):void +distance(AnotherPoint:MyPoint):double +distance(p1:MyPoint,p2:MyPoint):double | |
Re: Note that the instructor asks to verify the value provided for "year" is at least 1908 and at most 2012, hence the code should be: [CODE]if (y >= 1980 && y<= 2012) year=y; else year=2010;[/CODE] The following code by using ternary operator is also valid: [CODE]year = ( y>=1980 && … | |
Re: The class Math in the package java.lang has a static method random() which returns a double value with a positive sign, greater than or equal to 0.0 and less than 1.0. I use this method to generate random number. For example, to generate a integer varying from 0 to 255 … | |
Re: In the definition of class EnemyShip, you may add a static int attribute numEnemieShip from which you may know the number of enemy ships created from time to time. Hence, the constructor is defined as follows: [CODE]public EnemyShip(int x, int direction){ this.x = x; this.direction = direction; numEnemieShip++; }[/CODE] | |
Re: In this case you should cast the result of the evaluation of "xCenter + 200 * Math.cos(2 * Math.PI * 3 / 7)" or "yCenter + 200 * Math.sin(2 * Math.PI * 3 / 7)": [CODE]g.drawLine ((int)(xCenter + 200 * Math.cos(2 * Math.PI * 3 / 7)),(int)(yCenter + 200 * … |