211 Posted Topics
Re: The difinition of the two methods from the line 15 to line 20 has some problem. The line 16 should be: return count== EmpYee.length; The line 19 should be: return count==0; | |
Re: nix nix, it is seen from the output shown in your post that [CODE]* * ** ** *** *** **** **** **********[/CODE]at the 1 st row: 1 star, 8 spaces, and 1 star are printed at the 2 nd row: 2 stars, 6 spaces, and 2 stars are printed at … | |
Re: (1) In the constructor you have redundant declaration for these attributes private JRadioButton courier, timesnr, helvetica; which makes them become the local variables within the constructor, but the actual three attibutes are still null. (2) The radioButtons have to be grouped so that the client may select only one of … | |
Re: (1) write a static method where the essential code has been already made as you posted: [CODE]static char letterToInt(char c) { switch (c) { case 'A': case 'a': case 'B': case 'b': case 'C': case 'c': return '2'; /* no "break" is needed becasue we have had the "return" */ … | |
Re: The index of the 10th position is 9. When (tos==9), that is the highest index is 9, the StackArray is full, which means the last value has been already stored in the 10th position. If you want to have no value stored at the 10th position, the condition has to … | |
Re: [QUOTE] what does this fucntion do. why do i need it if it is empty[/QUOTE] You may insert some code into the method void print(){...}. If there is no such a method, the line 23 @Override should be deleted. [QUOTE]why do i need to use inheritance here?[/QUOTE]In the class InnerEx7 … | |
Re: [QUOTE]the conversion [/QUOTE] Use the static method of class String: String valueOf(int i )/String valueOf(double d)/String valueOf(float f) in java.lang to convert number to words | |
Re: see: [URL="http://www.roseindia.net/java/example/java/swing/DisplayImage.shtml"]Display Image in Java[/URL] | |
Re: For example, to get the factorial of n where n is in int. The result is the final value of fac. [CODE]long fac=1; int i=1; while ( i<=n ) { // the condition for execution of the loop fac *= i; // the previous factorial (factorial of i-1)is multiplied by … | |
Re: I have questions for you. (1) Where is the definition of the class Console? As fas as I know it is a defined class in the package: java.io (2) For line 15: in the class Graphics there is a member method drawRect(int x, int y, int width, int length), but … | |
Re: The following errors should be corrected. The code line 19 should be: years = Integer.parseInt(yearsInvest); The code line 20 should be: while(yearsloop < years) The code line 22 should be: balance = investment * Math.pow(1.0 +rate/100, yearsloop); The code line 23 should be: JOptionPane.showConfirmDialog(null, The code line 27 should be: … | |
Re: If both files under the same folder, (1)remove line 3 in the file Main.java, i.e. remove "package deposit_withdraw;" (2) in lines 31 and 34 in Main.java, the method getBalance should be written as myAccount.getBalance(); | |
Re: (1)You have to assign the following variables an initial value, such as 0 for init or 0.0 for double in lines 10,11, and 12: double withholding= 0.0; double netPay= 0.0; int withholding1= 0; to pass the compiling. (2) You have to delete the pair of curly brackets at the line … | |
Re: [QUOTE]If the number is divisible by 3 or by 5[/QUOTE] if (number%3==0 || number%5==0) [QUOTE] If the number is divisble by 3 and 5[/QUOTE] if (number%3==0 && number%5==0) | |
Re: If I understand correctly you want to do some java program for cell phone. You need a J2ME development environment so that you may develop some java application, resulted in a file.jar (an executable jar file) ready for cell phone. Your computer should have JDK 1.6 environment. Then download [URL="http://www.oracle.com/technetwork/java/javame/downloads/sdk30-jsp-139759.html"]the … | |
Re: You should use a browser or the command: appletviewer in DOS window to open a html file where the applet code, i.e. the file of the applet code is in the same directory/folder, is available: <html><applet code="####.class" width=400 height=500></applet></html> There is nothing to do with main method. | |
Re: Because there is no handle for the member method dispose(), hence there is no idea about which frame is to be disposed. Try: frame.dispose(); | |
Re: (1)Create a String object, for instance s (e.g., String s="";) to accommodate the information obtained from your for loop: for(int a=0 ; a<values.length ; a++){ System.out.println("[Firstname Length: "+values[0].length()+" ]" +"[Lastname Length: "+values[1].length()+" ]" +"[Employee IDnumber: "+(i+1)+" ]"+" = "+ staff[i]); a++; } (2)Create a BufferedWriter bw in the following way: … | |
Re: kvass's way is feasible. Check the input digits' string to see if its length is 5 nor not. If not then ask client to re-enter a 5 digits' number. There is no way to restrict number of characters a user types in at the console during typing. | |
Re: For the variable date should we define as String? [CODE]String date = "01/01/2010"; // To hold the date[/CODE] The code in line 33 would be: [CODE]date = keyboard.nextLine(); // To receive the date as a String[/CODE] | |
Re: If the digit number is understood as int data, then class String has static String valueOf(int i) method which converts the int data into String. | |
Re: jwmollman, Can you modify your code by the following 2 changes? (1) in line 34, replace intTriangleHeight with intIndex1 so that the line of code will be: [CODE] for (int intIndex2 = 0; intIndex2 <= intIndex1 ; intIndex2 += 1) // control the number of symbles for each row[/CODE] (2) … | |
Re: Please study [URL="http://www.dgp.toronto.edu/~mjmcguff/learn/java/"]Java Applet Tutorial http://www.dgp.toronto.edu/~mjmcguff/learn/java/[/URL] ![]() | |
Re: The formula for Monthly Payment is incorrect. It should be: Monthly payment = ((Loan Amount*Monthly Interest)/(1-(1+monthly interest)^(-number of years*12)) The method to calculate the Monthly Payment should thus be: [CODE]public static double monthlyPayment (double aI, double loanAmt,int years ){ double mp; double mi = aI/1200; mp = loanAmt * mi … | |
Re: int line 62, the denominator should be 1000.0: elapsedTimesec1 =(double)(elapsedTimeSec - start)/1000.0; also see: [URL="http://www.daniweb.com/forums/thread310983.html"]http://www.daniweb.com/forums/thread310983.html[/URL] | |
Re: The following code could be helpful. [CODE]public class Prinf{ static double decimal(double d){ int dd = (int)d; d -=dd; return d; } public static void main(String args[]){ double d = 6.328941; System.out.printf("%8.6f\n",decimal(d)); } }[/CODE] output: 0.328941 | |
Re: Or simply put the header as: import java.util.*; | |
Re: I have modified your code between line 41 and 62 as follows: [CODE] if (source == theMainButton) { resizeComponent(this); setLocation(rand.nextInt(screenSize.width-3*BUTTON_WIDTH), rand.nextInt(screenSize.height-3*BUTTON_HEIGHT)); long start = System.currentTimeMillis(); // get the starting milli-seconds n++; if(n>=8){ JOptionPane.showMessageDialog(null, "You Clicked it " +n); long elapsedTimeSec = System.currentTimeMillis(); // get the stoping milli-seconds, elapsedTimesec1 =(double)(elapsedTimeSec - … | |
Re: in lines 7,10, 13, the methods nextInt(), nextFloat() are called. the () is missing. The code should be: double inInt = nix.nextFloat(); ... int inYear = nix.nextInt(); ... int inLoan = nix.nextInt(); You are using the static method of pow of the Math class. If your fomula is correct, the … | |
Re: The errors I have found are indicated as follows: (1) line 10 is a header declaration (import java.util.*;", which should be place in "the heading part", i.e. the first line of the code. (2) line 13: The class name is Scanner rather than scanner; (3) lines 25,27: the method println(...) … | |
Re: You did not difine the following classes: gradeTypePabel,namePanelname, testPanel panel , and resultPanel | |
Re: Call stop() method to kiill the thread. [CODE]import java.lang.Runnable; public class T implements Runnable{ Thread timer = null; public void start() { if(timer == null) { timer = new Thread(this); timer.start(); } } public void stop() { timer = null; } public void run( ) { while (timer != null) … | |
Re: [URL="http://www.concentric.net/~Ttwang/tech/javafloat.htm"]Java Floating-Point Number Intricacies[/URL][url]http://www.concentric.net/~Ttwang/tech/javafloat.htm[/url] | |
Re: the printf(...) ,which is a C-style output, is used starting from JDK1.5. for the details about java printf() see [URL="http://www.java2s.com/Tutorial/Java/0120__Development/UsingJavasprintfMethod.htm"]6. 14. 1. Using Java's printf( ) Method[/URL] | |
Re: The methods of an [URL="http://en.wikipedia.org/wiki/Inner_class"]inner/nested class [/URL] may also directly access the variables of its top-level class. So in some case one may declare a class entirely within the body of another class | |
Re: The area of a circle is 3.14*radius*radius rather than 3.14 *(radius*2) The following static method start() may do one run to calculate the area of a circle. [CODE]private static void start() { String n = JOptionPane.showInputDialog(null,"Enter the radius to calculate the area of a Circle"); int num = Integer.parseInt(n); DecimalFormat … ![]() | |
Re: Instance variable/method - Variables/methods that are specific to each instance (object) of the class e.g. name, age.... When accessing/calling them, the object, as the reference has to be used as a handle. Class variable/method - Variables/methods that represent/deal with class wide situation, e.g. a static variable which belongs to a … | |
Re: I wrote a testing program as follows. If I clicked twice the label is deleted. Perhaps for the line 5: [U][B]this.layeredPane.remove(e.getComponent());[/B][/U] your may replace e.getComponent() with actual reference: "label". [CODE]import java.awt.*; import java.awt.event.*; import javax.swing.*; public class DeleteComponent extends JFrame { JLabel label; public DeleteComponent(){ Container container = getContentPane(); label … | |
Re: kch1973 , the following comments for your consideration. 1. Since the reference of the array is in fact passed to the sortArray method (i.e. pass by reference), no return value(s) is needed. Therefore the definition of the sorting method would be: public static void sortArray ([B]Printer[] a[/B]){...} where The argument … | |
Re: should line 65 be: [CODE]pieces =new ChessPiece[?][8];[/CODE] ? | |
Re: Your code is basically correct. Please use the tag [CODE] for your code. I have made a small modification. I am not sure if there is a term called "accumulated interests" which is different from simple interests. import java.lang.*; public class simple { public static void main (String[] args){ // … | |
Re: [CODE]import java.io.*; class vowel{ public static void main (String args[])throws IOException{ String sentence; InputStreamReader isr = new InputStreamReader (System.in); BufferedReader br = new BufferedReader (isr); sentence = br.readLine(); System.out.println (vowels(sentence)[0]); System.out.println (vowels(sentence)[1]); } static Object[] vowels (String default1){ // return an Object array including various data types char ch; int … | |
Re: line 24,25,26: You have incoorectly made 5 parameters for the constructor, but in fact the Camera constructor requests 4 arguments: Camera( String Name, int Number, int Units, double price ) // see line 120 ... According line 30,31: Camera.showInventory(); The showInventory() method must be a static since you use the … | |
Re: I have modified your code by adding the paint() method to draw string, oval, and rectangle, from which you may start to taste the Graphics methods. Read the API to find more methods of Graphics. [CODE]import java.awt.*; import javax.swing.*; public class DrawGraphics extends JFrame { private JLabel label1; private JLabel … | |
Re: for (double d : numbers) { total += d; } is equivalent to: [CODE]for (int i=0; i<numbers.length;i++){ double d = numbers[i]; total += d; }[/CODE] | |
| |
Re: The line 3 and 4: private string city; private string state; The type of both attributes city and state should be [B]S[/B]tring | |
Re: First you may try the class : javax.swing.JOptionPane You should at first [CODE]import javax.swing.JOptionPane;[/CODE] Then you may, for example, replace line 14 and 15 by the following code: [CODE]String input = JOptionPane.showInputDialog("To Order new item. Press Y to leave press any other key..");[/CODE] Try it. Does it work? Read API … | |
Re: I guess, in the Bank's constructor, the attribute "bankAddress" should be: bankAddress = new Address(); Where is the code for the definition of Bank class? | |
Re: When executing the line of code: System.out.println(new Final(2)); an address of the instance of the Final is printed as 9cab16 (Final@9cab16) which tells that the instance of Final is stored at the memory: 9cab16 in hexadecimal system |
The End.