How do I pass the data within an initialized array from inside one method to another method of the same class? Will I need to return the array, assigning it to a temp array, which will then be passed as an argument to the other array? The idea is to create an array for an entire year, and be able to manipulate or edit data for a particular month using the other method.
public class Temperature {
static Scanner input = new Scanner(System.in);
static String [] monthArray = {"January", "February", "March", "April", "May",
"June", "July", "August", "October", "November", "December"};
public static void main(String[] args) {
in my progrm there are three diff array of objects...namely garments..gadgets and home app...now one who buys from each of these sections will have to make a bill at last...when he choses to make the bill he will be shown the list of products he bought and their details (like price...brand...etc)...so i thought that while he orders each product(which is done in a previous method called purchase()...)....(each product is stored as an object in there diif arrays namely garments...gadgets ...appliances)....each of those object will be copied in a new array in a diif class...then that array print will give me the desired result...
is this approach correct...?and if its correct then how can i pull out a specific obj frm a stored array of object and then save it in a new array....?
I have to make two classes. The first one crates an instance of an array of several integers and prints data (average, greatest, lowest, et cetera) based on the second class, which contains the methods. I'm having a problem with the syntax for the first class required to use the methods.
Here's a shortened version of what I have right now just based on processing the number of integers in the array (because if I can get just one method properly connected, I could figure out everything else).
Driver
import java.util.Arrays; public class ArrayMethodsDriver { //Creates the ArrayMethods object public static void main(String[] args) { int[] a = {7,8,8,3,4,9,8,7};
[Code] ....
When I try to compile this, I currently get the "class expected" error on the count part.
I have a test that covers Objects & Classes, Importing Classes and Polymorphism. One of the essay questions will be: Explain two ways to pass arguments to methods and give examples. I was reading the book and found Pass by Value and Pass by Reference. Is this the two ways to pass arguments?
i'm able to login and download pages of a website using httpclient library.but i cannot launch a page on browser after login successful!becouse the browser not remember the username and password of the session so the site show that i'm not logged!
I have a question about an error I am getting when trying to pass a two dimensional array to a method. I keep getting the "incompatible types, int cannot be converted to int[][]". I am getting the error in a few different place (see comments - at the first call of the method, at a recursive call, and at the return statement. I believe I am passing the same type of array in all cases to the type of array defined in the method parameters.
Below is my code.
// this is a call from the main method int[][] c = new int[temp1.length][temp1.length]; c = MatrixMultiply(a,b); // this is first place the error occurs } // end main public static int MatrixMultiply(int[][] A, int[][] B) { // throw new UnsupportedOperationException("Not supported yet."); int a[][] = A;
public class AddArray { public static void main(String[] args) { int sum = 0; sum = addArray(myarray); System.out.println(" hello"); System.out.println("This program will create an array then pass the array to an method to be totaled"); int myarray[] = new int [6];
I need to pass user input from the main method, which is then validated using another method that is returned as a valid score, and then I pass the valid input to another method that stores the data in an array. The array is initialized within the method. I tried to use an if-else statement to initialize the array, because I originally did this at the beginning of the method. I soon learned that I was creating a new array everything I accessed the method. Needless to say, this isn't working either.
public static void main(String[] args) { int judges = 7; float[] validScores = new float[judges]; for (int i = 0; i < judges; i++) { float score = -1;
I have an arraylist in my servlet which i need to pass to jsp as a response for a javascript call. This is an arraylist of DTOs. There are 24 DTO objects in the list. The DTO has an int variable and a HashMap. And i need to pass this into the javascript code in my jsp page. Do i use json? Do i send the entire list as a json object or should i iterate through the arraylist (from servlet) and serialize all the DTOs and pass that to the jsp?
prompts user for the grades of each of the students and saves them an int array called grades. Your program shall check that the grade is between 0 and 100. program should then check if the grade is equal to or greater than 50, where 50 is the pass rate.
A sample output :
Enter the number of students: 3 Enter the grade for student 1: 55 Enter the grade for student 2: 108
Invalid grade, try again...
Enter the grade for student 2: 56 Enter the grade for student 3: 57
The average is 56.0 The maximum is 57 The minimum grade is 55 The number of fails is 0 The number of passes is 3 ..
I'm writing a program that involves the use of set/get methods. I will submit a sample code of my issue. The format appears to be alright however the program is not returning any data. This is the same format as my actual code. Why this might be happening?
Java Code:
public static void main(String [] args) { SecondClass object = new SecondClass(); object.setName("Name"); object.getName(); } mh_sh_highlight_all('java');
Java Code:
public class SecondClass { private String name; public SecondClass(){ name = " "; } public void setName(String name) { this.name = name; } public String getName() { return name; } } mh_sh_highlight_all('java');
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);
The following code is supposed to generate random integers and sort array1 and array2 using two different sorting methods. array1 is to be sorted with a "selection sort" method and array2 is to be sorted with the built-in Arrays.sort() method. However, array1 is the one that has a problem. It does not appear to output any values at all for array size of 4000 or more, such as array1[10000]. The assignment is to generate random integers, sort and benchmark the speeds at which array1 and array2 can generate and sort ints at array1[1000] array2[1000] array1[10000] array2[10000] array1[100000] array2[100000]
/** * * The following is a sorting and benchmarking program to sort * array1 and array2 with 1,000 , 10,000 and 100,000 array sizes. * array1 uses selection sort from section 7.4 of the book * and array2 uses the built in Arrays.sort() method.
[code]....
I cannot post the output because the amount of data seems to have crashed the two previous posts I made on this topic due to the size of the problem.
I'm working on a project that involves the following:
-Creating a superclass of bankaccounts -Creating two subclasses, checkingaccount and savingaccount -Each of the two subclasses has different methods (writeCheck for checking, for example) -Both types are created in a main class bank and stored in the same array
So let's say a user goes through the menus and creates a few savingAccounts and a few checkingAccounts (stored in the accounts[] array). Then, to write a check from one account, the user can enter the account number (a string), and the method will use a for loop to cycle through the array until it hits an account number match. Then it checks that it's the correct account type and calls methods from the subclass.
Problem here is that some methods work and some don't. In the following example:
for (BankAccount account: accounts) { if (account.getAccountType().equals("Checking")) { do { if (account.getAccountNumber().equals(accountNumber)) { amount = Double.parseDouble(JOptionPane.showInputDialog(
[Code] .....
The getAccountNumber method works but writeCheck is throwing an error. I tried creating a method in the superclass and overriding it in the subclasses but with no success.
Some methods such as ServletRequest's getParameterValues return a String array whereas others (e.g. HttpServletRequest's getHeaders) return an Enumeration. Do these return types need to be learned parrot-fashion, or is there some sort of logic to it?
In this project each individual will create a data analysis program that will at a minimum,
1) read data in from a text file, 2) sort data in some way, 3) search the data in some way, 4) perform at least three mathematical manipulations of the data, 5) display results of the data analysis in numeric/textual form, and 6) display graphs of the data. In addition, 7) your program should handle invalid input appropriately and 8) your program should use some "new" feature that you have not been taught explicitly in class.
(Note: this is to give you practice learning new material on your own - a critical skill of today's programmer.) If you do not have a specific plan in mind for your project, below is a specific project that meets all of the qualifications as long as 7) and 8) are addressed in the implementation.
Everything is done except I need to call my methods in my GradeTester.
GradeBook:
/** *This class creates an array called scores. *This class determines the length of the array scores and determines the last grade in the array scores. *This class sorts the array using a bubble sort, and searches the array. *This class calculates the mean, standard deviation, and the median of the grades in the array scores. *Once the grades in the array is sorted, the class then calculates the highest and lowest grades in the array. */
public class GradeBook { public final int MAXARRAY_SZ = 20; double [] scores = new double [MAXARRAY_SZ]; int lastGrade = 0; double mean = 0;
I want to keep count of how many students are in my array. the array i made up of objects from other classes. like the class Student how do i do this. i have tried contains but better way it to to a loop to go through the array and determine if each object is a particular type but i don't know how to do this. here is the code
import java.util.*; import java.util.ArrayList; public class Driver { public static void main(String[] args){ /* Comments required PersonFileReader pfr = new PersonFileReader("person.dat"); ArrayList<Person> testData = pfr.readData(); Database db = new Database(testData);
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" .....