Possible To Set Setter And Getter Various Times

May 8, 2014

I am trying to set my setter and getter various times o that I can store a name, price and value but i can only set it once. Once i try to set again the previous entry resets.I have tried

job = sc.next();
jobdetails.setjob(job);
wage = sc.next();
wageD.setwage(wage);
hours = sc.next();
hourd.sethour(hour);

This sets the values for me and i receive the input i entered but if i try to enter again the input from before is removed.I have searched array lists and tried

[code] List<Object> list new ArrayList<Object>();
list.add(jobname)
list.add(price)
list.add(Event)

out.println(list.get(0));

for (Object s : list) {
out.println(s);
}

For this to work I would have to keep adding list.add. Is there a way I can use the array to add a new item to the list so that when I try to display what I have stored in the setter and getter it will display what I have entered in each time instead of only the last input? or any other way that may be possible to do this?

View Replies


ADVERTISEMENT

Using Setter And Getter Methods Instead Of Altering Variables

Apr 15, 2015

i need to change my code in order to stop the member variables from being directly altered and its been suggested that i should use a setter and getter method. Ive read up about these and im still unsure at how they should be implemented into my code for my project.

import ddf.minim.*;
DragShape[] piece =new DragShape[77];
PImage puz16;
PImage frame;
PImage text;

[code]....

View Replies View Related

ImageIcon Setter And Getter Methods Not Working

Jan 3, 2015

I have been assigned with a task to have a class which has the methods setImage and getImage. These methods are meant to set the ImageIcon by using the url taken from another class and the getImage method is meant to return the ImageIcon that was set before hand. The problem is that i'm not really familiar with ImageIcon so the code in both my methods is giving out errors and i just can't figure out why. Heres the code in the class that has the setImage and getImage methods:

