- Upvotes Received
- 0
- Posts with Upvotes
- 0
- Upvoting Members
- 0
- Downvotes Received
- 1
- Posts with Downvotes
- 1
- Downvoting Members
- 1
46 Posted Topics
Re: First: import java.io.*; Then you need to read from the console: try { //create a buffered reader that connects to the console, we use it so we can read lines BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); //read a line from the console String lineFromInput = in.readLine(); //create an print writer … | |
Re: Did you try using Application.Exit(). Call this function when you want the entire application to end. For more help, [url]www.NeedProgrammingHelp.com[/url] | |
Re: To add a new node to the end of the linked list you should try: [CODE]Node newNode = new Node(characterObject); if(length == 0) { firstNode = tailNode = newNode; } else { tailNode.next = newNode; tailNode = newNode; } length++;[/CODE]The problem with your code is that you update tailnode in … ![]() | |
Re: Try this code [CODE] double num = 1001.27124; double newNum = Math.round(num*100.0)/100.0; System.out.println (newNum); //prints 1001.27 [/CODE] It works because *100 shifts the numbers to the left twice. Then the round is applied. Then we divide by 100 to shift twice right. For more help, [url]www.NeedProgrammingHelp.com[/url] | |
Re: Your error lies in the following code: [CODE]while (!phrase.equals("quit")) phrase = scan.nextLine();[/CODE] This reads lines but only saves the last line in phrase. Each time it overwrites the last line with the new line. Also, your loop is stopping too late. It includes quit as a phrase. The correct code … | |
Re: Suppose you want to generate 50 unique random numbers from 0 to 100. [CODE] //Create an array of size 100 that remembers which integers are taken boolean[] taken = new boolean[100]; //start count at 0 int count =0; //create random gen Random r = new Random(); //create array to hold … | |
Re: Did the professor tell you what the Gift class is supposed to represent? If this program is about converting currency, what does a gift have to do with converting currency? You mentioned that the Gift class must hold the total. You could use the Gift class below and create a … | |
![]() | Re: You could create a batch file (.bat). This answer is for Windows computers. It is not an executable but it is very simple to make. Suppose you main method is in the class MyTest. Then create a file called MyJavaRun.bat. (The name is arbitrary) Inside the file write: [CODE]java MyTest … ![]() |
Re: The scanner interface can be used to read lines, tokens, etc. Suppose you want to open a file named "c:\test.txt" using the Scanner: [CODE]Scanner sc = new Scanner(new File("c:\\test.txt"));[/CODE]To read all the lines from the file using the created scanner: [CODE]while(sc.hasNextLine()) { String scLine = sc.nextLine(); //process line }[/CODE]What is … | |
Re: Take $123.30. [COLOR=Blue][B]1.[/B][/COLOR] First you need to separate the dollars and the cents using the substring method of the String class (see code below). [COLOR=Blue][B]2.[/B][/COLOR] How do you convert a hundreds digit? Just put "Hundred" afterwards: 1xx = > One Hundred xx [COLOR=Blue][B]3.[/B][/COLOR] How do you convert a tens digit? … | |
Re: Melotron, Here is an example of the code you need: [CODE]import javax.swing.JOptionPane; public class Test { public static void main(String[] a) { //get first string from user String indata1 = JOptionPane.showInputDialog("Enter text"); //get second string from user String indata2 = JOptionPane.showInputDialog("Enter text"); //check length if( indata1.length() > indata2.length()) { System.out.println("The … | |
Re: OllieFalle, Here are a few things that seem incorrect to me (correct me if I am wrong): [B]1.[/B] Your method called userInput shown below has problems [CODE]public void userInput () { System.out.println("Enter a sequence of notes: "); String sent = Keyboard.readString(); StringTokenizer st = new StringTokenizer(sent); String word; while (st.hasMoreTokens()) … | |
Re: Run this code below. See the comments for an explanation. This should help understand what you need to use. [CODE]import javax.swing.*; import java.awt.*; class TestPanel extends JPanel { //paint function public void paint(Graphics g) { //cast to Graphics2D Graphics2D g2D = (Graphics2D)(g); //set stroke int lineWidth = 5; g2D.setStroke( new … | |
Re: glamo, See Chapter 7 in this page: [url]http://www.jeffheaton.com/ai/[/url] You need to understand Neural Networks. I would suggest to read the other chapters. :?: For more help, [url]www.NeedProgrammingHelp.com[/url] | |
Re: I would suggest to use a 3x3 two dimensional array. Maybe something like [CODE]char player[][] = new char[3][3];[/CODE]Then when player 1 wants to use cell (1,2) write: [CODE]player[1][2] = '1';[/CODE] :?: For more help, [url]www.NeedProgrammingHelp.com[/url] | |
Re: To check if someone is already in the room use the following code: [CODE]boolean isRoomOccupied(int floor, int room) { if( array[floor][room] == null ) return true; else return false; }[/CODE] When someone checks out call this function [CODE]void checkOut(int floor, int room) { array[floor][room] = null; }[/CODE]It is very important … | |
Re: Here is a working example of what you need. Basically it takes commands like 'add node' with name "Child1" to node with name "Parent1". The root must always be referred to as "root". Run the code and read the comments. Should be easy to use/modify. [CODE]import javax.swing.*; import javax.swing.tree.*; import … | |
Re: The while loop only runs one time because of the statement [CODE]return itemNo ;[/CODE]Once that statement executes the loop (and the entire method) are ended. Take out the return and it should work. Why are you putting a return there anyways? :cool: For more help, [url]www.NeedProgrammingHelp.com[/url] | |
Re: Have you tried this code: [CODE]Dim strBinary As String = "11111111" Dim intValue As Integer Dim iPos As Integer Dim iVal As Integer For iPos = 0 To strBinary.Length - 1 iVal = strBinary.Substring(strBinary.Length - iPos - 1, 1) intValue = intValue + iVal * 2 ^ iPos Next[/CODE] You … | |
Re: There are many problems: 1. Fix mispelling/case errors. 2. There is no unsigned keyword 3. main must be public static 4. f has no return type 5. readLine() returns String not int 6. I have no idea what you mean by the following line: System.out.println("you have entered names of "+name[i=String[i].length()>=0]+"these … | |
Re: Why do you need to store all the lines? Couldn't you just maintain the average of the numbers in a variable. For example, [CODE]create a total & amount variable (for the average... average = total/amount) double total =0; double amount=0; //for each line in the file while ((line = input.readLine()) … | |
Re: Override the paint method and use the translate method of the Graphics object. Remember that translate(100,100) doesn't mean goto point 100,100. It means move to the right 100 and move down 100. [CODE] public void paint(Graphics g) { //draw circle drawCircle(g); //move left and down by 100 g.translate(100,100); //draw another … | |
Re: Check out these two links. Hope it helps. [url]http://www.falkhausen.de/en/diagram/html/javax.swing.JComponents.html[/url] [url]http://www.falkhausen.de/en/diagram/html/java.awt.Components.html[/url] For more help, [url]www.NeedProgrammingHelp.com[/url] | |
Re: Your image is not being found. Probably the directory "C:/MyDocuments/MemoryGame/woodTable.gif"; doesn't exist. If its in your documents folder then the correct directory would be: C:/Documents and Settings/YOUR WINDOWS USER NAME HERE/My Documents/woodTable.gif. For more help, [url]www.NeedProgrammingHelp.com[/url] | |
Re: You can use the String classes replaceAll method. Here is an example: [CODE]String str = "Hello blank"; String newStr = str.replaceAll("blank", "Jim") ; System.out.println(newStr); //prints "Hello Jim"[/CODE] For more help, [url]www.NeedProgrammingHelp.com[/url] | |
Re: Firstly, The line with the code [CODE]if((tokens.hasMoreTokens()) );[/CODE]is basically useless. This checks if there are tokens and does nothing. What you want is [CODE]if((tokens.hasMoreTokens()) ) { //put code here }[/CODE]Also, you might want to use the trim() function when getting tokens. This cleans out the string of weird spaces at … | |
Re: You received a NullPointerException because the array [B]possibleseq [/B] is always null and you end up using it in your code. The best solution is to create an ArrayList by writing [CODE][B]ArrayList [/B]possibleseq= new [B]ArrayList[/B]();[/CODE] then add your strings into it by writing: [CODE]possibleseq.add("someText");[/CODE] Then to get the 11th item … | |
Re: Each row contains a persons info. The best thing to do is create a class that holds each row. Here is an example: [CODE]class PersonInfo { private String name; private int age; private String address; public PersonInfo(String name, int age, String address) { this.name=name; this.age=age; this.address=address; } } [/CODE] Then … | |
Re: Polymorphism means many forms. The idea of polymorphism is very important in OOP. Lets look at Java's IO classes (they use a lot of this concept). The code below is legal: [CODE]//The inputstream r will get its input from a file. InputStream r = new FileInputStream("someFile.txt");[/CODE]The code below is also … | |
Re: == has many meanings [B]1.[/B] When comparing simple data types (int, char, double, bool, etc), == compares the value of the two. [CODE]int x = 1; int y = 2-1; System.out.println( x == y ); // **** [B]prints true[/B] ****[/CODE] [B]2. [/B] When comparing two object references, it compares the … | |
Re: Here is a quick & simple example of showing an image in java. The most import code is in the paint method. In this case, we are redefining the way a usual panel draws itself. The class ImagePanel does just this. The other class just uses this panel in a … | |
Re: [B]For the first problem,[/B] you must use two for loops. Lets call the horizontal direction i and the vertical direction j. Notice how the #'s change [B]10 [/B] times from 10 to 100 in direction i Notice how the #'s change [B]10 [/B] times from 10 to 210 in direction … | |
Re: 1. Shouldn't TotalBalance start off with the initial balance? [CODE]double TotalBalance = initialBalance //not: double TotalBalance = 0[/CODE] 2. When there are insufficient funds for a check, shouldn't the original transaction be cancelled and only the overdraft charge applied? [CODE]balance = (balance) - Fee; //not: balance = (balance + transaction) … | |
Re: Here is a test class to get you started. I think this should help you. [CODE]import java.io.*; import java.util.*; class Bytes { public static void main(String[] args) { try { [B]//create byte output stream[/B] ByteArrayOutputStream outBytes = new ByteArrayOutputStream(); [B]//creat object output stream and connect [/B] him to the byte … | |
Re: This is an simple example on implementing the ActionListener interface. [CODE]class MyClass implements ActionListener { public void actionPerformed(ActionEvent e) { JOptionPane.showMessageDialog(null, "ACTION!"); } }[/CODE] By looking at your code, this method actionPerformed will be called whenever the controls fire an action. I'm not sure if this is what you want. … | |
Re: Here is the code you need. Read the comments to understand it. [CODE]public static void talk(String numbersAndLetters) { [B]//go through the string's characters[/B] for (int i = 0; i< numbersAndLetters.length(); i++) { [B]//get a char[/B] char currentChar = numbersAndLetters.charAt(i); [B]//switch on the char[/B] switch(currentChar) { [B]//if its 1 print one[/B] … | |
Re: Maybe you should try setting the maximum heap size for the JVM. [CODE]java -Xmx256m MyClass[/CODE]You can put higher values if needed. For more help, [url]www.NeedProgrammingHelp.com[/url] | |
Re: Replace the line [CODE]instructionPanel.add(instructionTextPanel);[/CODE]with[CODE]instructionPanel.add(slider);[/CODE] The scrollpane [I]slider[/I] was created to wrap the textpane. You must add that object to the panel not the original text pane. Are you sure you want this JTextPane to be disabled? For more help, [url]www.NeedProgrammingHelp.com[/url] | |
Re: Suppose you want to create an array of <type> with size 1555. <type> can stand for int, double, or String The syntax is: [CODE]<type>[] nameOfTheArray = new <type>[1555];[/CODE] This creates the 1555 empty slots. The actual contents depends on the type. For example: an int array always starts with all … | |
Re: Web.config is a configuration file for an ASP.NET Web application. Windows applications use a similar file called Application.Config. The purpose of these configuration files is to set global settings like debugging information, authorization, etc. You can also define global values that can be accessed from .NET using the syntax: <add … | |
Re: Display the value of a found item: 1. search for the item Item itemFound = null; for(int i =0; i < length;i++) { if( it.getName().equals(nameToFind) ) { itemFound = it; } } if(itemFound == null) System.out.println("Not found!"); else System.out.println( "Found it! Its price is: " + itemFound.getPrice() ); 2. Sell … | |
Re: Here is a way to do it. Suppose we have an array: int[] newBase = new int[100]; it will hold the bits for the decimal system the user inputs. Given 25 as decimal and 2 as base, do: 1. Compute ln(25)/ln(2) approx 4.64. Round it down to 4. 2. start … | |
Re: Suppose the size listbox has Small, Medium, and Large Suppose the color listbox has White, Blue, White & Blue Then write: dim total as Double //check if its small and white If lstBoxSize.SelectedIndex = 0 And lstBoxColor.SelectedIndex = 0 then total = total + 5.99 End if //check if its … | |
Re: Everything looks good except for the sorting code: for(sort = 0; sort < 10; sort++) { for(unsort = 0; unsort < 10; unsort++) { if(input[unsort] > Largest) { Largest = input[unsort]; i = unsort; } } It seems to me that you are trying to use Selection Sort. Selection Sort … | |
Re: To search the vector you would write String cdNameToFind = JOptionPane.showInputDialog(null, "Enter CD Name") ; CDEntry currentCD=null; for( int i = 0; i < cdVector.size(); i ++ ) { currentCD = (CDEntry)(cdVector.elementAt( i ) ); if( currentCD .getCdName().equals( cdNameToFind )) ) break; } if(currentCD == null) JOptionPane.showMessageDialog(null, "NOT FOUND!"); else … | |
Re: 1. Its unnecessary to write: for (int i=0; i<128; i++) charSet[i] = 0; The int[] is already initialized with zeros. Unlike c++. 2. In the constructor, why do you do this code? The frequencies are already computed in charSet? for (int i=0; i<128; i++){ if (charSet[i] > 0) { frequency[count] … |
The End.