Java Code:
/**
*The method creates an array list of integers and then prompts the user
* for an integer. As long as the user continues to enter anything other
* than -999, add the number to the array list.
*
* @return the array list of numbers
*/ mh_sh_highlight_all('java');
I've attempted this several times but am still struggling.
I'm writing a program that acts as a 'pocket' where the user is able to enter a kind of coin, such as, a quarter and the amount of quarters it has. I was assigned to do 3 different class, the Coin Class in which the coins and their values can be instatiated from, a Pocket Class, where I have to write a method that can add the coins of the user (basically the method would act like ArrayList .add() ) and the PocketClass tester. I have already written most of the code, but I am stuck as to how I could write the following method:
Java Code:
public void addCoin(String s, int i) { // s is type of coin, you are using s to instantiate a Coin and get value // i is number of coins, you are using i to keep adding value to the totalValuefor } mh_sh_highlight_all('java');
Would I use a for-loop in order to keep track of the number of coins? I would use ArrayList but the assignment calls for creating a method similar to that of .add()
How do I code this so that after the user has added to the arraylist 'theFruit' if they then press 'V' to view all fruit it includes the default fruit as well as the fruit they've added?
Also in the method 'AddFruit' it only allows me to add 2 fruit before printing. Why is this?
import java.util.ArrayList; import java.util.Scanner; public class StkOv { public static void main(String[] args) { TheMenu();
my arraylist is declared in my main method. A string that i will be calling on is declared in my main method as well. The arraylist and string is passed to a method outside the main. I am to search for the beginning of a string and end of the string, remove those items. Then i am to pass the string with the removed items to arraylist that is called in my main with an enhanced for loop. The for loop then displays what is needed from the string and the method i created. I will posting an example of my main and method that is used in my program.
public class ExampleUrl { public static void main(String[] args) throws MalformedURLException, IOException { ArrayList<String> urlList = new ArrayList(); String url = "";
how to read and understand the API's. I've got an array list and I was wondering if there was a method that can randomly re arrange the elements in terms of their index positions.
I have created a method Rectangle and added a loop in my class Resizer (MouseAdapter) but impossible to resize the rectangles of the arraylist independantly !
class Rectangle extends Rectangle2D.Float{ private String name; public Rectangle(float x, float y, float width, float height, String name) { setRect(x, y, width, height); this.name = name;
This is the code fragment I have for searching my ArrayList. Now, each contact is stored in the ArrayList with five elements (first name, last name, etc.) and they're Strings. The error I get when I try to compile my program lies within this code fragment. It says it cannot find the symbol for the search method. I'm not quite sure what to do with this error.
int foundIndex = SAAddressBook.search(aBook); System.out.println(); if (foundIndex > -1) aBook.get(foundIndex).displayContact(); else { System.out.println("No Entry Found"); }
I am trying to remove the duplicate elements from ArrayList using .contains() if elements are primitive datatype it works but user-defined datatype does not work.
public class UserBean { String name; String address; public String getName() { return name;
How do I code this without having the need to use iterator? Code a Java method that accepts an ArrayList of integers and an integer. The method should delete all elements in the array list exactly divisible by the integer and return the number of remaining elements.
So I'm trying to implement a quick sort method for an ArrayList of Strings and right now I'm getting the compiler error message: Exception in thread "main" java.lang.OutOfMemoryError: Java heap space. I don't know what that error means nor how to fix it. I've marked in my code where the error seems to be occurring.
import java.util.ArrayList; public class quickSort { // constructor public quickSort()
I'm doubted regarding the implementation of Collections.binarySearch() method on an ArrayList of objects of a custom class Movie.
Here is the movie class :
public class Movie implements Comparable<Movie> { String movieName; String rating; String director; String theme;
[Code] .....
The sort/binarySearch in searchByMovieName function is done with natural sorting (and Comparable Interface in Movie class). I mean no comparators involved here. And the comparator that I used for sorting/binarySearching on Movies Director attribute in searchByMovieDirector function is :
public class MovieDirectorComparator implements Comparator<Movie> { public int compare(Movie movie1, Movie movie2) { return movie1.getDirector().compareToIgnoreCase(movie2.getDirector()); } }
But I was not able to implement binarySearch ?? How to implement the binarySearch here. I have google to see only binarySearch working on Arrays or probably ArrayList of String only, but not on ArrayList of custom objects.
We are supposed to create a MergeSort method without the using recursion. Most of the code is already completed, the only thing that I believe I need are two for loops (an inner and an outter) that will make calls to the merge method. I need implementing the sort method of the merge sort algorithm without recursion, where the length of the array is a power of 2. Keep merging adjacent regions whose size is a power of 2. For ex: lengths will be 1, 2, 4, 8, 16,.
public class MergeSorter { public static void sort(int[] a) { //for(int i = 1; i <= a.length; i++) the parameters for the for loop are wrong. { merge(0,0,1,a); merge(1,1,2,a); merge(2,2,3,a);
I need to create a method that returns a new array containing the componentwise sum of its arguments(if length is the same). For instance, if the input arrays are {0,1, 2} and {2, 2, 3} then the output is {0+2, 1+2, 2+3}, i.e. {2,3,5}.If the input arrays have different numbers of elements, the method should return null.
I came with something like this, however i dont know how to make a copy of an array from two arrays. My code obviously wont compile. package whatever;
import java.util.Arrays; public class hhhh { public static void main(String[] args) { double [] a = {1,2,3}; double [] b = {2,3,4};
I'm trying to create a simple java math question quiz using random operators, but keep sinking myself into deeper despair. The numbers must range from 0-9 and given an operator: +,-,/,*,%. Can't create a new method or use Case statements. The code isn't finished but don't want to make it any worse.
package marco; import java.util.Scanner; import java.util.Random; public class Project { public static void main(String[] args) { Scanner keyboard = new Scanner(System.in); Random rand = new Random(); System.out.println("How many questions do you want?");
I've been writing classes over and over for school. So I create a class outside of my main class. I create a new constructor and then create objects from my main class. I hope that makes sense. So i use methods in that class to work with the object. So I have an object name I've created <dot> method name. So I can create objects and then use methods from the class, but I'm wondering can I create a method in my main class and use it on that object? I don't understand how to do that.
im trying to create an insertion sort method for a vector. I know how to insertionsort for an array, but for a vector im having problems
Source code: PHP Code: package test; import java.util.*; import java.io.*; public class LinearSearch { public static void main (String[] args) { Vector myVector = new Vector();
[Code]...
I'm getting errors at lines 38 and 39 "Left-hand side of an assignment must be a variable". "Syntax-error(s) on token(s) misplaces contructor(s)". How can i fix them ??
I need figuring this problem out. It appears that I am attempting to generate a permutation of the string "ABCDEF" 720,000 times using this method:
In the second method, j is chosen randomly in the range from 0 to i (inclusive).
Once the permutations are generated, the program will proceed in counting the number of times each permutation occurs, calculating the chi square statistic of the situation, and creating the chi square distribution with 719 degrees of freedom, then outputting the statistic and the chi square probability of the permutations. The generatePermutation method is where all the magic happens. Only trouble, I can't figure out what I equals to. The times where I think I have i as a correct value only give me the program outputted as 1.0 probability every time. What it needs to be doing is outputting variable probability as a number always between 0 and 1, not 1 all the time. Here is my code:
I have two classes: main (with JFrame) and a panelLogin class with a method returning a panel with all login components..so I create a new panelLogin in main and use the method to get the panel, put it into my JFrame. But here the problem: on the loginPanel the ActionListener for the login-event, if the input is correct,the panel shall disappear and the main panel shall appear.Should I make some kind of top class, which handels the panels?
public void randomCreate(ParentObject obj){ int x = random(0-4); //pseudo int y = random(0-4); //pseudo create new ParentObj(x,y); }
ParentObject is actually abstract, so you would only ever pass one of its children objects to it, and a child object of that type would be created. It seems like there should be a way to pass a type, rather than an object, and then create an instance later down, but I don't know if that is actually possible, or if it is poor programming style.
I am having trouble with methods. What I want to do is be able to create 4 types of strings under the same method, but only draw one of them at a time.
so i have this question where it wants me to create a recursion method that takes ONLY THE ARRAY as a parameter, and without using loops or static variables inside the method, and then the method returns the smallest value in that array. However, i tried making the simple if statements where i compare the first element of the array with the second element using the length of the array and decreasing it to get the next elements and compare it again by calling the recursion method, but the problem is when i call the method again, the length does not decrease, even if i store it in a variable, the variable will initialize itself again, and the length wont change.
In my book for learning java, one of the questions asks us to create a method header named convertTOKM that takes an int parameter, which is the number of miles, and returns a double value for the converted value in kilometers. I made one, but wanted to know if I was right in any way.
Here it is:public double convertTOKM(int miles, double kilometers){
I am trying to create a method that calculates the standard deviation of array. What I want to be able to do is something like this
package standardDevaitionAndMean; public class StandardDeviationTest { public static void main (String[] args) { int [] array = {12,12,12,12,12,12,12}; standardDev = array.StandardDevation(); System.out.print(standardDev); } }
With something like this
package standardDevaitionAndMean; public class StandardDeviation {double mean1; double standDev; public double Mean(double ... array) { for(int i=0; i<array.length;i++)
[Code]...
So basically I want to be able to make an array in a class and be able to calculate its standard deviation with my method in my other class. I know the code I wrote is terrible but I just wanted to show what I am trying to do. I am kind of shaky on how arrays operate
Create a method called mirrorImage, which takes two integer arrays as input parameters. You may assume that the two actual parameters have the same length. Your method should return true if the arrays are the reverse of each other. Otherwise mirrorImage should return false.
Examples:
data1:{1,2,3} data2:{3,2,1} ==> true
[code].....
I'm pointing a place outside of the array or something
public Unit(String code, String name) { enrolStudent(student); this.unitCode = code; this.unitName = name; } public void enrolStudent(Student newStudent){ students = new ArrayList<Student>(); newStudent = new Student(24662496, "Kingsley", " Iwunze"); students.add(newStudent); }
how can I call this enrolStudent() method on this Unit constructor in another class when I create a new Unit. all I need is to enroll students in units when units are created. below is my create unit method.