Creating Complicated Objects

Dec 30, 2014

I'm trying to create complex Character objects. Each object has a name, and for each object with the same name, they share some of the same initial data. However, there are also some bits of data that are given to the object when it's created. For example, an "Elephant" always starts out having a weight of 500, but its position is determined when it's created. Any of these values may later be changed during runtime.

class CharacterStaticParameters {
int weight;
int numberOfFeet;
int numberOfEyes;

[code]....

For example, whether I should try to use words other than 'static' and 'dynamic', or a nicer word than 'parameters'?

View Replies


ADVERTISEMENT

Creating Objects From Methods?

Mar 20, 2014

public class demo
{
Public class static void main(String[]args) {
//Creating a variable that will be a reference to the object
Peoples person_one;

[Code] ....

I have assembled this code below that has a void method which will creat a new object. Problem I encounter is that in

Create_object(person_one);

the person_one has an error saying not initialized. I'm jus trying to learn on my own ways here and practice so may know what's wrong with this? I know I can use a return object from methods but what about this approach?

View Replies View Related

Creating Objects From Class

Aug 17, 2014

So I'm still trying to get to grips with Java, and like to understand exactly why I'm doing something, so that I am not just regurgitating the code, If I want to create an object from class "Apples", I would use the following, right?

Apples MyAppleObject = new Apples();

From what I understand, MyAppleObject is the new object name, new -> creates a new instance of it in memory, and Apples() is the onCreate method that is called

So question 1: (just a quick aside question) Can I create an object without calling Apples()? i.e.

Apples MyAppleObject = new;

Question 2: - PARTLY SOLVED - I discovered that (Button) is a way of typecasting, so I understand that line a little better. What I don't understand is why we don't need to initialize the object with "new"

I've now looked at a bit of android development and xml and those declarations are all together different, and I'm not sure why. I haven't found a single explanation for the difference in format.

Java Code:

Button Add;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Add = (Button) findViewById(R.id.button1); mh_sh_highlight_all('java'); So the Button object is declared above the onCreate method, but initialized afterwards I guess....

But instead of using Button Add = new Button() they use Add = (Button) findViewById(R.id.button1);

Question 3:

then In XML they use the following:

Java Code:

public*static*void*main(String[] args){
*********
********// Creates a DOM object in memory. Now you can access
********// data in the xml file
*********
********Document xmlDoc = getDocument("./src/tvshows5.xml"); mh_sh_highlight_all('java');

Once again, why didn't they have to use : Document xmlDoc = new Document()

View Replies View Related

Creating New Objects Within Methods?

Sep 14, 2014

I want to make a program where users are prompted to enter a username and a password and have these two values create a new instance of the Object User. But I'm not sure where to start.

import java.util.Scanner; 
public class Main {
public static void main(String[] args) {
createUser();

[Code] ....

how to take username + password and put it into an object.

View Replies View Related

Why Isn't Constructor A Requirement For Creating Objects

Jun 13, 2014

Java Code:

class GenericQueue<E> {
private LinkedList<E> list = new LinkedList<E>();
public void push(E element) {
list.addFirst(element);
}
public E pull() {
return list.removeLast();

[code]...

Is a constructor required to create an object, if one of its instance or class variables haven't been instantiated? Like private String string;

View Replies View Related

Creating Array Of Objects In Constructor

Mar 16, 2014

I want to create a simple app that takes a name from the console then compares the name to a small phone book,when the name matches another name it will return the associated phone number.

I have a small contacts class which has name and number fields,Then I have a phone book class which populates an array with 4 contact objects that I can compare the entered number against.

here is my contacts class

public class Contact
{
String name;
int number;

[Code].....

In the main method I am just trying to print out one of the fields for one contact to see if I can actually access it to compare it to the name entered.Its saying "MaryJones" cannot be resolved to a type.I'm guessing I cant create all that code in the constructor?

View Replies View Related

JSF :: Creating Primefaces 4.0 Charts From Database Objects

Jul 27, 2014

I'm trying to create a simple bar chart from integer values (measuring number of bulldozers) stored in a mySql DB, in the following schema:

Integer rigId PK;
Integer rigQty;
Date recordDate;
String country FK;

I want to plot the date on the x-axis and quantity on y-axis. I can't seem to find any examples of how to render charts from a database. I just find the generic Primefaces 4.0 examples which uses static data like this:

private void createCategoryModel() { // category chart
categoryModel = new CartesianChartModel();
ChartSeries boys = new ChartSeries();
boys.setLabel("Boys");

[Code] ....

I'm really not sure how to adapt the above to a database method nor have any web searches produced useful examples. I tried something like this, but how to find examples or the type of methods I need to use to create a bar graph from Db values:

@ManagedBean(name = "chartb")
@SessionScoped
public class BarChartBean {
private final Map<Integer, Map<String, Number>> rigNums = new HashMap<>();
// private final Map<Integer, Map<String, Number>> HorasOrcadasPorFunci = new HashMap<>();
private CartesianChartModel cartesianChartModel;

[Code] ....

View Replies View Related

Importing And Creating Objects From The Text Files?

May 25, 2014

I've been trying to write a program for some time now, but im encountering problems while trying to complete it. The program has a student class and a course class (set up with some info about the class, like #, professor name, course title, course time). Now, i have a text file in the workspace, and i have to import the data from the textfile, and thats just what i did, but then there is an option which allows the user to delete a course only by inputing the course number, and when he does that, the program outputs the course's name, and confirms the deletion of the course (From the student's record, i created a vector for that and imported all the courses from the text file). But how can i let the program know what's the name of the course when the user inputs the course number ???

When the data is read from the file, objects should be created and added to the student's course record. <- i think here's where i messed up ? i imported the data, but how can i actually make them objects before adding them into the vector ?

PHP Code:

public static void main(String[] args) throws IOException
{
Scanner scan = new Scanner(System.in);
Vector Record = new Vector();
try {FileReader filereader = new FileReader("CLASSES.txt");
BufferedReader bufferedreader = new BufferedReader(filereader);
String test = "";
while(test != null)
{
Record.addElement(test);
test = bufferedreader.readLine();
} mh_sh_highlight_all('php');

View Replies View Related

Program Like Applet - Creating Multithreading Or Drawing Objects

Aug 20, 2014

What is the best choice to program like an applet i mean easy with creating multithreading or drawing objects etc.

View Replies View Related

Complicated Data Copy

Jun 14, 2014

Disaster has struck some of ACME's redundant data centers. The administrators have managed to restore backups, but some data sets are still missing from some data centers. Fortunately, every data set can be found at least once in one or more of the data centers. However, before ACME can resume normal operations, it needs to ensure that each data center has a copy of every data set.Your goal is to ACME resume normal operations by writing a program to synchronize data sets between data centers using as few copies as possible.

The first line of input will contain an integer between 0 and 999999 inclusive, representing the number of data centers.Following that will be one line of input for each data center. Each line will contain an integer from 0 to 299 representing the number of data sets at that data center, followed by a space and space-separated list of data set ids currently present at that data center. Data set ids are each an integer between 1 and 999999, inclusive. Each line will be at most 999 characters long.Data set ids are not necessarily consecutive. The list of data sets will not be in any particular order.

Output:The program must output an optimal data set copy strategy to ensure that every data center has a copy of every data set. Output one line for every copy instruction.A copy instruction is of the form <data-set-id> <from> <to>, where <data-set-id> is the data set id, <from> is the index of the data center the data set will be copied from (1 = the first data center), and <to> is the index of the data center to copy the data set to.When there are no more copy instructions, the program must output the word "done" on a line by itself. There is often more than one correct output with minimal number of operations for a given input, and any output that satisfies the requirements is valid.

Example 1:
----------
Input:
4
3 1 3 4
3 1 2 3
2 1 3
3 1 4 2
One Possible Correct Output:
2 2 1
4 1 2
2 2 3
4 4 3
3 1 4
done

Example 2:
----------
Input:
2
2 1 2
2 2 1
Output:
done

View Replies View Related

Adding Complicated Selections To Eclipse Link Criteria Builder?

Jan 21, 2015

How to add select case

when to_char(trunc(TO_DATE ('03-APR-2015','DD-MM-YYYY'), 'mm'), 'FMDAY') = 'SUNDAY'
then to_number(to_char(TO_DATE ('03-APR-2015','DD-MM-YYYY'), 'W'))+1
             else ceil((to_char(TO_DATE ('03-APR-2015','DD-MM-YYYY'), 'dd') + 1 - to_char(next_day(trunc(TO_DATE ('03-APR-2015','DD-MM-YYYY'), 'mm'), 'SUNDAY'), 'dd'))/7)+1
        end week_no
from dual
query to Eclipse Link CriteriaBuilder

I am able to add distinct(to_char(sum(datecolumn,number),'W-MM-YYYY')) like
 
                       Expression sum = cb.sum(CriteriaQueryUtils.getPath(rt, breakupFields), cb.literal(miliSecToAdd));
                        Expression<String> literal = cb.literal("W-MM-YYYY");
                        Expression<String> functionselectclause = cb.function("TO_CHAR", String.class, sum,literal);
                        return query.select(functionselectclause ).distinct(true).where(p).orderBy(orders);

But need to know how to add case when else to CriteriaBuilder...

View Replies View Related

Complicated ArrayList Function - Moving Between Fields Which A Player Can Perform Based On Game Rules

May 27, 2014

I have been working on this function and i can't get it to work. It's a little bit complicated so let me first explain what this is about:

1. As a little exam in my studies i have to program a halma console game with KI an stuff.

2. Everything is finished and works except for the Move-Calculation.

3. A Move is a Move from Field a to Field b which a player can perform in one round based on the game rules (Careful: We are not using the standard halma rules, we use different ones).

4. Class Move consists of the Starting Cell where the Figure before the Move stands and a target Cell where the figure will stay on at the Move end. It may include an Array of serveral Cells, the stop cells which the figure passes from start -> target since several jumps can be performed in one Move.

Valid Examples for Moves:

a -> b (From Field a to Field b)
d -> f through g,h,i (From Field d to Field f through the Field g,h,i

My Move Calculation where all possible Moves are calculated for a given figure consists of 2 parts. An expand() function which will generate all possible moves (works perfectly) and a jumpFix() function which isn't working properly.

Example:

After expand() I'm getting something like that:

a -> b
b -> c
c -> d
s -> t

This is however not finished, because the first 3 Moves are actually 1 Move. Because the player can Move from a -> d in one turn because those 3 are consecutive Move. The fixed Move would look like that:

a -> d through b,c

jumpFix() is also perfectly working for that situation, however there is one specific situation when it doesn't work. Let's say we have this situation.

a -> b
b -> c
c -> d
b -> e
e -> f
f -> g
s -> t

Then the only valid jumpFix() output would be:

a -> d through b,c
a -> g through b,e,f
s -> t

However i can not get it to work yet. Note: It definitely needs to be iterative, not rekursive else i would get an StackoverflowError.

This is my current Code of jumpFix():

Java Code:

/**
* Takes a look into all calculated moves and finds those which should be seen as one move, but are still considered to be more than one move (several jumps in one move)
*/

public static List<Move> jumpFix(List<Move> moves) {
Set<Move> result = new HashSet<Move>();
Set<Move> remove = new HashSet<Move>();
int lastSize = -1;
// repeat action until no moves could be merged
while (lastSize != remove.size()) {

[Code] ....

How to implement the special case where a Move splits into 2 or more branches and jumpFix() able to handle this case.

View Replies View Related

Copying Data Objects To Serializable Objects

Jul 27, 2014

I am currently working on a project where I need to return data from a database over RMI to a client who requests it. Some of the fields in the Data Object can not be seen by the client so I need to create another object to send over the network instead. The method I use is this...

public static SerializableObject createSerializableObjectFromDataObject(DataObject dataObject){
SerializableObject serializableObject = new SerializableObject();
serializableObject.setField(dataObject.getField());
serializableObject.setAnotherField(dataObject.getAnotherField());
return serializableObject;
}

Is there a better way of doing this? I am creating many subclasses DataObject which all require this static method to be implemented and I can't push it into the superclass because each one needs custom behaviour.

View Replies View Related

How String Objects Are Different From Other Objects

Jan 23, 2015

how String objects are different from other objects

part 1:

// creating two objects
Dog mydog1 = new Dog();
Dog mydog2 = new Dog();
// comparing the reference variables
if( mydog1 == mydog2){
System.out.println(" The reference variables refer the same object ");
}
else {
System.out.println(" They refer to different objects ");
}

The above code works as I understand objects , it prints "They refer to different objects " to the screen.

Part - 2

// creating two objects ( I beleive, pls correct me if i am wrong )
String a = "haai";
String b = "haai";
 
if( a == b){
System.out.println(" Reference variables refer to same object");

When i run the above code it prints that a and b refer same object , I don't understand how they refer to same object when i didn't assign " String b = a; ". My question is did java just create one object and stored the same reference values to a and b .

View Replies View Related

Best Way Of Creating Forms

Jun 8, 2014

Im creating a program that has about 20 different input forms. Fairly standard forms but what i need to know whats the easiest way of creating forms. Is there some way of using templates or some plugin to quickly generate forms.

View Replies View Related

Creating A 4x4 Gird

Feb 6, 2015

I am having trouble developing a 4x4 grid that has the letters A-Z and a-z and the corresponding ASCII numbers for each letter. I have created the code to retrieve these letters and their corresponding ASCII numbers, I only am having trouble with creating the grid and displaying these numbers and letters in their separate 4x4 grids: one grid for (a-z), one grid for (A-Z), one grid for (ASCII# a-z), one grid for (ASCII# A-Z).

Java Code: // Constants Declaration Section
//*******************************
public static void main(String[] args)
{
// Variables Declaration Section
//******************************

[code]...

View Replies View Related

Creating A Map With Stocks

Dec 9, 2014

Empty the following csv table to a map, where the key is a calendar, and the value is arraylist. The table represents the sock values of Google fro a period of time.

"Date,Open,High,Low,Close,Volume,Adj Close
12/8/2014,527.13,531,523.79,526.98,2323000,526.98
12/5/2014,531,532.89,524.28,525.26,2552700,525.26
12/4/2014,531.16,537.34,528.59,537.31,1388300,537.31
12/3/2014,531.44,536,529.26,531.32,1274500,531.32
12/2/2014,533.51,535.5,529.8,533.75,1521600,533.75

[Code] ....

-----------------------------------------------
import java.util.*;
public class Mymap {
public static void main(String[] args) {
Map<String,List<String>> map=
new HashMap<String, List<String>>();
map.put());

Code] ....

View Replies View Related

Creating A Table

Feb 17, 2015

creating a table, and this is the code that I go down so far:

import java.util.Scanner;
public class program1 {
public static void main(String[] args)
{
String heading1 = "Quiz 1";
String heading2 = "Quiz 2";
String heading3 = "Test 1";

[code]...

View Replies View Related

Creating A Web Service

Jul 23, 2014

I'm new to Web Services and I've been finding trouble when creating my first one. Before talking about the problem, I'd like to show you the process I followed to see if it's ok. Note that I'm using Eclipse Kepler, Tomcat 5.5 and Axis2.

1- I created a new Dynamic Web Project.

2- I created the Java class that implements the service with just one method, a simple one: you pass it a name and it returns "Hi, <name>"

3- Right click over that class and then: Web Services -> Create Web Service

4- I go through the next steps. On the last one, I select "Launch the Web Services Explorer to publish this Web service to a UDDI Registry". Click on "Finish".

5- The Web Services Explorer is launched, but I just get a "HTTP ERROR: 500" message.

I understand that my Web Service wasn't published and therefore it's useless to create a client as it wouldn't connect.

View Replies View Related

Update XML Using DOM Objects

Sep 29, 2014

I have a requirement to insert the data into xml file . I have used DOM class for doing this. Below is my xml file

<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>
<deployments>
<applications>
<application>
<name> PCMH</name>

[Code] ....

The thing is if SITA is the name then I have to insert component to the particular envi tabs , if DEVB is the component I have to insert the component there. How can I do this I have done some code its inserting the data at the bottom og the XML .

View Replies View Related

How To Get Two Classes To Get Objects From Each Other

Oct 18, 2014

I'm quite new to Java. I have some trouble with understanding how to get two classes to get objects from each other (if that is the correct term).

Lets say I have a login class, in which I have a method checking what the user has entered into the console (I have not displayed the whole code, but this class works as it should and give the user an option to enter username and password and return it true if entered correct).

public static boolean validateUserPass(String userName, String password) {
String[] user = {"admin"};
String[] passwords = {"firkanten"};
boolean check = false;
for (int i = 0; i < user.length; i++) {
if (userName.equals(user[i])) {
if (password.equals(passwords[i])) {
check = true;

Now, in another class I want a display box to appear on the screen and give the user three options: Click yes, no or cancel. I get this to run perfectly alone, this is not the hard part for me. I want the display box only to appear when the correct username and password is given, but I can't seem to figure out how to do this probably.

View Replies View Related

Getting Names Of Objects?

Jan 22, 2015

In my project I had to create 2 classes, Room and Animal.

Room had to have an array (NOT arrayList-I know theyre better and easier but I need to use an array, for now) This array must be able to be populated by 10 "Animals", and the Room class needs two methods, a method to add animal a to the room (rooms array) and a toString() that returns the name of the room and the names of the animals in the room. The teacher added a hint saying that this toString() should reference the animal classes toString()

Here is my code thus far:

public class Room {
private String name;
Animal[] inRoom = new Animal[10];
public Room(String roomName){
name = roomName;
} public void addAnimal(Animal a){
for(int i = 0; i < 10; i++){

[code].....

View Replies View Related

XML Editing Using DOM Objects?

Sep 29, 2014

I have a requirement to insert the data into xml file . I have used DOM class for doing this.

Below is my xml file

<code>
-<deployments>
-<applications>
-<application>
<name> PCMH</name>
-<envs>
-<env>
<name> DEVA</name>
<version>1.0.0 </version>

[code]....

The thing is if SITA is the name then I have to insert component to the particular envi tabs , if DEVB is the component I have to insert the component there. How can I do this I have done some code its inserting the data at the bottom og the XML.

View Replies View Related

Objects Being Displayed On Top Of One Another?

Dec 15, 2014

I am making a game in java and for the game board i want to fill the screen with blocks. to do this i stored objects of a class that displays squares into an array list and displayed the array list. however, when i do this all of the squares are drawn on top of anther at the final squares coordinates and i dont know why.

here is the code

// code for adding the squares into the array
nt x = 0;
int y = 0;
int size = 10;
static ArrayList<Map> map = new ArrayList<Map>();
//static ArrayList<Items> items = new ArrayList<Items>();

[code]....

View Replies View Related

Can't Create New Die Objects?

Apr 2, 2015

I'm having trouble creating two new die objects for the PairofDie class. I'm trying to run two separate die and print the face value and then add both numbers up and print those values as well.
 
public class Die {
private final int MAX = 6;
private int faceValue;
//private int faceValue2;
public Die(){
faceValue = 1;
 
[Code] .....

Exception in thread "main" java.lang.Error: Unresolved compilation problems:

The method Die() is undefined for the type PairofDice
The method Die() is undefined for the type PairofDice
at PairofDice.main(PairofDice.java:6)

View Replies View Related

Iterate Through Objects

Feb 27, 2015

I would like to know how I can iterate through objects . I have a manually created linked list (without using the built-in method one). So in the memory my object looks like this(attachment).I would like to do a for loop or while loop to get each element under the test3.head.

View Replies View Related







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