Sphere Class Using Accessor / Mutator Methods

Feb 25, 2014

So I've been working on this sphere class forever and have tried rewriting it a number of times. each time i change something i get a different error...

Instructions: create a sphere class with the following properties:

private attributes: x, y, z coordinates of center, and the radius.

Accessor and mutator methods to: set and get the x,y,z coordinates, set and get the radius, get the volume and surface area of the sphere.

This is the main sphere class:

Java Code:

package spheretester;
<pre class="brush:java;"> */
import java.io.*;
import java.util.Scanner;
public class Sphere {
public static void main(String[] argv) throws Exception

[Code] ....

View Replies


ADVERTISEMENT

RetailItem Class Modify With Accessor Mutator

Apr 23, 2014

Here is what i have so far. The retaiItem class and the demo. Basically, my output looks like this:

Description:
Candy bar
Item Number: 17789
Wholesale Cost: $0.75
Retail Price: $1.50
new wholesale cost: 1.0
new retail price: 1.99

[Code] ....

package retailitemdemo;
public class RetailItemDemo {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {

[Code] .....

View Replies View Related

Creating Accessor And Mutator For Dual Array?

Apr 19, 2015

I am familiar with creating accessors and mutators, Any example of how to create them for dual arrays? I need the dual arrays to be int

View Replies View Related

Using Accessor Methods To Access Data From Another Class

May 6, 2014

I have been asked to write a program with 3 classes(an interface, a store and a product class) and I have been going ok until I need to display data on the interface that is held in the product class. At the moment the code will compile fine but when I run the program and try to use the writeOutput() method I get a stack overflow error.

I realise now that it is because of a non-terminating recursive call, however I can not think of a solution on how to fix the problem. And just to clarify, what I am aiming to do is have the MatesTerminal class display the data for name that is stored in the Product class(I have no way of determining which product to display at this time, so I would like to be able to display the data for all three products if possible). Anyway this is what I have so far:

The method from the MatesTerminal Class:

private void writeOutput() {
int productChoice;
Scanner console = new Scanner(System.in);

[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

How To Enter In Diameter In Main Class For Sphere Class

Apr 1, 2015

public class Sphere {
public double diameter;
public double volume;
public double area;
public double fourThirds = 4/3;
public Sphere(double someDiameter){
someDiameter = diameter;

[Code] ....

I am trying to get this code so that I only enter the diameter once in the sphere object1 = new Sphere(4); but I can't get it to work right. I can get the diameter to work with the calculate volume and area methods but that's it.

View Replies View Related

Assignment To Create A Sphere Class

May 8, 2015

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:

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

[code]....

Here is a sample run of what the final result should look like

Enter the radius of a sphere (in meters): 1
Enter the radius of a 2nd sphere (in meters): 2
Sphere 2 is greater than Sphere 1 by 29.3215 cubic meters

View Replies View Related

Declaring Methods For A Class In Its Own Class Whilst Objects Of Class Declared Elsewhere?

Mar 5, 2015

How do you declare methods for a class within the class whilst objects of the class are declared else where?

Say for instance, I have a main class Wall, and another class called Clock, and because they are both GUI based, I want to put a Clock on the Wall, so I have declared an instance object of Clock in the Wall class (Wall extends JFrame, and Clock extends JPanel).

I now want to have methods such as setClock, resetClock in the Clock class, but im having trouble in being able to refer to the Clock object thats been declared in the Wall class.

Is this possible? Or am I trying to do something thats not possible? Or maybe I've missed something really obvious?

View Replies View Related

How To Use Mutator Method

Jul 31, 2014

So I am doing exercises from my book and I am stuck for nth time. I have problems understanding the exercises from this chapter, this one as well... Add the following method to the Stock class:

public void clear()
Resets this Stock’s number of shares purchased and total cost to 0.

So I did this : public void clear(){
this.totalShares = 0;
this.totalCost = 0.0;

My problem is I don't know where and how to use it in my code and what result should I look for.Here is a pastebin with the Stock class URL....

View Replies View Related

Inheritance In Java - Child Class Get Copy Of Methods And Variables Of Parent Class?

Mar 1, 2015

Does child class gets a copy of the methods and variables of parent class?

public class test1 {
public static void main(String a[]) {
Child c = new Child();
c.print();

[Code] ....

why is the output 1?

View Replies View Related

Methods From Original Class Receiving Error When In Test Class

Jul 5, 2014

I am working on a program that simulates a bug moving along a horizontal line, My code works correctly when I test it in it's own class but when I tried testing my constructor and methods in a test class I received an error saying, "package stinkBug does not exist" on lines with my methods. However, stinkbug is not a package.

Java Code:

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/

[code]....

View Replies View Related

Write A Class Named Calculator Add Four Methods To That Class

Jan 30, 2014

Write a class named Calculator add four methods to that class:

add(int a, int b)
sub(int a, int b)
mul(int a, int b)
div(int a, int b)

Then write a Tester class with main function and show the use of the methods in Calculator class..

View Replies View Related

Using Mutator Method To Set Data To Array Element

Jun 2, 2014

the problem I'm having is I want to use a mutator method to set data for an array element. The code I have so far is:

public void addProduct(String productName)
//Goes through and sets the name of a product and assigns it to the array
{
int index;
for (index = 0; index < product.length(); index++)
{
product[index].setName(productName);
numberOfProducts++;
}
}

The array was initialised like this:

Product[] product = new Product[3];

And the setName(String) method is just your typical mutator method.However, in Eclipse, I have an error messages. It is:

"-The method setName(String[]) is undefined for the type String" .....

View Replies View Related

Calculate Area And Volume Of Cube / Sphere / Cylinder And Regular Tetrahedron

Sep 9, 2014

Write a Java program that calculates the area and volume of a cube, sphere, cylinder, and regular tetrahedron. Your program should obtain the necessary input for each of the objects from the console and output the input, area, and volume of the object. Use appropriate messages to guide the user of your program.

View Replies View Related

JavaFX 2.0 :: 3D Sphere To Represent Each Single Point - Rotation Lagging With Large Number Of Points

May 22, 2014

We are doing a visualisation tool for point cloud research project. We use 3d sphere to represent each single point and when we have large number of points to display (~40,000), the rotation becomes very lagging.
 
What we have tried:

set JVM flag -Djavafx.animation.fullspeed=true, this worked a bit, but not significant.set JVM flag -Djavafx.autoproxy.disable=true, this did not work.

set Cache to true and CacheHint to Cache.SPEED, this did not make much difference.create another thread to do the rotation, and sync back after calculation, this did not work neither.

View Replies View Related

Methods In Object Class

Jan 16, 2014

We know that all classes in Java extend the Object class. But methods in Object class are declared as public.I think if they were declared as protected, then also there wont have been any issue. So, what is the reason behind making them as public?

View Replies View Related

Multiple Methods In One Class

Sep 13, 2014

Is it possible to have multiple methods in one class?And can I use the Scanner in methods other than the main method?

View Replies View Related

Move A Methods To A New Class

Feb 5, 2015

there are two classes here. I need to put the max and min methods should be in the tester class, but I have tried moving it to the tester class and it will not comply. When I run I get a list of errors of "Error:(43, 9) java: illegal start of expression

Error:(43, 16) java: illegal start of expression
Error:(43, 22) java: ';' expected
Error:(43, 41) java: '.class' expected
Error:(43, 52) java: illegal start of expression
Error:(43, 51) java: not a statement
Error:(43, 53) java: ';' expected
Error:(57, 9) java: illegal start of expression
Error:(57, 16) java: illegal start of expression
Error:(57, 22) java: ';' expected
Error:(57, 41) java: '.class' expected
Error:(57, 52) java: illegal start of expression
Error:(57, 51) java: not a statement
Error:(57, 53) java: ';' expected"

package A808;
public class FuleTesterV1
{
public static void main(String[] args)
{
String titleLines;
titleLines = "Yearly Gas Mi Calc | Assignment 8.08";
String TitleLines;
TitleLines = "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";

[code]....

View Replies View Related

How Many Methods Should Be Included In Class Definition

Apr 6, 2014

Suppose you have an abstract class say Sparrow that extends the abstract Bird class. The abstract Bird class has the abstract methods, fly() and run()

How many methods from the Bird class should you implement in the Sparrow class?

View Replies View Related

Override Certain Methods In Class File?

Oct 16, 2014

I am wanting to override certain methods in some Minecraft class files, and tell those class files to use code from my class files.

And no, I don't mean extend a class. When I try to extend from the main Block.Class, it makes that file as another block file for the game, or something.

So like, I want to tell the main file that handles block registries to use the code from my class file to register my custom blocks to the list of blocks, but without modifying that main block file.

Is this even something that's possible?

Also, I know that the way a file is named affects the loading order. My class files would be named using symbols to make it load right before the class file I want to override.

View Replies View Related

Scanner Class - Can't Seem To Access Methods

May 9, 2014

I have two classes built for this assignment. One with getters, setters and constructor and a test class. The test class works fine up until the point when the user wants to (M)odify an employee that he/she built with the loadEmployee method. What happens is I need to enter multiple "M" inputs before anything pops up, and when something pops up, it's the displayMenu instead of modifyEmployee method. I imagine it has something to do with the amount of sc.nextLine()

import java.util.Scanner; // utilize scanner via console
import java.text.NumberFormat; // allows numbers to be format in form of currency
//Example of "big loop" in main to repeat using a No Trip (0,N) test first
public class EmployeeTest {
// space provided to make code easier on eyes...

[code]...

View Replies View Related

Create Instance Of Own Triangle Class And Use One Of Its Methods

Mar 15, 2014

So in the code below I create an instance of my own triangle class and use one of its methods. The thing is I use one of my triangle classes methods in a method other the main method of my main program so I'm thinking it can't access it?

Any way here's the code for my triangle class
 
import java.util.Scanner;
public class QudratullahMommandi_Triangle_06 {
Scanner keyboard = new Scanner(System.in);
private double side1;
private double side2;
private double side3;

[Code] ....

and here's the error message

QudratullahMommandi_S_06.java:46: error: cannot find symbol
{ triangle1.outPut();
^
symbol: variable triangle1
location: class QudratullahMommandi_S_06
1 error

View Replies View Related

Creating Methods Using Arrays - Fraction Class

Sep 27, 2014

I am trying to get the average of 3 different fraction arrays. I made a fraction class and I made methods such as read() and average() in this new class.

package fractions;
import java.util.Scanner;
import java.util.Arrays;
public class FractionArrays {
public static void main(String[] args) {
Fraction completeFraction = new Fraction(5,6);

[Code] ....

I was wondering if there was any way to use the arrays I created in the read method in the average method. If I find that out I should be able to do it on my own. Is there a way to make the arrays public to use in different methods?

View Replies View Related

Creating Instance Methods And Driver Class

May 5, 2014

Okay, so I have to create a class with instance data and instance methods.

First, BankAccount class. It should contain the following information, stored in instance variables:

First name: The customer's first name.
Last name: The customer's last name
Balance: The amount of money the customer has in the account.

It should have the following methods:

BankAccount(String firstName, String lastName,
double openingBalance)

This constructor creates a new BankAccount

public String firstName()
Returns the customer's first name
public String lastName()
Returns the customer's last name
public double balance()
Returns the customer's account balance

Finally I need to create a driver to test my class. And create several accounts and verify that the first name, last name, and balance methods work properly. This is my code below.. I don't know if I did it right.

public class BankAccount {
String firstName, lastName;
double balance;
public BankAccount(String firstName, String lastName, double balance) {

[Code] .....

View Replies View Related

Create Constructor With Parameters And Methods In Same Class?

Feb 28, 2014

The one problem in my book was to create a constructor for different shirt features, which I did and ran successfully. Out of curiosity, I also added other methods to see if it would run if the parameters were different from the constructor. It keeps giving me a constructor error. So, my question is, am I able to create a class that uses a constructor with parameters and other methods without errors? I'm guessing there's no reason to since it would be wasted space since the constructor could do it but was just curious if it's possible.

Is everything from the constructor down (in the class) and Shirt.oneShirt (in the main) just a waste of time?

Here's my example:

public class Shirt//class name.
{
int collarSize;//data field.
int sleeveLength;//data field.
int pocketNumber;//data field
public final static String MATERIAL = "cotton";//final data field for material.
public Shirt(int collarSize, int sleeveLength, int pocketNumber)//start of constructor.
{

[Code]...

View Replies View Related

How To Write Driver Class To Test Methods

Apr 13, 2015

I am to create a Array class then create a Driver class (TestArray) to test all the methods in the Array Class. Here's the code i've written for the Array Class. I just nee developing the TestArray class.

import java.util.Scanner;
public class Array
{
Scanner sc = new Scanner(System.in);
private double[] array = new double[];
public void setArray(double[] arr) {

[Code] ...

View Replies View Related







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