Creating Object Of Class And Calling Its Method In Different Class

May 20, 2015

In the process of creating a new class, I need to move my main method from the class SaveDate to the class DynamicTest. Below I have listed the code of both classes.The objective is to be able to run my program from the DynamicTest Class. I need understanding the process of moving my main method to a different class and creating an Object of a class and calling its method.
 
public class SaveData { 
  private static final Map<String, Object> myCachedTreeMap = new TreeMap<String, Object>();
   public static final List<String> getLines(final String resourceParam, final Charset charset) throws IOException{
  System.out.println("Please get: "+resourceParam);
  if (myCachedTreeMap.containsKey(resourceParam) ) {
  // Use the cached file, to prevent an additional read.

[Code] ......

View Replies


ADVERTISEMENT

Calling A Method On Object From Another Class?

Oct 27, 2014

I have a class for employees. This class has basic information for the employee but no real pay information. And 2 subclasses, one for employee's paid for hourly rates and one for those paid a yearly salary. Each subclass has their own pay() method, that calculates and returns their pay and extra fields relative to calculate that.

I'm just curious, if I do this and create an object for an hourly paid employee like so:

Object hourly1 = new HourlyEmployeeWilson("John Doe", "123 Tech Street",361961,"Human Resources", 0,12.50,50);

How can I utilize that classes public method of pay() to gather this instance (or hourly paid employee)'s pay? I've tried doing so via:

System.out.println(hourly1.pay());

But I get

DriverPayWilson.java:9: error: cannot find symbol
System.out.println(hourly1.pay());
^
symbol: method pay()
location: variable hourly1 of type Object
1 error

View Replies View Related

Calling Method Of Another Class Which Is Implemented By Runnable Class

Aug 11, 2014

i am having a problem while calling a method..i am having a class

Java Code:

public class MySer implements Runnable {
public void getMessage(String msg)
{
...,
}..,
} mh_sh_highlight_all('java');
i use the above class in another class

[code]....

View Replies View Related

Creating / Using Object Class To Create Another Field In Another Class?

Jun 10, 2014

Design a class named Person and its two subclasses named Student and Employee. Make Faculty and Staff subclasses of Employee. There is also a MyDate class as explained below. A person has a name, address, phone number, and email address. A student has a status (freshman, sophomore, junior, or senior). Define the status as an integer which can have the value 0 (for "Freshman"),

1 (for "Sophomore"),
2 (for "Junior"), and
3 (for "Senior"),

but don't allow the status to be set to any other values. An employee has an office, salary, and dateHired. The dateHired is a MyDate field, which contains the fields: year, month, and day. The MyDate class does not explicitly inherit from any class, and it should have a no-arg constructor that sets the year, month, and day to the current year, month, and day. The MyDate class should also have a three-argument constructor that gets three int arguments for the year, month and day to set the year, month and day.

A faculty member has office hours and a rank. Define the rank as a String (for values like "Professor" or "Instructor"). A staff member has a title, which is also a String. Use data types for the fields as specified, or where one is not specified, use a data type that is appropriate for the particular field. Write a test program called TestEveryone.java that creates a Person, Student, Employee, Faculty, and Staff object, and invoke their toString() method (you don't need to call the objects' toString() method explicitly).

Note: Your MyDate.java class is the object class that your dateHired field is created from in the Employee.java class.

Do not use the Person, Employee or Faculty classes defined on pages 383 and 384 of the book. Create new ones.Here is the code I have so far concerning the employee and MyDate.

public class Employee extends Person {
private String office;
private double salary;
//private MyDate dateHired;
//7 argument constructor for employee
public Employee(String name, String phoneNumber, String email, String address, String office, double salary /*MyDate dateHired*/) {
super(name, phoneNumber, email, address);

[code]....

View Replies View Related

Calling Method Of A Class From Main Class?

Aug 31, 2014

// Add range to Vehicle.
class Vehicle {
int passengers; // number of passengers
int fuelcap; // fuel capacity in gallons
int mpg; // fuel consumption in miles per gallon

// Display the range.
void range() {
System.out.println("Range is " + fuelcap * mpg);

[Code] ....

I'm compiling it in Eclipse and this continues to show in the console display

Minivan can carry 7. Exception in thread "main" java.lang.NoSuchMethodError: Vehicle.range()V
at AddMeth.main(AddMeth.java:34)

View Replies View Related

Accessing Parent Class Method Using Child Class Object?

Feb 4, 2015

I want to know is there any way we can call parent class method using child class object without using super keyword in class B in the following program like we can do in c++ by using scoop resolution operator

class A{
public void hello(){
System.out.println("hello");
}
}
class B extends A{
public void hello(){
//super.hello();
System.out.println("hello1");

[code]....

View Replies View Related

Calling Method From Within A Class

Sep 15, 2014

I am calling a method from within a class like so:

xmlWriter.updateFile(environment, doc);

The class is xmlWriter & the method is updateFile

updateFile passes Environment environment (another class) and Document doc (document builder)

but I am unsure about it passing these through the parameters in the method call..is it correct?

Also underneath that method call for the update could I then do another method call for the export method of the file?

View Replies View Related

Calling A Method From Another Class

Mar 24, 2014

I am having problem to call a method from another class using arrays. I already know how to call a method without using arrays but I am not sure how to pass parameters to the main method using arrays. I'd really appreciate any feedback or comments!This is what I have so far.

public class Customer123 {
public static void main(String [] args){
Scanner input = new Scanner(System.in);
int x;
System.out.print("Total number of customers: ");
x = input.nextInt();

[code]....

View Replies View Related

Calling A Method From One Class To Another

Mar 6, 2015

calling a method from one class to another.I have two classes. One called Vacation and another called VacationDriver.I am trying to input an int for addVac and have the value update to the numSold within the updateSales() method in Vacation. From there it should update and display in the v1.toString in the VacationDriver.

Vacation
import java.text.NumberFormat;
public class Vacation {
private String vacationName;
private int numSold;
private double priceEach;

[code]...

View Replies View Related

Calling Private Method To Another Method Located In Same Class

Oct 23, 2014

I 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] .....

View Replies View Related

Calling Encode Method To Driver Class

Oct 30, 2014

I have a driver and a main program. How would I go along with calling the encode method to the driver class that I made so I can have the user inputs affected by the encode method?

Java Code:

public class ShiftEncoderDecoder
{
private int shift;
public ShiftEncoderDecoder(int shift)
{
setShift(shift);
}
public int getShift()

[Code] ....

View Replies View Related

Creating Object Of Inner Class - Getting Error

Aug 23, 2014

package home;
import java.awt.Color;
import java.awt.Graphics;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class Box{
int x=70;
int y=70;

[Code] ....

L a = new L(); causing the error. It will be great to know why it is showing error.

View Replies View Related

Binary Search Tree - Calling FindSmallest Method In Main Class

Nov 3, 2014

How should I call my findSmallest method in the main class.. Here is the code:

public class Tester {
public static void main(String[] args){
try {
BinaryTree<Integer> myTree2 = new BinaryTree<Integer>();
 
myTree2.insert(5);
myTree2.insert(2);
myTree2.insert(7);

[Code] ....

So the question is what kind of parameter I should pass in myTree2.findSmallest()??? Here is my findSmallest method..

public E findSmallest(Node<E> parent){
if(parent.left.left == null){
E returnValue = parent.left.data;
parent.left = parent.left.right;
return returnValue;
} else {
return findSmallest(parent.left);
}
}

View Replies View Related

Swing/AWT/SWT :: Can't Change Visibility Of Two JPanels When Calling Method From Button Event In Another Class

Dec 30, 2014

I have two classes involved in this portion. CheckIn_Search

(class #1) is my main UI and I am collecting search information from the user in a jPanel form. When they click "Search" it passes the search criteria to a method that contacts a web service and gets the results. These results are passed to coSearchResults

(class #2) that opens a jFrame and jTable (in modal format, over the main window created by CheckIn_Search.

The user selects a row in the table and that selection data is passed back to coSearchResults to populate a new jPanel form. When the data is passed from coSearchResults, I want to close its window, hide the first jPanel in CheckIn_Search and make the second jPanel visible. To accomplish this, I created a method in CheckIn_Search that simply hides/shows the panels (it will do more later).

I instantiate and call the method in CoSearchResults as part of the button click event. The problem is, it doesn't work. The panels are unaffected and there are no errors. I've put in break-points and it goes into the method.. Here is the coSearch_Results code.

Here is am retrieving the jtable row id and using the first value in the row to get the data from the table model as there is more data than what is displayed in the table. I'm sending that whole row of data to the method that changes visibility.

private void btnOKActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnOKActionPerformed
// TODO add your handling code here:
int rowNum = jTable1.getSelectedRow();
String coNum = jTable1.getValueAt(rowNum,0).toString();
String[] text;

[code]....

View Replies View Related

Servlets :: Calling DoGet Of Child Class From Service Of Parent Class

May 28, 2014

Regarding the lifecycle of servlet , in headfirst servlet i can find :

You normally will NOT override the service() method, so the one from HttpServlet will run. The service() method figures out which HTTP method (GET, POST, etc.) is in the request, and invokes the matching doGet() or doPost() method. The doGet() and doPost() inside HttpServlet don’t do anything, so you have to override one or both. This thread dies (or is put back in a Container-managed pool) when service() completes.

How can I call the doGet method of the subclass from the superclass. i am not getting this .

View Replies View Related

Creating Equals Method To Compare Strings In A Class?

Mar 26, 2015

How would I create a equals method to compare strings in a class that I'm creating. I need to create the method in my class, and then call it in a driver. How would I do this?

View Replies View Related

Passing Parameter From Object Of Class B To Object Of Class C By Use Of Class A?

Dec 13, 2014

Assuming that we have two classes B and C which inherit from class A. What is the best way to pass a parameter from an object of class B to an object of class C by the use of class A without using static variable and without defining a get function in B?

View Replies View Related

Why Protected Method In Class Object

Nov 1, 2005

I don't know why class Object have two PROTECTED method -- clone() and finalize(). And in JUnit's source code, I notice that kent write :public class AClass extends Object {}I really don't understand what diffrient frompublic class AClass {}

View Replies View Related

Create Method In Main Class And Use It On Object

Feb 26, 2015

I've been writing classes over and over for school. So I create a class outside of my main class. I create a new constructor and then create objects from my main class. I hope that makes sense. So i use methods in that class to work with the object. So I have an object name I've created <dot> method name. So I can create objects and then use methods from the class, but I'm wondering can I create a method in my main class and use it on that object? I don't understand how to do that.

View Replies View Related

Overriding Equals Method From Object Class

May 5, 2014

I am attempting to override the equals method from the Object class which checks if two variables point towards the same object. I want the method to check if if the argument being passed in(an object) has the same data(instance variables) as the object that's calling this method. A NullPointerException is being thrown; Here is the code.

package javaapplication5;
import java.text.NumberFormat;
import java.util.Scanner;
import java.lang.Object;
public class Product {
private String product;
private String description;
private double price;

[Code] ....

And here is the stack trace

Exception in thread "main" java.lang.NullPointerException
at javaapplication5.Product.equals(Product.java:42)
at javaapplication5.Product.main(Product.java:24)
Java Result: 1

View Replies View Related

Creating New Constructor In Child Class Which Is Not In Parent Class

Feb 7, 2014

I've a parent class with a argument constructor like below(a sample code)

public class Parent {
Parent(String name) {
System.out.println(name);
}
public static void main(String[] args) {
}
}

Also I've child.class which extends Parent.class as shown below,

public class child extends Parent {
child(String name) {
super(name);
}
}

Now, I want create/modify the constructor which is in child, by taking "int i" as an input instead of "String name". How can I do that? Run time I want to execute child constructor not a parent constructor.

Condition is: Without making any changes to the Parent class

View Replies View Related

Creating New Non-static Inner Class Outside Of Parent Class

Nov 22, 2014

I have an Abstract Class called GameColorEffect which contains a number of non-static Inner Classes that extend their Parent Class, GameColorEffect. I want to be able to create instances of the Inner Classes, however my IDE, eclipse, prompts me with the error:

No enclosing instance of type GameColorEffect is accessible. Must qualify the allocation with an enclosing instance of type GameColorEffect

And eclipse shows me a possible solution which is to turn the Inner Classes to static, this would allow me to create instances, but not really. This is because using methods from the static Inner Classes that change values in the Inner Classes will do this for every instance of the same Inner Class which is literally like a single instance. However, I want these Inner Classes to be individual with their values and still be able to use them outside as instances. I've found out a possible solution, which I'm not sure works like I want it to:

Java Code : GameColorEffect = new GameColorEffect.ExampleEffect(); mh_sh_highlight_all('java');

However, this is in-compact because sometimes all I need is to use just a method like:

Java Code : new GameColorEffect.ExampleEffect(intensity).applyEffect() mh_sh_highlight_all('java');

And another solution that I already knew prior was that I could make the Inner Classes proper classes not inside of the GameColorEffect class, but this is also in-compact because I will have to have so many classes for the so many effects that I have.

View Replies View Related

Pass Private Final Class Object To Another Class Constructor

Aug 28, 2014

can we pass private final class object to another class constructor?

View Replies View Related

How To Create Object For Multiple Class Inside Single Class

Apr 22, 2015

How to create object for "class B" and call the "function_B" from other different class D where class D has no connection with class A? Here is my program.

public class A(){
void print(){}
}
class B{
void function_B(){}
}
class C{
void function_C(){}
}

Here, A, B, C are in the same package. But class D is in different package.

View Replies View Related

Interface Class And Object Class Is Compiling Symbol Errors

Nov 16, 2014

I am a beginner here at JAVA and I am trying to program a Gratuity Calculator using both interface class and object class but it keeps on compiling with errors saying "cannot find symbol".I tried everything to fix it but it just keeps on stating symbol.

[CODE]
public class GratuityCalculator extends JFrame
{
/* declarations */
 
// color objects
Color black = new Color(0, 0, 0);
Color white = new Color(255, 255, 255);
Color light_gray = new Color(192, 192, 192);
 
[code]....

View Replies View Related

Modify Class Time2 To Include Tick Method That Increments Time Stored In Object By One Second

Jul 9, 2014

Modify class Time2 to include a tick method that increments the time stored in a Time2 object by one second. Provide method incrementMinute to increment the minute and method incrementHour to increment the hour. The Time2 object should always remain

a) incrementing into the next minute,

b) incrementing into the next hour and

c) incrementing into the next day (i.e., 11:59:59 PM to 12:00:00 AM).

how to manage case 4 stuff and what's the problem of this CODE.

import java.util.Scanner;
public class Time2Test
{
public static void main( String args[] )
{
Scanner input = new Scanner( System.in );
Time2 time = new Time2();
// input
System.out.println( "Enter the time" );
System.out.print( "Hours: " );
time.setHour( input.nextInt() );

[code]....

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved