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()
import java.util.ArrayList; public class LectureRoom{ private String courseName; private String roomNumber; private String Lecturer; private ArrayList <Student> studentList;
[Code] .....
Question:
Given the following BlueJ class diagram
Lecturer class (same with previous lab, no changes needed) Student class (same with previous lab, no changes needed)
LectureRoom (changes occurs here)
1. LectureRoom has roomNumber (e.g. A301), courseName (e.g. Java), lecturer (a reference to a Lecturer object), and studentList (a reference to an ArrayList that stores Student object). 2. LectureRoom has a constructor that receives courseName, roomNumber, and Lecturer. The constructor then sets/assign the courseName, roomNumber and Lecturer. This constructor also creates the studentList arraylist object.
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.
How would I go about and make an enum, that has Strings and Methods?I want to make a class called GraphicalEffects, this class and be instanstiated and it has a method to apply graphicalEffects AS methods or some type of references to methods in an ArrayList.
If I have a method that creates a new variable (the name of which is a string argument for the method). Can I get that variable to appear in the workspace in the variables pane?
So instead of just using return to output the variable how do I get in that variables pane?
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;
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 + " "); }
I am trying to create a method that reverses the digits of a number.
import java.util.*; public class KDowlingWeek7 { static Scanner console = new Scanner (System.in); //Scanner input = new Scanner(System.in); public static void main(String[] args) {
[Code] .....
The error I get is :
Error: cannot find symbol System.out.print(reverseDigit + " "); Symbol: variable reverseDigit Location: class KDowlingWeek7
i am trying to create an applet with drop-down lists. When I compile the program the following error message appears '. . .is not abstract and doesn't override abstract method action Performed. . . Here is my code . . .
import java.awt.*; import java.awt.event.*; import java.applet.*; public class DavidApplet extends Applet implements ActionListener //class header { Label fName=new Label("First Name");
How would I create a equals method to compare strings in a class that I'm creating. I need to create the method in my class, and then call it in a driver. How would I do this?
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 doing an assignment and I am clueless as to what I did wrong or supposed to do in terms of placement of coding.
This is what I supposed to do:
1.) Type the following shell for the class:
public class ParadiseInfo { }
2.) Between curly braces of the class, indent a few spaces and create the shell for the main() method:
public static void main(String[] args) { }
3.) Between the braces of the main()Method, insert a call to the displayInfo() method:
displayInfo();
4.) Place the displayInfo() method outside of the main() method, just before the closing curly brace for the ParadiseInfo class:
public static void displayInfo() { system.out.println ("Paradise Day Spa wants to pamper you."); system.out.println ("We will make you look good."); }
This is what I attempted to do:
I know it is wrong I am just clueless on where to put the code and why
public class ParadiseInfo { displayInfo(); public static void main(String[] args) { public static void displayInfo(); } system.out.println("Paradise Day Spa wants to pamper you."); system.out.println("We will make you look good."); }
--- Update ---
I also tried it this one and ended up with 1 error..
public class ParadiseInfo { displayInfo(); public static void main(String[] args) { } public static void displayInfo(); { system.out.println("Paradise Day Spa wants to pamper you."); system.out.println("We will make you look good."); } }
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.
I am trying to create a method that prints the square root of a number up to a certain number. It needs to take a single int parameter for example "n" , and then print all of the (positive) even perfect squares less than n, each on a separate line. I want the method to be called something like this:
public void Squares(int n) { }
I need the output to look something like this:
Example: if n = 40, your code should print
4 16 36
So I have been working for a few hours now and am really stuck.
This is what I have so far:
int count = 0; int n = 4; int max = n; while(count < max) { System.out.println(n); n = n * n; count++;
In the process of creating a new class, I need to move my main method from the class SaveDate to the class DynamicTest. Below I have listed the code of both classes.The objective is to be able to run my program from the DynamicTest Class. I need understanding the process of moving my main method to a different class and creating an Object of a class and calling its method.
public class SaveData { private static final Map<String, Object> myCachedTreeMap = new TreeMap<String, Object>(); public static final List<String> getLines(final String resourceParam, final Charset charset) throws IOException{ System.out.println("Please get: "+resourceParam); if (myCachedTreeMap.containsKey(resourceParam) ) { // Use the cached file, to prevent an additional read.