Creating Accessor And Mutator For Dual Array?
Apr 19, 2015I 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 RepliesI 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 RepliesHere 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] .....
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] ....
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" .....
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....
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].....
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] .....
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] ....
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]....
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?
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]....
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....
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
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 + " ");
}
How to create a MAGIC SQUARE, i just wanted to learn the logic of it .. with 2d array and looping..
View Replies View RelatedI 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 RelatedI 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.....
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.....
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 RelatedI 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]...
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] ....
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]...
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.
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.
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 RelatedI 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] ....