SimpleCharacterReader.java::
import java.io.EOFException;
import java.util.Random;
public class SimpleCharacterReader implements ICharacterReader {
private int m_Pos = 0;
[Code] ....
My task is as follows:
1.) Write a class that takes an ICharacterReader interface as an argument and returns a list of word frequencies ordered by word count and then alphabetically.
And also write a main method of a console application that exercises this class using a SimpleCharacterReader, and prints the output to the console.
For example, if the stream returns "It was the best of times, it was the worst of times" then the output will be:
it - 2;
of - 2;
the - 2;
times -2;
was - 2;
best - 1;
worst - 1;
2.) Test the answers in part 1, by writing unit test cases.
How to pass interface as an argument and what is meant by "writing unit test case"?
I am trying to pass an object of type Product p to my editProduct method, however trying to call p.getName(); doesn't work and throws a NullPointerException. The same kind of thing works for my displayRecord method (in a different class) and I can call .getName() on Product p, also passed as an argument to that method. Below is my editProduct class. The NullPointerExcepion is being thrown at line 61 (i.e., nameField.setText(p.getName());).
I don't know if I explained right, so here's a line thing of how the classes relate:
And as a side note: adding the line p = new Product(); fixes it and successfully runs the class (including the Save and Quit parts) but obviously I want it to specifically refer to the Product I pass to the method.
I'm asking a question because I don't understand how Product p could possibly be null, because the argument is passed through my DisplayRecord class, which also takes a Product p argument and works. In that class, I have declared Product prod = p; and prod is what I am passing to editProduct.
I want to read property file in java from command line argument,i.e. if i have some parameters which i have to use separately , i comment the parameters which i don't have to use that time , then uncomment when i have to use.
Is there and way to read the required parameters through command line arguments in java.
I am trying to complete this question. I understand the most of it but I haven't go a clue to read in the file name.
Full question: Implement a program that reads in a Java source code file and checks to see if it has balanced {}brackets. Your program should use a stack, implemented as a linked list, to check the brackets.
NOTE: you can use a reference called top which points to the head of the list. Your program should run as a command line program and should take a filename as an argument and print one of BALANCED or NOT BALANCED.
For example: c:> java checkBalanced "myProgram.java" BALANCED
why don't I define my methods in a class, rather than going a level up and declaring it first in an abstract class/interface? If the point is to have different implementations for different needs, then we have the option to override the methods.
I am trying to implement this method in another class but I'm not sure how to do so. My attempt is:
public getCalls(){ return getCalls(); }
When I run the program it sends the following exception:
Exception in thread "main" java.lang.StackOverflowError at FibonacciForget.getCalls(FibonacciForget.java:14) and it highlights the [return getCalls();] part.
What is the correct way to implement the getCalls() method?
Can we pass array as a cmd line argument as follows ?
>java TestRun file[], number if yes, in the main(), how do we capture this array ? public static void main(String [] args){ String [] files = args1 ; // or will it be String [] files = args1[]; }
class Test3 { } class MySub extends Test3 { } class Test4{ public static void main(String args[]) { MySub m = new MySub(); } }
I learned that if a class and its parent class both have no constructors, the compiler is supposed to complain. When I compiled Test4, i got no errors. why did it give no errors?
So I have an application where the user logs in (using j_security_check). User is taken to a welcome page where user's name is displayed as a link. When clicking that link I would like to take the user to a page where the user is able to update the credentials (password, address, etc). In this way the user only has access to the link related to that specific user's credentials. I am trying the following structure:
public String selectedUser() { userName = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get(userName); selUser=uServ.findByName(userName); return "UpdateUser";
[Code] ....
The last line of the stack suggests that a null PK value is being picked up by the FacesContext method in the backing bean. I'm confused because the userName string IS the primary key of the user table which is structured like this:
One interviewer has asked me one question that why main() method has argument "String[] arg".What is reason behind this ??I am unable to explain it because i never think about it ..
So I'm trying to make a simple program which takes in an argument (target) and then looks through an ArrayList of strings. If it finds a string that begins with (target) then it will return the index of that string. If it doesn't find a string which begins with (target) then it will return -1 instead.
For some reason, the program is always returning -1, rather than the index of the string within the ArrayList when there is one which matches the search criteria.
Here is the code:
public int getIndex(ArrayList<String> text, String target) { int i = 0; int index = -1; boolean found = false;
I am trying to create a class to read data from the JOptionPane. I am trying to create a general procedure and then be able to overload it using the rest. Basically I just want to call the procedure readString with options and without options while verifying that the user entered the correct information.
Java Code: public class BankIO { public static final Object[] mainMenu = {"1. Create Account", "2. Delete Account", "3. Update Account", "4. Display Information", "5. Quit"}; public static final String APPLICATION_NAME = "Banking Pro";
I'm having trouble with how to read a text file into my program so the words can be sorted alphabetically. Should I use something like a FileReader?
An example of what I'm trying to do is a .txt file that holds the statement "java is a simple object oriented and distributed and interpreted and robust and secure and dynamic."
The output should organize the words like so: and and and and distributed dynamic interpreted is java object oriented robust secure simple
Here's what I have:
public static void main(String[] args) { if (args.length != 1) { System.out.println("Usage: java AscendingAlphabet"
[Code].....
I can never get it to read the file correctly, it just prints the "usage: java..." statement.
But for the method get() of Paths, I get this error in eclipse.The method get(String, String[]) in the type Paths is not applicable for the argument..Yet on the Oracle documentation site, it uses a similar example:
I have learn that every function in java is treated as a normal function including main() except that execution of a program starts here. I tried to overload it.
But I am getting error while doing so via String type array as an argument of main.
class Hello { public static void main() { System.out.println("Hello"); } public static void main(String... s) { System.out.println("main from Hello");
I'm writing a Java program to get the gpa of a student as a command line argument. Then display the class of the degree according to some criteria. Here is my code. But it says "ArrayIndexOutOfBoundsException :0". How can I fix this?
public class Stgpa { public static void main(String[] args) { double gpa= Double.parseDouble(args[0]); if(gpa>=3.6) System.out.println("Class of the degree is: First Class Hons"); else if(3.6>gpa && gpa>=3.4)