I have the following method that I need to implement:
{
// YOUR CODE HERE
File file = new File(filename);
int counter = 0;
String tempArtist, tempName;
Album tempAlbum;
Track tempTrack;
[code]....
Ok so I updated my code from the initial post since I made some progress on my own. I guess now I'm just stuck on how to scan in the file of strings and stock it into the type Track. (I've tried using both the initial linked list for this and a temporary variable with no luck).
One of the requirements of my programming assignment is that a user enters a command along with two numbers. For example, if I entered the following command:
I 5 6
The program create an image like this (it wouldn't be outputted though):
00000 00000 00000 00000 00000 00000
It creates a 5 x 6 "image". This is where my troubles begin. The program should also accepts other commands, such as:
L 3 2 F
which would produce (also not outputted):
00000 00F00 00000 00000 00000 00000
Here is my method for creating an "image" with an M * N array
for (int i = 0; i < column; i++) { for (int j = 0; j < row; j++) { System.out.print("0"); } System.out.println(); }
The code works, but I need to store the image in an array so it can be changed by other methods (I can't create the image manually every time). I tried doing something like this but it doesn't work:
public static String[][] createImage(int row, int column) { String[][] image = new String[row][column]; for (int i = 0; i < column; i++) { for (int j = 0; j < row; j++) { image[j][i] = "0"; } System.out.println(); } return image; }
This method outputs as many blank lines as the columns I entered and the memory location of image.
So my question is: how would I store "0" in a 2D array so that it can be accessed and changed by other methods?Or, am I using a 2D array incorrectly and will the image have to be created manually every time? If so, how would I output image if it is created in a separate method?
I am building an app, where I have to store the data eg: "hello ! how are you" in java as a string and then use scanner to get input and check if the entered word is present in the line stored. If it is stored then the entire sentence must be displayed. eg : if the stored string is "hello how are you"
if the entered string is "how", then the entire sentence "hello how are you" should be displayed.
I am having trouble with getting a user input once they enter it in to a JTextArea and then storing it in to a string value. See, I wanted the user to enter an answer in to the JTextArea, and then once I store it in to a string value, I would be able to use it later. I wanted to after storing the variable to print it on to a JLabel, but nothing is showing up... Heres my code.
static String usera[]= new String [10]; for (int i=0; i< usera.length; i++) { //These are the JTextArea names usera[0]= Question1.getText(); usera[1]= Question2.getText();
[Code].....
I already initialized the JLabels earlier in my code, and I did not feel the need to post all my code here. This is where I am trying to get the string variable and then printing it out.
When learning HashMaps in C++ I had to create the whole algorithm. In the code I created I could simply place a string into the method and it would store the names for me by turning the string into a integer and storing is accordingly. If there was a collision it would grow linearly at that location.
//play with Hash Tables void getNames(String names) { HashMap<String, Integer> map = new HashMap<String, Integer>(); map.put(names,22); }
How can I do this in Java. I read about them and look at examples and they all for the most part look like this.
public class MonthsName { static String monthsName[]; public static void main(String[] args) { String[] months = new String[13]; months[0] = null ;
[Code] .....
I keep getting 1 error that tells me this. Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0 at MonthsName.main(MonthsName.java:22) Java Result: 1
Just before that netbeans couldn't find the main class. I was wondering if it netbeans or my code that's wrong.
I am trying to make a program that calculates the change due in dollars and cents. The user inputs both the amount due and the amount tendered. My program only works with whole numbers?
I have built a binary tree, from a file. In each node, I am storing each word as a string, and an int frequency for each time the word occurs. For the assignment, I need to find how many words occur only once in the file. I wrote the program, but for some reason I am getting a number different from what my professor is expecting.
As far as I know, this file has loaded into the tree correctly, because all of my other answers in the assignment are correct. What am I doing wrong?
public void findUnique() { System.out.println("There are " + findUniqueWords(root, 0) + " unique words."); } private int findUniqueWords(Node subTree, int uniqueCount) { // Base Case: At the end of the branch if(subTree == null){ return uniqueCount;
I am trying to get a price of a certain show in a theatre but the problem is that i don't know how to use the method's String parameter:
/** * Gives the price of the show with a given place in the room * * @param place the place in the room (VIP, average seating, in the back) * @return price */ public double getPlaceprice(String place) { if (place !=null) { double p = place.getPrice(); // price= Double.parseDouble("place.getPrice()"); return p;
} return 0; }
Now I have a class called Place which has an attribute double price and a getter for price
public double getPrice() { return price;
So I somehow have to alter the String parameter Place to the object(class) Place, on which i can call the method getPrice()
At least, that's what i think i have to do. Where i go wrong?
this is part of a larger project but i figure if i can figure out this first step i can work the rest. I need to get a title from the user add it to a object array (i think thats what it is) and then when i call listAllItems(), items[] should be copied into a string array called listAllItems, and then printed, but currently im jusst having trouble i think making it an object and then make it an item in the items[], if i run case 3 the list it says null...
public class MediaItem { String title; MediaItem(){ } MediaItem(String title){
I am converting String to date object while converting this i am getting Run time Exception. Here in this code i am using String tokennizer reading a data from a text file. Here is my code
public static void main(String[] args)throws Exception { FileReader fr = new FileReader("g:abc.txt"); BufferedReader br = new BufferedReader(fr); String line = br.readLine();
I am making a function to search through the whole inventory to see if any of the Lamborghini object has a certain model name such as aventador, diablo, etc....
This is what I have but I figured there's a big mistake when I make it true / false; it's making it going through the list and what's return is the last one instead of saying there's such match in the whole list or not.
public boolean hasCarModel(String modelName){ boolean exist = false; for (Lamborghini lambo : inventory){ String carModelName = lambo.getModelName(); if(carModelName.equalsIgnoreCase(modelName)){
[Code] ....
I figured if I add break; under exist = true; it'll work because as soon as it found one match then it'll turn to true and break out the loop but I don't think this is the best way to do it right?
why my sub class object just gives me a blank when it comes to the String. It works just fine for the super class but when I get to the sub class the program just gives me a blank. I won't let me input anything for the String. On line 24 of the client I attempt to input a new String but it doesn't ever let me enter one so then any call to getName is just a blank.
I have altered my super and sub class as well as the client to try to get it to work. I tried a local variable in the client, I tried using protected in the super class, I tried a handful of other things.
import java.util.*; public class TryingItOutClient { public static void main(String[] args) { Scanner input = new Scanner(System.in);
//Scanner Test String stream2 = "ab34ef 56"; // create a new scanner with the specified String Object Scanner scanner = new Scanner(stream1); // find a string "World"
[Code] ....
Matched expression found by findInLine: 34
ef56
is new line? right?
The java.util.Scanner.nextLine() method advances this scanner past the current line and returns the input that was skipped. This method returns the rest of the current line, excluding any line separator at the end.
then 56 is in new line and it must return ef.What is the problem?
Suppose that you have an ArrayList and that it contains String objects. Which declaration of the ArrayList requires that objects retrieved using the get method be cast to Strings before calling a String method?
I. ArrayList a = new ArrayList(); II. ArrayList<Object> a = new ArrayList<Object>; III. ArrayList<String> a = new ArrayList<String>;
A. I only B. II only C. III only D. I and II only E. I, II, and III
I know that all of these are ways to declare an Array List, but I am unfamiliar with the last two since I usually just declare my Array Lists with the first option.
I have a little a problem with String object in this class ....
public class Personne { private String nom; private String prenom; private int age; public Personne(){ this(null, null, 0);
[Code] ....
When i call the class personne with the Personne() i get these errors in compiling-time :
Exception in thread "main" java.lang.NullPointerException at java.lang.String.<init>(Unknown Source) at Personne.setNom(Personne.java:18) at Personne.<init>(Personne.java:12) at Personne.<init>(Personne.java:8) at Main.main(Main.java:4) // The line wich i inisialize my object in my main method.
I have a date in the following String format "2013-03-28,19:37:52.00+00:00" and post processing I am converting this to following String as per prevailing logic "2013-03-28,19:37:52.00+0000" (This is existing code and no changes have been Made here for last few years) And the using this SDFormat i.e new SimpleDateFormat("yyyy-MM-dd,HH:mm:ss.Sz") for conversion to Date Object
We are suddenly getting this exception now can't figured out what has changed ?
java.text.ParseException: Unparseable date: "2013-03-28,19:37:52.00+0000" at java.text.DateFormat.parse(DateFormat.java:357)
I am trying to parse a XML string into `org.w3c.dom.Document` object.
I have looked at solutions provided [here](xml - How to convert String to DOM Document object in java? - Stack Overflow), [here](How to create a XML object from String in Java? - Stack Overflow) and a few other blogs that give a variation of the same solution. But the `Document` object's #Document variable is always null and nothing gets parsed.
Here is the XML
XMLMappingValidator v = new XMLMappingValidator("<?xml version="1.0" encoding="utf-8"?> " + "<mapping> " + "<container> " + "<source-container>c:stem.csv</source-container>
[Code] ....
When I call **v.getXML().toString()** I get `[#document: null]`
Clearly, the parse is failing. But I don't understand why.