public class Die implements DieInterface {
private ImageIcon [] image = new ImageIcon[6]; //the number of images that would be stored in this array is 6 (six faces of the dice)
ublic Die()
{
//This puts images into the images array(the different die faces)
image = new ImageIcon[6];

[code]....

And this is where i call the methods (set and get methods) in the other class:

die1.setImage(new ImageIcon(Dice.class.getResource("face1.png")));
die1.getImage();

View Replies View Related

Fields / Getter And Setter Methods And Constructors

Mar 12, 2015

A blood clinic has hired a team of software developers to build a custom application to track patients. The clinic needs to keep a record of each patient and his or her blood data. Ultimately, they want all of the information stored in a database. As a starting point, the development team leader informs the team that the application has to have a set of core classes that represent the “real-world” entities the program needs to deal with. As a developer on the team, your job is to build a Patient class along with a BloodData class so that each Patient contains a BloodData object. This principle is known as “composition.”

Building the Framework Begin by creating a public Java class named PatientBuilder that contains a main method. Then, in the same file, create a non-public class named Patient and another named BloodType. Save the file as PatientBuilder.java. Note: If this was a real development project, you would put each class into it’s own file and put the files in the same folder. By combining them all into one file, we avoid having to submit three separate files, making it easier to keep all your work in one place.The BloodData Class This class should hold all of the attributes to hold the data the clinic needs for a given patient’s blood. Implement the following capabilities to accomplish this objective:

• Create a field to hold a blood type. The four possible blood types are O, A,B, and AB. For this project, you can simply define the field as a String.
• Create a field to hold the Rh factor. The two possible Rh factors are + and –.For this project, you can simply define the field as a String.
• Create getter and setter methods for both fields.
• Create a default constructor that sets the fields to “O” and “+”
• Create an overloaded constructor that accepts two parameters – one for a proposed blood type, and another for a proposed Rh. The constructor
should call the set methods and pass these parameter variables in to them.The Patient Class This class should hold all of the attributes to hold the data the clinic needs for a given patient’s blood. Implement the following capabilities to accomplish this objective:
• Create a field to hold an ID number along with get and set methods.
• Create a field to hold the patient’s age along with get and set methods.
• Create a field to hold the BloodData for a Patient. When declaring the field, initialize it by instantiating a BloodData object. Create get and set methods.
• Create a default constructor that sets the ID to “0”, age to 0, blood type of the BloodData object to “O”, and Rh value of the BloodData object to “+”.
• Create an overloaded constructor that accepts the following parameters: ID,age, blood type, and Rh. The constructor should call the set methods for the field associated with each parameter.The PatientBuilder Class.This class should contain the main method from which the program runs. In that method, implement the following functionality:• Ask the user for the ID, age, blood type, and Rh factor of a Patient.
• Create a Patient object, passing all of the data obtained from the user into the object.
• Write the code necessary to display the ID, age, blood type, and Rh factor of the Patient by calling the appropriate get methods of the object.

MY CODE ( which does not compile since it is wrong...)

import java.util.Scanner;
public class PatientBuilder
{
public static void main(String[] args){
String patientID;
int patientAge;
String patientRh;
String patientBlood;

[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

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

Declaring Variable And Using Getter

Jul 2, 2014

I have question on best practice on declaring variable and using getter. Is there any performance issue if I used getter every time to access the properties values or Is better to use getter once, store in variable then use that variable whenever needed.

a) What is the best practice?

b) Also what if getter in deep level e.g. myTopObj.getInnerOne().getInnerTwo().getProp();

Option 1

Java Code:
var myProp = obj.getProp();
x = myProp;
y = myProp mh_sh_highlight_all('java');
Option 2
Java Code: x = obj.getProp();
y = obj.getProp(); mh_sh_highlight_all('java');

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

Creating A Setter Method?

Aug 28, 2014

so here's my code

import java.io.*;
public class Movies {
public String title;
public String director;
public String theme;
public Title(String title)

[code]....

the error is in line 9 which is

public Title(String title)

and the error is (error: invalid method declaration; return type required)

View Replies View Related

Private Var Won't Save Value Of Public Getter Function From Base C

Sep 15, 2014

I'm working on this program for a class to create objects of a commissioned employee and union employee. Everything seems to work ok, but when I run my final pay calculation, one of my getter functions will not pass the variable for the pay into a class specific variable called check. here is the code in this function.

public void finalPayCal_U() {
setweekPay();//calculates weeks pay under 40 hours, stored in getweekpay
check = getweekPay();
if(getHours() > 40){
check = check + (1.5 * (getHours() - 40) * getRateOfPay());
}
check =- Dues;
}
}

The issue lies in check = getweekPay();

I thought this was a legal move, but I can't get it to work. It doesn't come back with anything more than 0 any time I run it.

All of these functions are out of the base class, employee (this function itself lives in the derived union class)

public void setweekPay() {
if (hours <= 40) {
weekPay = hours * rateOfPay;
} else {
weekPay = 40 * rateOfPay;
}
}

When I run, this function works as it returns the value when i print it to test.

however, when I do the part that says check = getWeekPay() above, it doesn't change the check variable. The only thing I have on the check variable is the dues taken out of it at the end, so it ends up being a negative number.

I have a similar problem with the other derived class's check variable. Both classes have the same variable as private but one is check the other checkC.

View Replies View Related

Modify And Use A GUI To Set Variables Setter Methods

Feb 24, 2012

i'm trying to modify and use a GUI to set the variables the setter methods. while the code seems valid to me and should work perfectly, i get ArrayIndexOutOfBounds and StringIndexOutOfBounds and respectively lines 111 and 134. i'm am not the original author of this code, all i want is to get it to work fine.

1package de.kugihan.dictionaryformids.dictdconv;
2
3import java.io.FileOutputStream;
4import java.io.IOException;
5import java.io.OutputStreamWriter;
6

[code]....

View Replies View Related

JSF :: PrimeFaces Calendar Not Calling Setter Method

Nov 24, 2014

I have a PrimeFaces page with a calendar component on it. Radio buttons on that page work fine and call the setter method on the back end. The Calendar however doesn't call the setter. The getter method is called on page display.I'm using the PrimeFaces v 5.0 jar file.

<h:panelGrid columns="4" cellspacing="5">
<p:radioButton id="timeframeOpt10" for="searchTimeframe" itemIndex="10" style="padding-left:30px;"
onchange="document.getElementById('_listenerportlet_WAR_listenerportlet_:articleSearchForm:tabView:timeframeChecked').innerHTML = '(#{i18n['timeframe-specify-dates-label']})';" />
<h:outputLabel value="#{i18n['timeframe-specify-dates-label']}" style="padding-left:10px;" />
<h:panelGrid columns="2" style="align-content:center;">
<p:outputLabel value="#{i18n['timeframe-dates-start-label']}" />
<h:outputText value=" " />
<p:calendar value="#{articleSearchFormBean.timeframeStart}" showOn="button" />
</h:panelGrid>
<h:panelGrid columns="2">

[code].....

View Replies View Related

NullPointer Exception From Calling A Setter In Array Of Objects

Sep 21, 2014

I hope I'm putting this question in the right folder. I have an array of objects, and I have defined a setter for a variable in the object. When I call the setter, I get a NullPointerException. Here is the relevant code for the object.

public class Digit extends Thread {
private int digit;
public void setDigit(int digit) {
this.digit = digit;
}
// run method follows
}

Here is the portion of the main class where I define an array and then call the setter.

Digit[] digits = new Digit[10];
for (int i = 0; i < digits.length; i++) {
digits[i].setDigit(i); // NullPointerException occurs here
}

View Replies View Related

How To Create Public Get And Setter Methods For Private Members Of The Class

Mar 23, 2015

If i have a class(lets say class name is Approval) with the following private members: String recip_id, Int accStat, String pDesc, String startDate How can i create public get and setter methods for these private members of the class?

View Replies View Related

How To Print String Only Five Times

Feb 11, 2015

I can't figure out how to print this string only five times. I tried to use the * operator, but that doesn't work with strings apparently, unles i'm not importing correctly.
 
import java.lang.String;
public class Looparray
{
public static void main(String args[] {
for (String myStr= "Hello there!";;) {
System.out.print (myStr);
System.out.print("
");
}
}
}

View Replies View Related

JSF :: Saving 2 Times One Form

Feb 22, 2014

I'm trying to save to a table in a database that has only 2 fields, (id, nota) . I want to save the data several times just to click on "save" one look . The code that I have is this:

<h:form id="frmPerso" style="font-size: 13px;">
<h:outputText value="Id 1" />
<h:inputText value="#{vistaEjem.notas.id}" />
<h:outputText value="Nota 1 " />
<h:inputText value="#{vistaEjem.notas.nota}" />

[Code] ....

I was told to use a foreach or for the insertDatos, but not as used..

View Replies View Related

How To Find The Best Time Of 14 Run Times

Oct 19, 2014

I have this code that prints the run time for each for loop iteration but how do I find the fastest time store it in a variable and the print that variable at the end? This is what I have currently.

for (int i = 1; i <= 14; i++) {
int n = (int) Math.pow(2, i);
int[] list = new int[n];
for (int j = 0; j < list.length; j++) {
list[j] = (int) (Math.random() * 2000);
}
int length = list.length;
double radixTime = radixSort(list, length);
System.out.println("For base " + i + " the time was " + radixTime);
}

View Replies View Related

How To Put Values In FloatBuffer At Different Times

Mar 17, 2014

I have to put values in a FloatBuffer at different times. How can I ensure that I put the current value in the lowest free position, that is, the values be in a row, not spaced and of course not overwritten. I guess I have to use buffer.position() but how? I've never used buffers before.

View Replies View Related

How To Make A Program Run Multiple Times

May 18, 2014

I have made a basic math game that asks you questions and tells you if you have answered them correctly or incorrectly. The game runs great! The thing is that it asks you a question one time and after you answer you have to run the program again. I want to get the program to ask ten questions. After that I want to figure out a scoring system for it but the first step is to get it to ask my ten questions. Here is my code.

package pkgnew;
import java.util.Scanner;
import java.util.Random;
public class New {
public static void main(String args[]) {

[Code] .....

View Replies View Related

If Condition Matches Multiple Times

Feb 16, 2015

I'm working on a problem that requires me to generator all possible word combinations based on a 7-digit number as input. Many of the generated "words" will be nonsense, but some with be "NEWCARS", "TAKEOUT", etc... This problem mimics the phone number a company would use to support clients remember that number.

I completed the exercise, but I would like to explore more elegant solutions. Specifically, I've used an IF-THEN-ELSE condition inside of a FOR loop. Here is my working code:

package com.johnny_v.exercises.telephone;
public class WordGenerator {
public static void main(String[] args) {
int numOfTimes = 2187;
String two = "ABC";
String three = "DEF";
String four = "GHI";

[code].....

I receive StringIndexOutOfBoundsException exceptions. I it's because multiple conditions are matched. For example, the indexSix is reset to 0 when row is a multiple of 9. Because row is also a multiple of 3, this condition also executes and then increments "indexSix".

View Replies View Related

Check How Many Times Char Is Used In The String

Apr 1, 2014

I tried to make a program that takes a string str, and char a and checks how many times the char is used in the string.

Example: the string Welcome and the letter e, is 2 times. so the program should print 2.

It compiles but when I run it and enter the information, i cannot get the printing line out.

Heres my code:

import java.util.Scanner;
class program
{
public static void main(String[] args) {
Scanner user_input=new Scanner(System.in);
String str;
String b;
System.out.print("Please enter a word");

[Code] .....

View Replies View Related

Servlets :: DoGet Executes 2 Times

Jan 28, 2015

I created a new servlet to download a pdf-file from a unix-server and display it in an iFrame. The servlet gets called, downloads the pdf, throws away the session parameters and then... starts over again. The session parameters aren't there anymore and the servlet returns an error. The strangest thing is, in our development environment the thing works.

web.xml
<servlet>
<servlet-name>iframeservlet</servlet-name>
<servlet-class>Enviro.DownloadIframeContent</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>iframeservlet</servlet-name>
<url-pattern>/jsp/servlet/iframeContent.pdf</url-pattern>
</servlet-mapping>

[code]....

View Replies View Related

Counting How Many Times A Value Appears In Array

Nov 23, 2014

I have this code but I can't seem to get it to work. It keeps saying that "count" cat be found and that it cannot return a value whose type is void.

Java Code: public class Cuantos {
static int getPosition(double listOfValues[], double targetValue ) {
int i,count,
position = -1;
for (i=0; i < listOfValues.length; i++) {
if (listOfValues[i] == targetValue)

[code]....

View Replies View Related

Hot To Get A Swing Timer To Update At Different Times

Apr 27, 2014

I'm working on a space invades game and I have a swing timer set up to update the score(number of aliens killed) and for the aliens to shoot. I'm trying to get the score to update at say 100 ms, but the aliens to shoot at 3200ms. I tried to use 2 timers one for the aliens, and one for the score,but the aliens would just use faster score timer.

import java.awt.Color;
import java.awt.Container;
import java.awt.event.ActionEvent;

[Code]......

View Replies View Related

Check How Many Times Char Is Used In String

Apr 1, 2014

I tried to make a program that takes a string str, and char a and checks how many times the char is used in the string. Example: the string Welcome and the letter e, is 2 times. so the program should print 2. It compiles but when I run it and enter the information, i cannot get the printing line out.

Heres my code:

import java.util.Scanner;
class program
{
public static void main(String[] args) {
Scanner user_input=new Scanner(System.in);
String str;
String b;
System.out.print("Please enter a word");
str=user_input.next();

[Code] ....

View Replies View Related

Making A Loop Go A Certain Amount Of Times?

Jun 14, 2014

I am having is not being able to print out the diamond the amount of times the user enters (for example, when it asks how many diamonds, I enter a 2 and only one diamond comes out.)

import java.util.Scanner;
public class Pattern5
{
public static void main(String[] args)
{
// For this pattern program, ask the user how many diamonds
// she would like to print to the screen. The following pattern is one diamond.

[code]...

View Replies View Related







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