Cannot Find Method AvailableProcessors
Jul 21, 2014What's wrong with this statement that it cannot find the method AvailableProcessors();?
Java Code:
Runtime.getRuntime().AvailableProcessors(); mh_sh_highlight_all('java');
What's wrong with this statement that it cannot find the method AvailableProcessors();?
Java Code:
Runtime.getRuntime().AvailableProcessors(); mh_sh_highlight_all('java');
I was given the Java code for a project and I am supposed to build unit tests to test the performance of seven sorting algorithms and I am getting the following error in my Lab1Test file...cannot find symbol: method sorta(int[]) location: class Lab1Test.
Lab1.java
Java Code: package funcollege.comp10062.perflib;
import java.text.DecimalFormat;
import java.util.Arrays;
import java.util.Random;
[code]...
i'm working on a "name sorter" program and i want it so when i add names and such to the list box i can click sort and it sorts the names in A,B,C format.Here is my code:
import org.jdesktop.application.Action;
import org.jdesktop.application.ResourceMap;
import org.jdesktop.application.SingleFrameApplication;
import org.jdesktop.application.FrameView;
import org.jdesktop.application.TaskMonitor;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.Collections;
import javax.swing.Timer;
import javax.swing.Icon;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JPanel;
[code]....
I'm using Netbeans FYI and a java desktop application. Also, i have looked everywhere and even my teacher has had to look further into it, i really want to get it to work.
I was trying to find the complete readLine() method In the online docs but all I can get hold of Is:
readLine
public String readLine()
throws IOException
Reads a line of text. A line is considered to be terminated by any one of a line feed
('
'), a carriage return ('
'),
or a carriage return followed immediately by a linefeed.
Returns:A String containing the contents of the line, not including any line-termination characters, or null if the end of the stream has been reachedThrows:IOException - If an I/O error occursSee Also:Files.readAllLines(java.nio.file.Path, java.nio.charset.Charset)
Is It possible to view the actual method syntax online ?
I am trying to run the following code but getting the error above.
import java.io.*;
public class StringBuilder {
public StringBuilder() {
super();
}
public static void main(String args[]) {
// creates empty builder, capacity 16
StringBuilder sb = new StringBuilder();
// adds 9 character string at beginning
sb.append("Greetings");
}
}
I made a method which takes values from a data set and finds out which one is the highest value. When it finds the highest value, it returns the country which is associated with the value. Here's the data set.
"Country""Total CO2 2005 (million tonnes)""Road CO2 (million tonnes)""Road CO2 per person (tonnes)""Cars per 1000 people"
10
USA5951.131530.35.16777
UK2573.4119.681.99470
Italy476.08116.862592
Germany841.78150.211.82550
Canada553.02123.423.82562
France414.03128.132.04477
Russia1575.44114.690.8178
Japan1254.47224.241.76447
China5100.6228.020.317
India1147.4691.060.18
So if the number was 5951.13 then the program would return USA. How do I do that? I've already started on trying to get this code to work but it doesn't seem to compiler so what's wrong with it?
public static CO2Data highest (CO2Data [] arr2){
Scanner sc = new Scanner(System.in);
CO2Data highestindex = arr2[0];
CO2Data currentcountry = arr2[0].getCountry(sc.nextLine());
[Code] ....
Also the array is a CO2Data array which is part of the following class:
public class CO2Data { //The CO2Data class will be called in other methods
private String country; //A private variable will prevent other users from accessing and changing these variables.
private double totalCO2;
private double roadCO2;
private double CO2PerPerson;
private int carsPerPerson;
public CO2Data() {
country = "";//this sets the initial values for the different variables
[code].....
I have some work where I have to create a binary tree. Anyway I am stuck on one of the classes which has several methods I must fill in! The code is below
The headers for each method are: public Node find (member p1)The method find(Member p1) is used to return the node which contains a particular member. It is a private method because the interface to CabinetTree should not provide direct access to the internal nodes. It makes use of the method Node findNode (Member p1, Node current)
and the next method is : Node findNode(Member p1, Node current) which searches the tree from current node to find a node whose value is equal to the Member p1, i.e. a node in the tree such that p1.equals(current.getMember()) is true. If there is no such node then the method should return null.
public class CabinetTree {
private Node head;
CabinetTree(Member p1) {
head = new Node(p1, null);
[Code] ....
I am writing a palindrome program. I don't understand what is wrong with my Main method. It is giving me error and error is "Can not find symbol in main method"
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class PalindromeA extends JFrame {
private JTextField inText;
private JTextField outText;
[Code] ....
How can find any string length without using any library method??
View Replies View RelatedI have been looking around and I cannot seem to find which algorithm java uses for its sort method. Merge, sort etc.
While I am on the topic BinaryTree is a balanced heap right?
Are there any libraries for depth or breath first search?
Is the ArrayList a double linked list?
We are required to write a binary‐search method to find an int within an array of ints. Without using any functions besides the basics (for loops, if statements, etc.)
I have this so far:
public int binarySearch(int[] ints, int n) {
for(int i = 0; i < ints.length; i++) {
if(ints[i] == n) {
return ints[i];
}
}
}
Does this look somewhat correct?
I am wondering if there is something similar to the "Find and Replace" action, that we use in applications like Eclipse and MS Word, that is actually built into the Java API so we can use it in our code, mainly for method names?
For example, right now I have these couple of lines
rotateLeftCounterClockwise(1);
rotateBottomClockwise(1);
rotateLeftClockwise(1);
//and
rotateRightCounterClockwise(1);
rotateBottomCounterClockwise(1);
rotateRightClockwise(1);
that does one operation for a side of Rubik's cube. However, all other sides of the cube can use these same exact code with the exception of the 2nd word, ie the position, in each method.
So for example, another side would do something, like, lets say
rotateFrontCounterClockwise(1);
rotateBottomClockwise(1);
rotateFrontClockwise(1);
//and
rotateBackCounterClockwise(1);
rotateBottomCounterClockwise(1);
rotateBackClockwise(1);
The reason why I ask this is because this would DRASTICALLY shrink the size my code, rather than have to create separate methods for each operation. Now I know there is a Find and Replace feature for Strings, but I am not sure about method names...
I am trying to understand how package(directory structure) and JAR files work interchangeably. From my understanding JAR is a package file format typically used to aggregate many Java classes. Since many classes are usually contained inside a package, I should be able to create a JAR file from a package, and use them interchangeably. A single JAR file is easier to handle then multiple classes and folders.
To test my understanding of the concept, I am working with the following project structure,
/development_directory
____/BookPackage
________Book.java
____BookDemo.java
Book.java contains the following code,
package BookPackage;
public class Book{
private String bookname;
public Book(String str){
bookname = str;
}
public String getBookName(){
return bookname;
}
}
and BookDemo.java contains the following code,
import BookPackage.Book;
class BookDemo{
public static void main(String ... args){
Book b = new Book("Lord of the Rings");
System.out.println(b.getBookName());
}
}
From the development_directory, I used the following commands to compile and run the project,
development_directory/ javac BookDemo.java
development_directory/ java BookDemo
...and it compiles and works as expected.Now, I will try to convert the BookPackage folder(package) into single jar file for portability, and I am using the following command to do that,development_directory/ jar -cf bookpkg.jar BookPackage ...this command generates the bookpkg.jar file.
I am going to remove the BookPackage folder to see if bookpkg.jar file really works as a replacement for the BookPackage directory structure.
After removal of BookPackage folder, the development_directory structure looks like this,
/development_directory
____bookpkg.jar
____BookDemo.java
Now, I tried to use the following commands to see if the program works as before,
// to compile
development_directory/ javac -cp ./bookpkg.jar BookDemo.java
...it compiles without any error - this means the replacement of bookpkg.jar for BookPackage(package) folder structure is working - Am I correct?
// to run
development_directory/ java -cp ./bookpkg.jar BookDemo
...And I hit an error,
Error: Could not find or load main class BookDemo
But the BookDemo class is at default namespace - why it JRE won't be able to find the main method?
And, the way I am trying to replace package folder structure with a single JAR file - am I getting the concept correctly?
i have to write a method, The method receives a parameter of two-dimensional array of integers. The method returns the number of the column which has the lowest sum of the integers.I'm allowed to use only recursion! no loops allowed!-of course i need to make a private method that will sum a column as a single array and then i have to do another private method that compares the column , but it doesn't really work .
View Replies View RelatedThis is the code fragment I have for searching my ArrayList. Now, each contact is stored in the ArrayList with five elements (first name, last name, etc.) and they're Strings. The error I get when I try to compile my program lies within this code fragment. It says it cannot find the symbol for the search method. I'm not quite sure what to do with this error.
int foundIndex = SAAddressBook.search(aBook);
System.out.println();
if (foundIndex > -1)
aBook.get(foundIndex).displayContact();
else {
System.out.println("No Entry Found");
}
I was given some code by a professor to add some features to as part of an assignment. However, the code itself doesn't seem to work.
import java.util.HashSet;
import java.util.InputMismatchException;
import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.Set;
public class DijkstraPriorityQueue
[Code] ....
The method to find minimum distance is nonfunctional...I receive an error that the types are incompatible. I can't do the assignment if the base code doesn't work to begin with...
I'd like to know how to return a new array, I wrote in a method below the main method. I want to print the array but system.out.print doesn't work for arrays apparently. What structure i should use?
View Replies View RelatedI have to write a method called censor that gets an array of strings from the user as an argument and then returns an array of strings that contains all of the original strings in the same order except those with length of 4. For example if cat, dog, moose, lazy, with was entered, then it would return the exact same thing except for the words with and lazy.
Currently, my code so far just prints [Ljava.lang.String;@38cfdf and im stuck.
import java.util.Scanner;
public class censorProgram {
public static void main (String args[]){
Scanner input = new Scanner (System.in);
System.out.println ("How many words would you like to enter?");
int lineOfText = input.nextInt();
[Code] ....
I have to make new string array in the method and return words without four letters in the main method
Consider the following recursive method that calculates the greatest common divisor using Euclidean method.
PHP Code:
public static int GCD ( int x , int y )
{
if ( y == 0 )
return x;
else if ( x >= y && y > 0)
return GCD ( y , x % y );
else return GCD ( y , x );
}
Trace the above method for x=32 and y=46
Alright, I don't understand how to link my compress method to my return statement method "getPText". Also in my compression I only want it to compress for 3 or more consecutive letters.
import java.util.Scanner;
class RunLengthCode {
String pText;
String cText;
void setPText(String PText) {
pText = "";
}
[Code]...
I have two classes (Daughter and Son) that contain some very similar method definitions:
public class Family {
public static void main(String[] args) {
Daughter d = new Daughter();
Son s = new Son();
d.speak();
s.speak();
[Code] .....
Each of those classes has a "speak" method with two out of three lines being identical. I could move those into a parent class, but I need each of the child classes to continue to exhibit its unique behavior. I'm trying the approach below, which replaces the unique code with a call to a "placeholder" method that must be implemented by each child class:
public class Family {
public static void main(String[] args) {
Daughter d = new Daughter();
Son s = new Son();
[Code] .....
This works and moves the shared code from two places (the Daughter and Son classes) into one place (the new Mother class, which is now a parent class of Daughter and Son). Something about this feels a bit odd to me, though. It's one thing for a child class to override a parent class's methods to extend or alter their behavior. But, here, I've implemented an abstract method in the parent class to alter what happens when the parent class's method (speak(), in this case) is called, without overriding that parent class method itself.
I am just trying to test this array, for a locker combination program that involves classes...but the array is printing out the whacky numbers for the location. When I try to call the method in the main, it does not work. How do I call a method that exist within a class into the main method?
public class locker {
public static void main(String[] args) {
CombinationLock();
[code]....
Which method is used while passing or returning a java object from the native method?
View Replies View RelatedI am trying to call a private method to another method that are located in the same class.
I am trying to call prepareString to the encode method below.
Java Code:
public class ShiftEncoderDecoder
private String prepareString(String plainText)
{
String preparedString = "";
for(int i = 0 ; i < plainText.length();i++)
if(Character.isAlphabetic(plainText.charAt(i)))
[Code] .....
I am currently working on a dice game. I have a private method called rollDice and it performs the action of rolling two dice. For my project, I need to create another method called playerRolls and I am supposed to invoke the rollDice method in the playerRolls method and perform actions based off of that. My question right now is how do I invoke a method into another method of the same class?
View Replies View RelatedI need to write a method that will consume string representation of Object type and will return one object of this type. How to set return type for the method in this case?
Here is exmaple :
public <?> identifyType(String typeString){
if (typesString.matches("String")){
return new String("");
}else if (typeString.matches("Integer")){
return new Integer(0);
}
//....etc..}