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


ADVERTISEMENT

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

Using Sentinel Value To End A Program?

Mar 24, 2014

So the question asks us to use a sentinel value to end a program, but the sentinel value is 999, but the while loop only recognises strings...
 
static Scanner console = new Scanner (System.in);
public static void main (String[] args)
throws FileNotFoundException 
{
PrintWriter outfFile = new PrintWriter ("Invoice.txt") ;
String firstItem;
String item ;
int price;

[Code] .....

View Replies View Related

How To Use CTRL-D To Terminate Program (sentinel Value)

Mar 1, 2014

how to use the CTRL-D in my program. The program records the amount of times a positive and negative integer is typed. When the user decides to end the program, they will use the CTRL-D to terminate the program. After the button combination has been pressed, I spit out to the user the results. The problem is when I press CTRL-D the program just terminates and I can't even get it to read the next line of code. ....

View Replies View Related

Program Not Recognizing String Sentinel?

Jun 10, 2014

I'm new to Java and am trying to create a simple payroll program that uses a while loop to repeat until the user enters "Stop" for the employee's name. I've tried everything I can think of and everything others have suggested and for some reason, I cannot get the program to differentiate between the word "Stop" or any other word. what I'm doing wrong? My code is as follows:

import java.util.Scanner; // imports scanner class for user input
public class Payrolltest {
public static void main( String[] args )// begins execution of program {
Scanner input = new Scanner( System.in ); // creates a scanner to obtain user input
String Employee = "name"; // employee's name

[code]...

View Replies View Related

Java Program That Will Ask A User To Input Grades Until User Inputs Sentinel Value

Apr 9, 2014

Write a java program that will ask a user to input grades until the user inputs the sentinel value -1. The program should test each input to determine whether 0<=grade<=100. If the grade entered is within this range, the program should print "Grade accepted;" if not, the program should print "Invalid input".

View Replies View Related

How To Get A Compound Interest Program To Work

Apr 10, 2014

/code

package com.eclipsedistilled.cis125;
import java.util.Scanner;
public class HowellBank {
public static void main(String[] args) {
//Written by George Torgerson
//Chapter 4 Link to Logic 7
//Program that accepts an account number, the account owner's first
//Declarations
int accountNumber;

[code]....

This is for college homework. Fictional bank. I would like the year to look like Year 1, Year 2, etc.

View Replies View Related

How To Make Hangman Program Work For Phrases With More Than One Word

Apr 13, 2015

I created the following hangman program, but it only works for one word file inputs. How can I modify the program to make it work for files with a multiple word phrase?

/**This program is a basic Hangman game. It takes a word or phrase from a file, and then asks the user to guess the letters in it. The program ends when the user inputs 8 wrong guesses.
*/

import java.util.Scanner;
import java.io.*;
 public class hangman{
public static void main (String[] args) throws FileNotFoundException{
  Scanner kb = new Scanner(System.in);
  String guess;

[Code] ....

View Replies View Related

Average Of Numbers With Sentinel Value Equals To 0

Mar 27, 2014

(Count positive and negative numbers and compute the average of numbers). Write a program that reads an unspecified number of integers, determines how many positive and negative values have been read, and computes the total and average of the input values (not counting zeros). Your program ends with the input 0. Display the average as a floating-point number.

I moved the different boolean statements around, but I'm not getting the sentinel value to end the run. It continues to let me add integers endlessly. The code I wrote is below:

package exerciseFourOne;
import java.util.Scanner;
public class AverageOfIntergers {
public static void main(String[] args) {
// TODO Auto-generated method stub
int positive = 0; // number of positive integers
int negative = 0; // number of negative integers
int sum = 0; // value of sum of integers

[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

While Loop With Two Sentinel Values Is Terminating Early

Sep 25, 2014

The program is supposed to print all even and odd numbers between 50 and 100 using ONE while or do while loop. The evens work, but the program terminates after printing 51 for the odds, which doesn't satisfy the second value sentinel value for the while loop.

public class EvenOdd {
public static void main(String args[]) {
int x = 50;
int y = 50;
int i = 0;
int j = 0;
System.out.print("Even numbers between 50 and 100: ");

[Code] ....

View Replies View Related

Create A Java Program That Can Read Specific Data Within Csv File To Work Out Averages

Aug 7, 2014

i am fairly new to java but have made a few projects so i do know most aspects that would allow me to complete the task its just i have been stuck at the same place now for 2 days.The project is to create a java program that can read specific data within a csv file to work out the averages etc. The csv file is a database of different weather stats . an example of the first 12 months of the csv file is below..

[CSV FILE]

year ,month,average rainfall etc

1946 15.70.616108.131.5
1946 28.23.56111.871
1946 38.82932.9 102.9
1946 414.16.3029.2 150.5
1946 513.96060.7 143.6

[code]...

I know that once the data is indexed i can than use a double to find the average of the 12 specific pieces of data and so on. once this is complete i should than be able to transfer the data to a simple graph.

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

Make A Java Program That Calls Object Value Initialized

Feb 23, 2014

i have this following codes and im trying to make a java program that calls an object value initialized.

public class TestClass
{
public String name;
public int age;
public void myMessage()
{
System.out.println("Hello I'm" + name + "and i'm" + age + "years old");
}
}

what i want is to put the following codes of the object.. so once i compile and run the project it executes the value of an object from the method i defined above.

TestClass myName = new TestClass();
myName.name = "Jefferson";
myName.age = 18;

my question is, it is possible to declare or define it in the same project? or i need to do this separately?

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