Creating Object Oriented TBG

Jun 9, 2014

I'm really new to object oriented coding. A good way to create a Text Based Game that used objects as rooms, and items. However, I can't figure out what the best way to define and use rooms and items would be. I've been at it for the past few days, and just can't think of something that works well and is easy to use.

I want to have each room have it's own "inventory" of items that the player can pickup, as well as drop items into. I want items that are dropped to maintain their properties (durability, level, ect). I would also need several methods for things like getting an item from a room by the item's display name or id. For instance, if there is a room with a Broken Iron Sword, and a Stone Dagger, I'd need to be able to get the Broken Iron Sword object with the string "Broken Iron Sword".

View Replies


ADVERTISEMENT

Object Oriented Sentinel Program Won't Work

Nov 28, 2014

I am working on this object oriented sentinel problem but when i am running it, its showing error.

import java.util.Scanner;
public class example1 {
private String gasmilage;
public example1(String milage){
milage=gasmilage;

[code]....

View Replies View Related

Import From File Using Object Oriented Programming

Apr 12, 2013

How to import data from a file using Object Oriented Programing? I know how to write OOP Java and I know how to read data from a file in Procedural Java but would like to know more about how to do it OOP. Is it the same as reading data process as in Procedural programming?

View Replies View Related

Checkerboard Using 2D Arrays And Object Oriented Programming In BlueJ

Apr 23, 2014

Driver:

*initiating theGrid[][]*
public Zhang()
{
con.setLayout(new FlowLayout());
for (int xDimension = 0; xDimension<theGrid.length; xDimension++)

[Code] ....

All I'm getting as a blank screen and I've searched for what to put into object oriented code to make the image show up how to program using 2d arrays. I don't get any error messages (which is good I suppose) but how to make the image show up because I have stuff under the graphics and draw methods, did I do something wrong where initializing the array?

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

What Does Creating ArrayList Object In A Constructor Mean

Mar 22, 2014

import java.util.ArrayList;
public class LectureRoom{
private String courseName;
private String roomNumber;
private String Lecturer;
private ArrayList <Student> studentList;

[Code] .....

Question:

Given the following BlueJ class diagram

Lecturer class (same with previous lab, no changes needed)
Student class (same with previous lab, no changes needed)

LectureRoom (changes occurs here)

1. LectureRoom has roomNumber (e.g. A301), courseName (e.g. Java), lecturer (a reference to a Lecturer object), and studentList (a reference to an ArrayList that stores Student object).
2. LectureRoom has a constructor that receives courseName, roomNumber, and Lecturer. The constructor then sets/assign the courseName, roomNumber and Lecturer. This constructor also creates the studentList arraylist object.

View Replies View Related

How To Prevent Java From Creating Object

Mar 6, 2014

I just want to ask about a kind inheritance.Let say I have an interface MachineCode.I also have different classes, Binary, Hex and Octal that implements MachineCode

Question: How can I prevent java to create an Object like this:

Binary bin = new Binary();
Hex hex = new Hex();
Octal octal = new Octal();

those declaration above must be compile error,

I want to create Objects of Binary, Hex, and Octal this way:
MachineCode bin = new Binary();
MachineCode hex = new Hex();
MachineCode octal = new Octal();

View Replies View Related

Super Constructor Call - Creating Object

Sep 18, 2014

Its written that every constructor calls its super class constructor. And we know, constructors are called to create an object. Does it mean that if I am creating an object of a class, I am actually creating objects of all its super class???

View Replies View Related

Linked Binary Search Tree - Creating Node Object

Apr 5, 2015

I'm trying to use LinkedBinarySearchTree but a lot of the variables are protected in BinaryTreeNode. I am creating a BinaryTreeNode object but it still isn't allowing me to use them. The variables I am trying to use are element, left, and right.

import ch11.exceptions.*;
import ch10.LinkedBinaryTree;
import ch10.BinaryTreeNode;
/**
* LinkedBinarySearchTree implements the BinarySearchTreeADT interface with links.

*/
public class LinkedBinarySearchTree<T> extends LinkedBinaryTree<T>
implements BinarySearchTreeADT<T>

[Code] ....

View Replies View Related

Timestamps And Time Zones (DB2 Oriented But May Apply To Other Databases As Well)

Dec 15, 2014

If you store a Timestamp in a database (in my case, I'm looking at DB2), doesn't something on the back end convert it to UTC?  And then when you read it back out, it gets converted to the local time zone?  How does this happen?
 
Lets say you are using a computer in one time zone, but the database is running on a server in another time zone.  What conversions take place upon storage and then retrieval?
 
And here is where it gets a little more Java specific. Using a PreparedStatement or a ResultSet, you can change the time zone when setting and retrieving a Timestamp.
 
Example:
Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
ps.setTimestamp(2, timestamp, calendar);
 
And you can read it out from a ResultSet in a similar fashion.
 
However, isn't using such methods technically wrong?  If the database is trying to store your instant in time accurately, doesn't specifying a Calendar other than the one in your local time zone cause the database to actually store an incorrect instant in time?
 
So I need to read Timestamps from a database, and I've been told they are stored as GMT.  This has caused me great confusion.  I think what I need to do is just read it out from the result set using a Calendar set for GMT timezone. 

View Replies View Related

Creating Menu Using Java - Animating Drawn Object On Button Click

Nov 7, 2014

i would like to create a menu like below where if i clicked on "DRAW", a frame to draw will appear and when i clicked on animate, I can animate an object drawn. I tried on using JButton, but I donno how to customize the design n so I would like to know is there other ways so tat my menu will appear as below?

View Replies View Related

Swing/AWT/SWT :: BorderLayout - Adding Multiple Video Game Oriented Objects Such As Sprites To JFrame?

May 24, 2014

I decided to write a small Java program to experiment around with BorderLayout, because I'm developing a Java game and I need to have 2 objects placed in a single JFrame at the same time, and everyone I asked said I need BorderLayout to do that.Before you answer: Also, is using BorderLayout the best option for adding multiple video game oriented objects such a sprites to a JFrame?

So the Java program I wrote is supposed to place a JButton on the JFrame and ALSO place a graphic component (a rectangle in this case). The problem is, only the button shows up, as can be seen in the image link below: URL....

Here is the code:

**main.java** --> The main method class + JFrame/JPanel/JButton constructor
import java.awt.BorderLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class main {

[code]....

View Replies View Related

Read Text File Into Object Array And Creating Random Access File

Dec 8, 2014

I am working on a project that requires me to build a database with random access file, representing products, the base product contains a name (about 30 characters), a price (double), and a quantity (integer). I have worked on this project for probably 15+ hours and have tried so many things and feel like I've barley made any progress...

The part i am really struggling with is taking the data from the text file and creating an object array with it using the product class. Once ive accomplished that, i have to use that data to create a random access file with the data.

Here is the base Product class that must be used to create the objects for the array.

public class Product
{
public String pName;
public String stringName;
public double price;
public int quanity;

[Code] .....

And then here is the data from the text file that i must extract to use to create product objects.

Dill Seed,938,34
Mustard Seed,100,64
Coriander Powder,924,18
Turmeric,836,80
Cinnamon (Ground Korintje),951,10
Cinnamon (Ground) Xtra Hi Oil (2x),614,31
Cinnamon (Ground) High Oil (1X),682,19

These continue for about 40-50 entries, they are not separated by a blank line though i had to add those so it would display correctly, each entry is on its own line with name separated with spaces, then price after a comma, then quantity after the second comma.....

View Replies View Related

Reading Text File Into Object Array And Creating Random Access File?

Dec 8, 2014

I am working on a project that requires me to build a database with random access file, representing products, the base product contains a name (about 30 characters), a price (double), and a quantity (integer). I have worked on this project for probably 15+ hours and have tried so many things and feel like I've barley made any progress...

The part i am really struggling with is taking the data from the text file and creating an object array with it using the product class. Once ive accomplished that, i have to use that data to create a random access file with the data.

Here is the base Product class that must be used to create the objects for the array.

public class Product
{
public String pName;
public String stringName;
public double price;
public int quanity;
//Constructor
public Product( String pName, double price, int quanity )

[code]....

and then here is the data from the text file that i must extract to use to create product objects.

Dill Seed,938,34

Mustard Seed,100,64

Coriander Powder,924,18

Turmeric,836,80

Cinnamon (Ground Korintje),951,10

Cinnamon (Ground) Xtra Hi Oil (2x),614,31

Cinnamon (Ground) High Oil (1X),682,19

these continue for about 40-50 entries, they are not separated by a blank line though i had to add those so it would display correctly, each entry is on its own line with name separated with spaces, then price after a comma, then quanity after the second comma.....

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

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 View Related

Equals Method - Take Object Reference And Return True If Given Object Equals This Object

Mar 28, 2014

Create an equals method that takes an object reference and returns true if the given object equals this object.

Hint: You'll need 'instanceof' and cast to a (Geocache)

So far I have:

public boolean equals(Object O){
if(O instanceof Geocache){
Geocache j=(Geocache) O;
if (this.equals(j)) //I know this is wrong... but I can't figure it out
return true;
}

else return false;
}

I think I have it correct up to the casting but I don't understand what I'm suppose to do with the this.equals(). Also I'm getting an error that I'm not returning a boolean... I get this all the time in other problems. I don't get why since I have to instances of returning booleans in this. "returns true if the given object equals this object" makes no sense to me. I assume the given object, in my case, is 'O'. What is 'this' object referring to?

View Replies View Related

Get Object Strings To Print In List So That User Can Select That Object To Manipulate Its Attributes

Oct 7, 2014

I am new to Java and have read books, the Java docs, and searched the Internet for my problem to no avail. I have an Array of objects that contains strings. How can I get the object's strings to print in a list so that the user can select that object to manipulate its attributes? For example, the user can select "Guitar 1" from a list and manipulate its attributes like tuning it, playing it, etc. I have a class called Instruments and created 10 guitar objects.Here is the code:

Instrument [] guitar = new Instrument[10];
for (int i = 0; i < 10; i++) {
guitar[0] = new Instrument("Guitar 1");
guitar[1] = new Instrument("Guitar 2");
guitar[2] = new Instrument("Guitar 3");
guitar[3] = new Instrument("Guitar 4");
guitar[4] = new Instrument("Guitar 5");
guitar[5] = new Instrument("Guitar 6");

[code]...

View Replies View Related

Swing/AWT/SWT :: How To Move A Object And Make Object Shot Laser

Mar 27, 2015

can a keyevent in java make the space ship and the laser too ?

View Replies View Related

Inheritance Relationship Between Type Of Actual Object And Object Reference?

Apr 15, 2014

For example I create an object like this:

BankAccount b = new SavingsAccount();

Now lets say that I want to access a method 'addInterest()' that is in the 'SavingsAccount' class I would have to do: '((SavingsAccount)s).addInterest();'

The question I have is why do I have to cast 'b' to SavingsAccount? Isn't the actual object reference of 'b' already an instance of 'SavingsAccount' class? How does the 'BankAccount' affect the object itself? I'm really confused as to what class is truly getting instantiated and how BankAccount and SavingsAccount are both functioning to make the object 'b'.

View Replies View Related

Object Reference Variable Unwilling To Be Reset To A Different Object Type

Nov 6, 2014

I don't understand why the object reference variable 'a' cannot be recast from a thisA object reference to a thisB object reference.Is it the case that once a reference variable is linked to a particular object type then it cannot switch object types later on.I am facing the Java Associate Developer exam soon and I am just clearing up some issues in my head around object reference variable assignment,

class thisA {}
class thisB extends thisA { String testString = "test";}
public class CastQuestion2 {
public static void main(String[] args) {
thisA a = new thisA();
thisB b = new thisB();

[code]....

View Replies View Related

Type In A Name And It Will Search Through Each Object And Print Back Corresponding Object Info

Nov 19, 2014

I am trying to get this to where I can type in a name and it will search through each object and print back the corresponding object info.

Java Code:

import java.util.Scanner;
public class MyPeople {
public static void main(String[] args) {
Person[] p = new Person[] {
new Person("Chris", 26, "Male", "NJ", "Single"),
new Person("JoAnna", 23, "Female", "NJ", "Single"),
new Person("Dana", 24, "Female", "NJ", "Single"),
new Person("Dan", 25, "Male", "NJ", "Single"),
new Person("Mike", 31, "Male", "NJ", "Married") };

[code]....

View Replies View Related

Create Object Deriving From PrintingClass And Use That Object To Print Text

Apr 9, 2014

Task:The main method of the class Things below creates an object called printer deriving from the class PrintingClass and uses that object to print text. Your task is to write the PrintingClass class.

Program to complete:
import java.util.Scanner;
public class Things {
public static void main(String args[]) {
String characterString;
Scanner reader = new Scanner(System.in);
PrintingClass printer = new PrintingClass();
System.out.print("Type in the character string for printing: ");
characterString = reader.nextLine();
printer.Print(characterString);
}
}

// Write the missing class here

Note: In this exercise the solution is part of a conversion unit where many classes have been declared. Because of this the classes are not declared as public using the public attribute.

Example output

Type in the character string for printing: John Doe

John Doe

My Class:
class PrintingClass {
public void print(){
System.out.println(characterString);
}
}

View Replies View Related

Display Properties Of Each Object Instead Of Object Array List Itself?

Mar 23, 2015

If I set a Jlist to contain an array of objects, how can I display properties of each object instead of the object array list itself. Ex:

Instead of:

Person1
Person2
Person3

display values such as each person name within the Jlist:

Mike
Paul
Andrew

View Replies View Related

Searching For Object In Linked List Then Removing The Object

Nov 19, 2014

I have just started working with linked lists. I have a linked list of Objects and I want to be able to search for a specific object. But currently my code continues to return false. Also how would I go about removing the first index of the linked list.

public static void main(String[] args) {
LinkedList<Cookies> ml = new LinkedList<>();
int choice = 0;
while (choice >= 0) {
choice = menu();

[Code] ....

View Replies View Related

Practical Use Of Multiple Object References Pointing To Same Object

Dec 27, 2014

I am reading Head First: Java and got to Object References. In the book I got a little bit confused on what happens when two object reference's point at the same object so I wrote a small crude test, the below code. This of course clarified what happens but what I am interested in knowing is in what circumstances would you want to have two separate references for the same object when you could just use the original? Eg. v1

class ObjectValue{
int objVal = 1;
}
class ObjectValueTestDrive{
public static void main(String [] args){
// "Value of v# should be" refers to if it copied the given object values, instead of referencing the same object
ObjectValue v1 = new ObjectValue();
System.out.println("Value of v1 should be 1:" + " "+ v1.objVal);

[code]....

View Replies View Related







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