Using Accessor Methods To Access Data From Another Class

May 6, 2014

I have been asked to write a program with 3 classes(an interface, a store and a product class) and I have been going ok until I need to display data on the interface that is held in the product class. At the moment the code will compile fine but when I run the program and try to use the writeOutput() method I get a stack overflow error.

I realise now that it is because of a non-terminating recursive call, however I can not think of a solution on how to fix the problem. And just to clarify, what I am aiming to do is have the MatesTerminal class display the data for name that is stored in the Product class(I have no way of determining which product to display at this time, so I would like to be able to display the data for all three products if possible). Anyway this is what I have so far:

The method from the MatesTerminal Class:

private void writeOutput() {
int productChoice;
Scanner console = new Scanner(System.in);

[Code].....

View Replies


ADVERTISEMENT

Sphere Class Using Accessor / Mutator Methods

Feb 25, 2014

So I've been working on this sphere class forever and have tried rewriting it a number of times. each time i change something i get a different error...

Instructions: create a sphere class with the following properties:

private attributes: x, y, z coordinates of center, and the radius.

Accessor and mutator methods to: set and get the x,y,z coordinates, set and get the radius, get the volume and surface area of the sphere.

This is the main sphere class:

Java Code:

package spheretester;
<pre class="brush:java;"> */
import java.io.*;
import java.util.Scanner;
public class Sphere {
public static void main(String[] argv) throws Exception

[Code] ....

View Replies View Related

Scanner Class - Can't Seem To Access Methods

May 9, 2014

I have two classes built for this assignment. One with getters, setters and constructor and a test class. The test class works fine up until the point when the user wants to (M)odify an employee that he/she built with the loadEmployee method. What happens is I need to enter multiple "M" inputs before anything pops up, and when something pops up, it's the displayMenu instead of modifyEmployee method. I imagine it has something to do with the amount of sc.nextLine()

import java.util.Scanner; // utilize scanner via console
import java.text.NumberFormat; // allows numbers to be format in form of currency
//Example of "big loop" in main to repeat using a No Trip (0,N) test first
public class EmployeeTest {
// space provided to make code easier on eyes...

[code]...

View Replies View Related

Month Class With Constructors And Getter / Setter Methods To Access Attributes

Jul 22, 2014

Write a class Month that represents one of the twelve months of the year. It should have three attributes for

the name of the month,

the number of days in the month, and

the birthstone.

Also add constructors and getter/setter methods to access the attributes.

You may use the following code to test your class.

Java Code:

import java.util.*;
public class Month
{
// ADD CODE HERE!!!
public static void main(String[] args)
{
Month[] months = new Month[12];

[Code] ....

So what I have added so far is (under public class month { :)

Java Code:

String monthName, monthBirthStone;
int monthDays;
public Month (String name, int days, String birthstone)
{
monthName = name;
monthBirthStone=birthstone;
monthDays=days;
} mh_sh_highlight_all('java');

So I believe that is the constructor. I still do not understand several things:

What would I need the getter and setter for?

I tested it using just the above code, and using month 1 I got:

Month@5a1cfb56

This makes sense as I obviously didn't do anything in order to get it in a String format for the array. But I do not understand this still - how would I get the constructor to output a string (to then be in the array?)

View Replies View Related

How To Access Objects Data From Another Class

Oct 3, 2014

I've been unable to figure out how to access an objects data from another class. I ended up missing a lesson in java and haven't been able to catch up on this topic on my own through my textbook.

Error: has private access

Code:

public class TestCoffeeDrinker {
public static void main(String[] args) {
Coffee latte = new Coffee("Starbucks Tall Latte", 2.85);
Coffee mocha = new Coffee("Starbucks Grande Mocha", 3.95);
Coffee mcdonalds = new Coffee("McDonalds McCafe", 0.99);
System.out.println(mcdonalds.toString());

[Code]...

View Replies View Related

RetailItem Class Modify With Accessor Mutator

Apr 23, 2014

Here is what i have so far. The retaiItem class and the demo. Basically, my output looks like this:

Description:
Candy bar
Item Number: 17789
Wholesale Cost: $0.75
Retail Price: $1.50
new wholesale cost: 1.0
new retail price: 1.99

[Code] ....

package retailitemdemo;
public class RetailItemDemo {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {

[Code] .....

View Replies View Related

How To Access Methods From Other Classes Using Buttons In Javafx

Jun 4, 2014

I have a javafx class that has buttons and textfields. Here is the code for a button, and i want the button to make a new object but im having trouble setting the constructor

Label label = new Label("Type");
GridPane.setHalignment(label, HPos.RIGHT);
TextField textField = new TextField();

Label label2 = new Label("First Name");
GridPane.setHalignment(label2, HPos.RIGHT);
TextField textField2 = new TextField();

[Code] ....

after i create the object i will insert the object in an arraylist of person objects

View Replies View Related

Declaring Methods For A Class In Its Own Class Whilst Objects Of Class Declared Elsewhere?

Mar 5, 2015

How do you declare methods for a class within the class whilst objects of the class are declared else where?

Say for instance, I have a main class Wall, and another class called Clock, and because they are both GUI based, I want to put a Clock on the Wall, so I have declared an instance object of Clock in the Wall class (Wall extends JFrame, and Clock extends JPanel).

I now want to have methods such as setClock, resetClock in the Clock class, but im having trouble in being able to refer to the Clock object thats been declared in the Wall class.

Is this possible? Or am I trying to do something thats not possible? Or maybe I've missed something really obvious?

View Replies View Related

Access Getter / Setter Of Bean Class Where It Defined As Member In Another Class?

Feb 18, 2014

Class UserAssessBean{
private String username;
private int userid;
private ArrayList<ModuleBean> module;
--{get/set}--

[Code] ....

How can i access the getters/setters of module bean, when it was returned as array list in UserAssessBean?

View Replies View Related

JSP :: How To Access Data In Different Domain

Aug 26, 2014

We have implemented SSO based on cookies.

1. user clicks the link in our app (www.app1.com) , cookie set up done (respose.addCookie)
2. request will redirect to (third party software, cant change anything)
3..Here if the SSO enabled, it will redirect to the another URL (www.issues.app1.com) .
4,Have to get the cookie(User details) set in #1 here and validate.

Its working fine .But if we change the www.app1.com to www.abc.com , SSO is not working. We cant change www.issues.app1.com.

How to share the cookie in cross domain across 3 apps ? because middle app , we dont have control over it.

View Replies View Related

How To Access Data In Array Of Objects

Apr 23, 2014

I want to keep count of how many students are in my array. the array i made up of objects from other classes. like the class Student how do i do this. i have tried contains but better way it to to a loop to go through the array and determine if each object is a particular type but i don't know how to do this. here is the code

import java.util.*;
import java.util.ArrayList;
public class Driver {
public static void main(String[] args){
/* Comments required
PersonFileReader pfr = new PersonFileReader("person.dat");
ArrayList<Person> testData = pfr.readData();
Database db = new Database(testData);

[Code] .....

View Replies View Related

Insert Data Into Access Database

Mar 29, 2014

I need my java program to insert data into my access database. I get no errors in my code, but it never inserts, deletes the data in my database. Here is my code:

import java.awt.*;
import java.awt.event.*;
import java.sql.*;
 public class INS extends Frame implements ActionListener{
Frame f;
Label l1, l2;
TextField t1, t2;
Button b1, b2, b3, b4, b5;
Connection c;

[Code] ....

View Replies View Related

Creating Accessor And Mutator For Dual Array?

Apr 19, 2015

I am familiar with creating accessors and mutators, Any example of how to create them for dual arrays? I need the dual arrays to be int

View Replies View Related

How To Insert Cachedrowset Data Into MS Access Database

Feb 11, 2015

I'm new to java and trying to insert data from a cachedrowset into MS Access database, Below is the error code that I get after running my program.

java.sql.SQLException: Parameter-Set has missing values.

The SQL test table that I am using.

Java Code:

create table book (
TITLE_ID CHAR(3 BYTE)
TITLE_NAME VARCHAR2(40 BYTE)
TYPE VARCHAR2(10 BYTE)
PUB_ID CHAR(3 BYTE)
PAGES NUMBER(38,0)
PRICE NUMBER(5,2)
SALES NUMBER(38,0)
PUBDATE DATE
CONTRACT NUMBER(38,0)
); mh_sh_highlight_all('java');

SQL table values with blanks:

Java Code: TITLE_ID TITLE_NAME TYPE PUB_ID PAGES PRICE SALES PUBDATE CONTRACT
T01Java history P0111121.99 566 01-AUG-001
T02Oracle history P0311419.95 9566 01-APR-981
T03SQL computer P0212239.95 25667 01-SEP-001
T04C++ psychologyP0451112.99 13001 31-MAY-991
T05Python psychologyP041016.95 201440 01-JAN-011

[code]....

Below is the piece of java code that I am using.

Java Code:

public void insertAccessTable(Connection connection, CachedRowSet CRS_insertAccess) throws Exception
{
try
{
RowSetMetaData metaData = (RowSetMetaData)CRS_insertAccess.getMetaData();
ArrayList<ArrayList<String>> TwoDimArrList = new ArrayList<ArrayList<String>>();
TwoDimArrList.add(new ArrayList<String>());
TwoDimArrList.add(new ArrayList<String>());
ArrayList<String> ColArrList = new ArrayList<String>();
for (int column = 1; column <= metaData.getColumnCount(); column++) {

[code]....

View Replies View Related

How To Read Data From Random Access File

Jul 10, 2014

I have a random access file stream. I have below code I want to written data that is currently pointed by pointer till the end and display that data on System.out Stream but it is not working my code is

//Create a Random Access File
java.io.RandomAccessFile random=new java.io.RandomAccessFile("D:/input.txt","rw");
//Position the pointer to a seek
try {
random.seek(300);
long pointer=random.getFilePointer();
System.out.println("Current Pointer is:"+pointer);
int a;
while((a=random.read())!=-1) {
System.out.println(a);
}

Where am I wrong? Although it is returning actual position of pointer in pointer using

View Replies View Related

Random Access File - How To Retrieve Particular Set Of Data

May 4, 2015

I am creating a read/write, RandomAccessFile that I will use to store several student ID and gpa score. What I don't understand is how I should go about retrieving a particular set of data.

public class ReadWrite {
static Scanner keyboard = new Scanner(System.in);
static String fileName = "Stu.dat";
static RandomAccessFile raf;
public static void main(String [] args) throws FileNotFoundException, IOException {

[Code] .....

View Replies View Related

JavaFX 2.0 :: Access Scene Graph Data From EDT

May 11, 2014

I have following methods, which I call from the Event Dispatcher Thread:
 
public void setTitle(String title) {       
Platform.runLater(() -> stage.setTitle(title));}   
public String getTitle() {       
return stage.getTitle(); // <- Access from outside JFX App Thread ok?} 

Is it thread-safe, when the getter-Method just return the value like the example show? Or must I create a Runnable, so stage.getTitle() is called inside the Java Application Thread? How I return the value then?

View Replies View Related

Inheritance In Java - Child Class Get Copy Of Methods And Variables Of Parent Class?

Mar 1, 2015

Does child class gets a copy of the methods and variables of parent class?

public class test1 {
public static void main(String a[]) {
Child c = new Child();
c.print();

[Code] ....

why is the output 1?

View Replies View Related

Methods From Original Class Receiving Error When In Test Class

Jul 5, 2014

I am working on a program that simulates a bug moving along a horizontal line, My code works correctly when I test it in it's own class but when I tried testing my constructor and methods in a test class I received an error saying, "package stinkBug does not exist" on lines with my methods. However, stinkbug is not a package.

Java Code:

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/

[code]....

View Replies View Related

Write A Class Named Calculator Add Four Methods To That Class

Jan 30, 2014

Write a class named Calculator add four methods to that class:

add(int a, int b)
sub(int a, int b)
mul(int a, int b)
div(int a, int b)

Then write a Tester class with main function and show the use of the methods in Calculator class..

View Replies View Related

Write Data For Three Products To Random Access File - Unexpected EOFException

Jul 11, 2014

I'm trying to write data for three products to a random access file, but I have a problem. Each product has a code and a price. After writing them to my file, I want to get to the second field or product. I do this by getting the length for each record, and multiplying it by the field number I want to go to. I use the result for the seek() method of the RandomAccessFile object. It is giving me an EOFException, but when I use 0 for the seek method i get the data for the first poduct or field.

Java Code:

public static void main(String[] args) {
final int RECORD_LENGTH = 16;
try(RandomAccessFile productsOutput = new RandomAccessFile("C:UsersalfonsoDesktopBinaryTestRandom.ran", "rw")) {
String[] codes = {"java", "jsps", "txtp"};
double[] prices = {49.5, 19.9, 29.9};
for(int i = 0; i < codes.length; i++) {

[Code] .....

View Replies View Related

Access To Variables In Another Class?

Oct 4, 2014

I will like to add to the questions about constructors and its this. I have a class A with a constructor, i have a class B which initialize the constructor. also i have a class C which needs a variable in class A but doesn't need to initialize the constructor of A. the question how do i access the variable of class A without initializing the constructor.

View Replies View Related

How To Access JFrame From Another Class

Oct 9, 2014

This is my main.java:

import javax.swing.UnsupportedLookAndFeelException;
public class Main
{
   public static void main(String[] args)
         throws ClassNotFoundException, InstantiationException, IllegalAccessException, UnsupportedLookAndFeelException
   {
      Core window = new Core("GAME1", 0, 0, true, true);
   }
}
 
And this is my Core.java:

import java.awt.GraphicsEnvironment;
import java.awt.Window;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

[Code] ....
 
In Core.Java at line 80 how can I access window (

JFrame window = new JFrame(Game_Title); // <- this window
) ?

Also should I use throws or try and catch ?

View Replies View Related

Returning Data Using Set / Get Methods

Jan 23, 2015

I'm writing a program that involves the use of set/get methods. I will submit a sample code of my issue. The format appears to be alright however the program is not returning any data. This is the same format as my actual code. Why this might be happening?

Java Code:

public static void main(String [] args) {
SecondClass object = new SecondClass();
object.setName("Name");
object.getName();
} mh_sh_highlight_all('java');

Java Code:

public class SecondClass {
private String name;
public SecondClass(){
name = " ";
}
public void setName(String name) {
this.name = name;
}
public String getName() {
return name;
}
} mh_sh_highlight_all('java');

View Replies View Related

Swing/AWT/SWT :: Access JLabel From Another Class

May 6, 2014

How can I access to a jLabel of a class from another class or edit its text?

View Replies View Related

How To Access Getter Method From Different Class

Sep 16, 2014

I have 2 classes. TestClassA has 1 getter and 1 setter. From my second class, TestClassB, I want to access the getter method of TestClassA. If I try to access it, I get null. How do I do it?I do not want the methods to be declared as static. How can the getter method value be printed in TestClassB (without marking anything as static)?

public class TestA {
private String name;
public String getName() {
return name;

[code]....

View Replies View Related







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