Can't Create Balloon Objects

Jan 26, 2014

I keep getting this as a result:

Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - Erroneous tree type: myprojects.Balloon
at myprojects.BalloonTester.main(BalloonTester.java:1 8)
Java Result: 1

View Replies


ADVERTISEMENT

Can't Create Balloon Objects

Jan 26, 2014

Our instructor gave us a list of steps to complete after creating a Balloon, but I can't get past just creating it. Search results have brought up other Balloon thread, however I couldn't find a topic about issues just creating the balloon.

package myprojects;
 ublic class BalloonTester
{
public static void main(String[] args)
{
Balloon redBalloon = new Balloon("Red Balloon", 100);

[code]....

View Replies View Related

Create A Balloon Object In Java

Sep 19, 2014

Programming Assignment #2

(Using an Existing Class: Creating Objects and Calling Accessor and Mutator Methods)

I. The Assignment

This assignment is to write a "test" class (aka: a "driver" class or "client code") that uses the class Balloon.java, available on the class web page.

To use the Balloon class, download it and store it in the src folder of your NetBeans project. Make sure you save it as Balloon.java.

The best way to learn how to use the Balloon class or any other Java class, for that matter - is to consult the documentation, Balloon.html (online). You can also read the javadoc comments that appear just above the class declaration and above each method declaration, which explain what each method does, what the method's parameters are, and what value if any - is returned by the method. The html support pages are generated from these comments.

-Review declaring variables, creating objects, calling methods that return a value vs. void methods, and accessor and mutator methods before beginning. To receive credit for this assignment, you must not modify the Balloon class in any way!

II. Your BalloonTester Class

Your BalloonTester class will have only a single method "main" and will perform each of the following operations, in the exact order listed below. Each operation may be done in one or two statements. Make sure you follow directions faithfully, and note that once you have done step 3, you can copy and paste it to do steps 6, 9, and 12.

1.Create a Balloon object with a name of your own choosing and an altitude of 100 meters.

2.Create a second Balloon object with a name of your own choosing, and specify an initial altitude of -100 meters.

3.Call the accessor methods of the Balloon class to get the name and altitude of each Balloon object. Print the data, one object per line.

4.Make the object you created in step 1 ascend to an altitude of 250 meters.

5.Call the adjustAltitude method to increase the altitude of the object you created in step 2 by 150 meters.

6.Call the accessor methods of the Balloon class to get the name and altitude of each object. Print the data, one object per line.

7.Call the adjustAltitude method to decrease the altitude of the object you created in step 1 by 150 meters.

8.Make the object you created in step 2 descend to the same altitude as the other object. You may assume that the other object is at a lower altitude.

To get credit for step 8., the statement(s) you write must always work, regardless of the actual altitude of the second object. It cannot depend on you knowing the altitude of the second object, but must utilize the fact that the object knows its own altitude. In other words, if you use a literal in any way to set the altitude, it is not correct.

9.Call the accessor methods to get the name and altitude of each object. Print the data, one object per line.

10.Move the object you created in step 1 to an altitude that is four times its current altitude. As in step 8, the statement(s) you write must work for any altitude and may not depend on you figuring out the new altitude beforehand.

11.Attempt to move the object you created in step 2 to an altitude that is 150 meters below its current altitude.

12.Call the accessor methods to get the name and altitude of each object. Print the data, one object per line.

and this is the Balloon.java given:

// File: Balloon2.java
 // Modified Balloon class has overloaded constructors
 
/**
* A class to represent a hot-air balloon. Balloon objects have a name and an altitude.
*/
public class Balloon2
{
// instance variables
private String name ; // name of the balloon
private int altitude; // altitude (height) of balloon in meters
 
[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

Write Tester To Get Current Volume Of Balloon That Starts With A Radius Of 0

Oct 8, 2014

I am supposed to write a Tester to get the current volume of a balloon that starts with a radius of 0 after it is inflated.This is the balloon:

public class Balloon
{
 
private double savedRadius;//instance variable
 
/**constructor!!
Constructs a balloon with a radius
*/
}

[code]....

View Replies View Related

How To Create Objects In A Loop

Feb 12, 2014

Is it possible to use a loop to create objects? I'm trying to put together a program (just as a way of learning) to run a horse race.

What I'd like to is have the user enter the number of horses they want in the race, and then create the objects as the user enters the various attributes of the horse (at least the horse's name), and then once all the instance variables have been set, create the first horse object and then move on to the second one, etc, until all the horse objects have been created.

I know I can't use something like a for loop to do it, so how would the code be writte

View Replies View Related

Create A Static Array Of Objects In Java?

Jan 2, 2014

Im looking for a means to store groups of static data..

so I understand these simple string arrays...

Java Code:

private static String[] names = new String[] {
"aidanmack",
"johnsmith"
}
private static String[] ages = new String[] {
"30",
"30"
} mh_sh_highlight_all('java');

But can I not combine that into an array of objects? something along the lines of what you would do with json? like...

Java Code:

private static array[] multi = new array(){
{"name":"AIDANMACK","age":"30"},
{"name":"johnsmith","age":"31"}
} mh_sh_highlight_all('java');

View Replies View Related

Create Word Game Using Classes And Objects

Feb 14, 2015

For class, we need to create a word game using classes and objects.

The game is played in rounds. The player is presented with a word that is missing letters. The player has to fill in the missing spaces with their letter guesses. The words presented are chosen with a random number generator which has been provided for us. At the end of the game, the player is shown their score.

In steps, I have to:

-Welcome the player.
-Present the puzzle.
-Allow the player to fill in the blanks.
-Have the program check responses for correct/incorrect input.
-End the game if they have three misses, or continue if they complete the puzzle.

Now, to start, I have a class for the number generator, a class to store the array of 25 words, and a class for the game itself.

View Replies View Related

How Can One Create Array Of Objects Of Class Type

Feb 10, 2015

I'm really new to object/class concepts and already having difficulties with applying them. How to create and return an array of Exam objects? I need to get a data from a textfile which is passed to the method.

Java Code:

public Exam(String firstName, String lastName, int ID, String examType, int score) {
this.firstName = firstName;
this.lastName = lastName;
this.ID = ID;
this.examType = examType;
this.score = score;

[Code] ....

View Replies View Related

How To Create Array Of Objects Of Class Type

Feb 10, 2015

I'm really new to object/class concepts and already having difficulties with applying them. how to create and return an array of Exam objects? I need to get a data from a textfile which is passed to the method.

public Exam(String firstName, String lastName, int ID, String examType, int score)

{
this.firstName = firstName;
this.lastName = lastName;
this.ID = ID;
this.examType = examType;
this.score = score;

[code]....

View Replies View Related

Create A Sphere Class That Will Allow To Create Sphere Objects

May 9, 2015

I'm new to Java and I have an assignment to create a Sphere class that will allow you to create Sphere objects using the code below. Then create a program called SphereTester that prompts the user for the radii of two spheres in meters. The program should display which sphere is larger and by how many cubic meters and display only four digits after the decimal point. I have the sphere class given to us for the assignment which is this:

Java Code: public class Sphere {
// instance variable (i.e., a field)
private double radius;
// constructor for the Sphere class
public Sphere(double r) {
radius = r;

[code]....

View Replies View Related

Array Of Objects To Create 3 CDs (music) - Moving Songs?

Oct 17, 2014

Do I need to use inheritance for this type of program? How to move my song list in main to songs and from songs to cd to make 3 separate cd's.

I have 3 classes: main, Cd, and Song. I am having trouble moving the songs from main to the song class and from the song class to Cd.

package p2;
public class Main {
public static void main(String[] args) {
String tempStr;
//array for song names
String [] songNames={

[Code] ....

View Replies View Related

Create Separate String Objects As Strings Are Immutable

Jan 28, 2015

I want to clarify it whether this below code, when running this loop, will it create separate string objects as strings are immutable or else, will it keep the same reference(as each time inside loop, we use the same name 'rslt') and assign new string value for this?

while(inc < numberOfColumns){
String rslt=rs.getString(inc+1);
rowArr[inc] = rslt;
inc++;
}

View Replies View Related

Tester Class - Create Objects Of New Type And Then Use Dot Operator

Jun 12, 2014

So I'm beginning to learn java with the book HeadFirst Java. The books says that all a tester class does is create objects of a new type and then use the dot operator...

I don't really understand what a tester class is and what it does ? and what is the Dot operator and how does it work ?

View Replies View Related

Create Array / Store 5 Objects And Calculate Total Price - VAT Rate

May 6, 2014

How can I do the work below in Java

In this main class, create 5 objects of the class Menu, as defined in the table below.

Name amount of calories cooking time price per person number of drinks

Fufu and Groundnut Soup 564.65 2515.572
Red Red 345 12 9.980
Rice and Beef Stew 560.4 1512.651
Ga Kenkey and Fish 780 10 10.15 1
Banku and Tilapia 450.4 35 25.17 2

Exercise d
In your main class create an array of length 5, and store the 5 objects (Exercise c) into the array. You can use any name for your array.

From the array, use a loop to: Print the details of all the objects using the method you defined in Exercise b.

Exercise e
Use another loop to:
-Print only the name and cooking time of all the dishes that take less than 30 minutes to cook. Hint: you may use the getter methods for the name and cooking time attributes, and then, print these values (name, cooking time).

Exercise f
Use another loop to :
-Calculate and print the total price of all the objects (in the array).
-Calculate the total price of all the objects with VAT included for each dish (VAT rate is 17.5%).

Submission
-Create a folder with your index number as its name.
-Copy your Java Project folder into the created folder.
-Print a hard copy of your classes.
-Submit both soft copy and hard copy of your project

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

Create A Class That Will Accept Dates In Various Formats And Create A Range

Feb 1, 2014

In the class below I'm trying to create a class that will accept dates in various formats and create a range. The first constructor is easy because I send it the begin date and end date as Date objects. Now I want to send a month(and year) in a constructor and derive the begin and end dates from it. In my constructor that accepts the month/year I need to put the this(startDate, endDate) at the top to be allowed, but the parameters are not built yet.

package com.scg.athrowaway;
import java.util.Calendar;
import java.util.Date;
public class DateRange {
private Date startDate;
private Date endDate;

[code].....

View Replies View Related

Create A Menu Where The User Can Create A New Account?

Oct 5, 2014

I'm having some difficulty with my bank account project. I'm supposed to create a menu where the user can create a new account, withdraw, deposit, view their balance, and exit. There's issues with the account creation.

Here's my necessitated class below: BankAccount, TestBankAccount, SavingsAccount, CurrentAccount, and Bank

/*---------------------------------------------------
Plagiarism Statement
 
I certify that this assignment is my own work and that I have not copied in part or whole or otherwise plagiarized the work of other students and/or persons.
 
----------------------------------------------------------*/ 

package BankAccount;
 import java.util.Date;
import java.util.Random;
 //Project 3
public class BankAccount {
protected static int accountID;

[code]....

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

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

Array Of Objects

Mar 28, 2014

Exercise the Coin class using a driver class in which 5 coins are flipped, as a group, 1024 times. Display the number of times exactly 4 tails are obtained. Display the number of times exactly 5 tails are obtained. Use an array of Coin.

how to put an object into an array?I know how to make a coin class with a Heads and Tails, but I dont know how to make 5 coins all at once.

View Replies View Related







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