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


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

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

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

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

Java Number Spiral - Creating 2D Array With Given Input Of Dimensions Of Array

Aug 3, 2014

I am working on a problem where i have to create a 2d array with given input of the dimensions (odd number) of array, along with a number within the array and to then print out all of the numbers surrounding that number.

Anyway, i am working on simply making the spiral, which should look like the one below.

n = 3

7 8 9
6 1 2
5 4 3

where the 1 always starts in the center with the 2 going to the right, 3 down, then left etc. etc. I was able to create the code by starting on the outer edges rather than the center and working my way to the middle, however my code always starts from the top left and goes around to the center where it needs to start from the top right. I am having trouble altering my code to meet this criteria. This is what i have thus far.

import java.io.*;
public class Spiral
{
public static void main(String args[])throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter the number of elements : ");
int n=Integer.parseInt(br.readLine());

[Code] .....

View Replies View Related

Creating Array That Works Like A Torus

Mar 14, 2014

I have create a program that takes a random array which is created by starting from 0 and adding Math.random() (double between 0 and 0.999) n times, and calculates the weighted average of each position within a certain radius. I currently have a program that does this but i was wondering how to create one using a torus. The basic principle is the last element is now equal to the first element and when the first element updates its position it takes into account the difference between the other elements including some of the last elements in the array.

Heres the code so far that works for one iteration. After one the code is incorrect and calculates the wrong values. I think using a circular list or a ring buffer may work but i have little experience with either.

import java.text.DecimalFormat;
import java.util.Scanner;
public class Torus {
public static void main(String[] args) {
  DecimalFormat df = new DecimalFormat("#.###");
 
 [Code] ....

View Replies View Related

Creating A Window In 2D Char Array

May 17, 2014

I am relatively new to java, and i am trying to create a window inside of a 2d char array, and eventually i will have to draw other shapes in this window. so for example

* * * * * * * * *
* *
* *
* *
* *
* *
* *
* *
* * * * * * * * *

The problem is my window is not drawing correctly too the border, but a couple extra chars on the x columns. Here is code. The dimensions of the window will eventually be passed through scanner in main, if i ever work out how to even draw it.Also, in class we never learnt to use the Graphics class, so im pretty sure we are not supposed to use it.

public class Window
{ //default values
private int xRow;
private int yCol;
private char ch;
public char[][] windowz = new char[30][20]; //30,20 (yx)flat values cuz doesnt work

[code]....

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

Creating Array That Works Like Torus

Mar 15, 2014

I have create a program that takes a random array which is created by starting from 0 and adding Math.random() (double between 0 and 0.999) n times, and calculates the weighted average of each position within a certain radius. I currently have a program that does this but i was wondering how to create one using a torus. The basic principle is the last element is now equal to the first element and when the first element updates its position it takes into account the difference between the other elements including some of the last elements in the array.I cant work out how this would be possible for multiple iterations.

heres the code so far that works for one iteration. After one the code is incorrect and calculates the wrong values.I think using a circular list or a ring buffer may work but i have little experience with either.

Java Code:

import java.text.DecimalFormat;
import java.util.Scanner;

public class Torus {

[code]....

View Replies View Related

Creating ArrayList And Adding Item To Array

Nov 27, 2014

Creating an Arraylist and adding item to that array, refer below code

ArrayList<String> sjarr = new ArrayList<String>();

Statement1:
String arritem1 = new String("First array item");
sjarr.add(arritem1);

Statement2:
String num = "text will decide";
sjarr.add(num);

Both adds the String item to array list but puzzling what makes the difference....

View Replies View Related

Creating Array With Multiple Data Type?

Oct 10, 2014

i need to create an array with attributes name, gender, phone, age.and then sort acording to age in ascending order.

i created like this,

public class Array{
private String[] name={"ram", "katy", "priti", "john"};
private String[] gender={"male","female","female","male"};
private int[] phone={989898089,89898989,8982989089,898908989};
private int[] age={45,24,30,28};
  public void printarray(){

[code]....

This code sorts the age attribute alone and when printing ouput it swaps one person's age to other person, how to make it correct

View Replies View Related

Creating Method To Print Array Of Integers

May 7, 2014

I am trying to create a method that takes an array of integers and prints it out using System.out.print. I'm having trouble creating the right way to print it out since I cannot find a way to convert the int array to a string to print it out.
 
public static String printArray(int[] num){
for (int i=0; i<num.length;i++){
String msg = num[i];
}
return System.out.print(msg + " ");
}

View Replies View Related

Creating Magic Square - 2D Array And Looping

Sep 12, 2014

How to create a MAGIC SQUARE, i just wanted to learn the logic of it .. with 2d array and looping..

View Replies View Related

Creating Array And Putting Into Steam And Leaf Plot

Feb 12, 2015

I just want to know how I would go about creating an array of 100 random ints and putting it into a stem and leaf plot...

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

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

Creating A Chart For Work?

Mar 6, 2015

I need to create a chart for work and comes across this sample from mbostock's chord diagram (bl.ocks.org/mbostock/4062006).

I only need to revise the tick label (names, display positions) but I don't know how to do it as I have 0 experience with Java.

My sample data for the var matrix is

[0,100,100,100]
[0,0,99,98]
[0,0,92,84]
[0,99,0,0]

which shows flows between country A, B, C and D.

I would like to revise the tick labels, so that:

1) Instead of showing 0K 5K 10K, I would like to show the country names (A - D), with no number or tick. I figured out this one by just commenting out all the codes relating to ticks.

2) Place the country names in the center of the arch. I don't know how to do this one.

View Replies View Related

Creating A Excel From Swing?

Jul 9, 2014

I wrote a program that asks the user to enter some information, does some calculations and tells them what they need to order. I know there is a way I just do not know how to do it. I would like the output from the program which is presented in text fields to be printed onto a form I made in excel when a button is pressed.

View Replies View Related

Creating A Diagonal Cross?

Oct 3, 2014

I need to create a diagonal cross however I can not figure out how to do the upper left side of it.

Currently I am getting

0*
1--*
2---*
3 *--*
4*-----*

I want to get it to look like

0*------*
1 *--*
2----*
3 *---*
4*------ *

( I replaced spaces with -) So far I have

System.out.println("Input a size(must be larger than 1: )");
size=input.nextInt();
if (size>1) {
for (x=0;x<size;x++){
System.out.println("");

[Code] ....

View Replies View Related







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