I'm taking inheritance now and some things look confusing. I'm trying to do the following but the code, in particular, the constructor in subclasses are pointed to be wrong. The constructor in LongestWord is not correct,how to pass the filename into the constructor?
Java Code:
import java.util.Scanner;
import java.io.File;
public abstract class FileProcessor {
protected Scanner input;
public FileProcessor(String filename) throws Exception
I am looking to write a constructor (in a herited class) to initialize the name of a single piece and its orientation using values passed as parameters. If no value is given for guidance , it returns "none" , I do it in this way but i am not sure it is the right way:
Suppose there're two classes: Exam and MainExam (contains a main method). class Exam has a constructor public Exam(String firstName, String lastName, int ID). Class MainExam reads data from a textfile. For example, the data can be: John Douglas 57. How can one pass data to the constructor from a textfile?
I want to make a tool that does the 2 following things::
- Open files that are not .txt but can be opened as .txt and return them as a string. It just returns an empty string at the moment.
- The filenames are unknown, just the file extension at the end and the the YYYYMMDD number in front are always the same, therefore I'd like the app to simply scan every file in the same folder (not the same file twice, obviously). How can this be done?
I have an program with an encryption and a decryption method, it works fine when i specify a name for the encrypted file, but i want the name for the encrypted file to be in cipher text, how do i do this and specify the path? i have marked out the "encryptionPath" specifically for specifying the location of the encrypted file which will have a cipher text name.
I was practicing my java skills and came across an exercise in which a non parameter constructor calls a two parameter constructor. I tried a few searches online but they all came back unsuccessful. This is the part I am working on:
public PairOfDice(int val1, int val2) { // Constructor. Creates a pair of dice that // are initially showing the values val1 and val2. die1 = val1; // Assign specified values die2 = val2; // to the instance variables. } public PairOfDice() { // Constructor that calls two parameter constructor }
I tried calling the two constructor using the line "this(val1, val2)" but I get an error because val1 and val2 are local variables.
Then I tried to use the same signature: "this(int val1, int val2)" but that didn't work either.
public static void main(String[] args) throws Exception { String s = "oldString"; reverse(s); System.out.println(s); // oldString } public static void modifyString(String s) { s = "newString"; System.out.println(s); // newString }
I thought the first print statement would print "newString" as String is an object, and when we pass objects between methods, changing state of the object in any method reflects across the methods.
I'm fairly new to Java, I'm very experienced with C++ and C# in which you can pass by reference - extremely useful. Take for example this bit of code in C#:
class MyClass { public MyClass(int i) { m_i = i; } public int m_i;
[Code] ...
Just at the end of this program x.m_i will be equal to 8. As far as I can see this is not possible in Java: you can't pass a double by reference, using a Double will kick in the autoboxing so that won't work either. The only "solution" in Java would be to pass in a double[] (of length 1) or to make a wrapper class, both nasty solutions because a user may want to just hold a double as a member of their class just as I have, for reasons such as not allocating more memory for a class and generally not being bloated.
i'm able to login and download pages of a website using httpclient library.but i cannot launch a page on browser after login successful!becouse the browser not remember the username and password of the session so the site show that i'm not logged!
I am new to the JMS technology. I have written one sample sender and receiver program to pass a string message to the JMS queue and retrieve it back. It is working fine as well. But now, I want to pass a xml file to the JMS queue. Then from there I need to read the XML file and convert it into a Java object Using Jaxb. I know how to convert an XML into java object using Jaxb. But i am unable to send the XML file as a jms message to the listener.
As the title says, how can I pass a value from one variable to another class?
Example:
So here I'm switching one frame to another, called "redigeraProjekt". Now in this class, I want the value from .getSelectedIndex() pass over to that class. I've tried to use the variable "valIListan" but it cannot find it. Probably because it's "private" (?)
valIListan = listaAllaSpelProjekt.getSelectedIndex(); redigeraProjekt npj = new redigeraProjekt(); // "switching" to another frame npj.setVisible(true); this.setVisible(false);
I'm new to Java and I'm trying to pass several values from one frame to another. I've searched around and most codes I've come across are from auto generated GUI code. This what I've been trying to do
Frame1
private class SubmitButtonListener implements ActionListener { public void actionPerformed (ActionEvent e) { Frame2 f2 = new Frame2(); //call setValue from Frame2 f2.setValue(4.0); f2.setVisible(true); } }
Frame2
private double val; public double getvalue() { return val; } public void setValue(double v)
Why will this NOT validate correctly in my IF Statement? Basically, a user chooses an option from the drop down list. The value is passed to t.jsp (itself) and if the option "All" is chosen, then it does something. If any of the years are chosen, then it does something else.
How do I pass the data within an initialized array from inside one method to another method of the same class? Will I need to return the array, assigning it to a temp array, which will then be passed as an argument to the other array? The idea is to create an array for an entire year, and be able to manipulate or edit data for a particular month using the other method.
public class Temperature { static Scanner input = new Scanner(System.in); static String [] monthArray = {"January", "February", "March", "April", "May", "June", "July", "August", "October", "November", "December"}; public static void main(String[] args) {
I have a variable <c:set var="var1" value = "myvalue" /> , I want to pass var1 as <%= new customclass().method1(var1) %>.what is the syntax to pass this value.