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"); }
'm working on a program that is to act as an inventory for a book store. There are two classes (Store and Book), and numerous methods which you will see in my code. The program is supposed to read in an inventory from a file which contains 10 books (each row in the file represents a book with an ISBN number, the price of the book, and the number in stock)and store this file into an array of type Book[]. There is then to be another method to process a purchase interactively. The Store class is also to keep a count of how many books were sold at the time of closing and also how much was made that day.
I'm having some difficulty figuring out how I should set up the purchase processing method though. I've written out how I think it would be set up (not too familiar with the terminology, but I think it would be called pseudo code?) I'll include that now along with a few other notes.
public Book[] purchase(String isbn, double price, int copies) { int itemsSold; double totalMade; Scanner input = new Scanner(System.in); System.out.println("Please enter the ISBN number of the book you would like to purchase: ");
[Code] ....
So basically here's what needs to be accomplished with this portion of code:
1.Ask the user to enter the ISBN number of the book they'd like to purchase. 2.Search the array for the object that contains that ISBN. 3.If the ISBN isn't found in the array, display a message stating that we don't have that book. 4.If the ISBN is found but the number of copies is 0, display a message saying the book is out of stock. 5.If the ISBN is found and the number of copies is greater than 0, ask the user how many copies they'd like to purchase. 6.If the number they enter is greater than the number of copies of that book in the array, display a message stating that and ask them to enter another quantity. 7.Once the purchase is complete I need to update the array by subtracting the number of copies of that particular book that was purchased. 8.Print the updated array. 9.Display a count of how many books were purchased, and how much money was made from the purchase.
I know that code has a lot of holes in it, but I'm just trying to get everything together and figure out how to do each step.
The part I'm stuck on right now is trying to figure out how to search the array to first see if the ISBN that was entered is in the array, and then to find the number of copies of the book with that ISBN number.
In case it will visualize what this array looks like, here's a print out of the array from a sample run I just did.
An array which contain a list of names. I let for a user input and I use that to search through the array. For example lets say the string name "Christian" is stored inside the names array and the user types in Chri, the program looks in the array and finds a name that contains Chri and prints them out. How do I go about doing this?
An array which contain a list of names. I let for a user input and I use that to search through the array. For example lets say the string name "Christian" is stored inside the names array and the user types in Chri, the program looks in the array and finds a name that contains Chri and prints them out. How do I go about doing this?
I am currently working on a application for a car park system. It uses GUI created by myself and holds 15 parking spaces. The user has the option to add, delete or search for a specific car. When the user adds a new car, details of the car are entered, the cars registration number (saved as a string), and the user had to check one raido button if the car is expensive, large or normal.
Once this information is entered a new instance of a vehicle will be created and the bay the car is allocated to turns green and stored in one of three arrays(expensive, normal or large). I also have a fourth array for creating the parking spaces.Each array can only hold 5 vehicles apart from the fourth which can hold all 15. When searching for a vehicle the user enters the registration of the vehicle they want to find, but I have to search through all three arrays to find it, and if it does not exist showing a message saying so.These are my three arrays
public static ParkingBay[] regularBays = new ParkingBay[5]; public static ParkingBay[] largeBays = new ParkingBay[5]; public static ParkingBay[] expensiveBays = new ParkingBay[5];
String Registration; - saves registration entered from add form String RegistrationNumber; - saves registration number from search form
I need to search to see if RegistrationNumber is in either of the three arrays if not show a message saying otherwise
I have an assignment for my intro class that requires me to read from a file that is a list of songs, their artists, and the year they were released. As seen below, a print line statement prompts the user to enter an artist name, and then it uses a buffered reader to gain input, and then it is supposed to match that input.I realize that this is not a complete statement, but I'm mostly concerned with getting the .indexOf statement to work.Currently it only returns the first object in the array.
for(int i = 0; i < song.length; i++) { System.out.println("Enter an Artist name"); String input1 = kb.readLine(); if (song[i].getArtist().indexOf(input1) > -1) { /*tried changing -1 to -2. When I do, it returns the first array entry, regardless of what I input*/ System.out.println(song[i].toString()); } }
public Polygon polygonFrom(Point[] corners) { // method body goes here }
So from what I understand this is a constructor method for a Polygon object from the Polygon class. What I dont get is the name of the method polygonFrom()
Shouldn't a constructor for a Polygon just have the same name as the class? Because from earlier examples in the tutorial it seems to me that this is what has been done
For example:
public Bicycle(int startCadence, int startSpeed, int startGear) { gear = startGear; cadence = startCadence; speed = startSpeed; }
Java SE Runtime Environment build 1.8.0..This is part of the code:
public static int addAddress (String[] number, boolean[] front, double[] total) { int num = 0; double ffee = 0; /*boolean value = false;*/
[code]...
I have tried using the line of code commented out, /*boolean value = false;*/. However, another error is displayed. The compiler shows the following...
Inspection.java:33: error: incompatible types: boolean cannot be converted to boolean[] front[num]= defineFront(num, value); ^ Note: Some messages have been simplified; recompile with -Xdiags:verbose to get full output error...I know that boolean values are by default stored as false, once you create the array. However, I'm having trouble passing the variable to the method.
I am working on an independent project it is a simple little text based rpg that will run in a counsel window. I have an object for Character that is creating during a CreateCharacter method. I want the play to be able to enter a character that will open up a menu that displays things like the name and health and stuff of the character from the object created in CreateCharacter, but because I have it in a different class I don't know how to reference the object made in CreateCharacter.
I have it in 6 files
Character --- Object with getters/setters for things like name, age, race, class, ect MainMenu --- Displays title and promts for new game and quit CreateCharacter --- Walks through and sets all values in Character Stats --- Keeps the players stats (health, attack, ect) in an array Intro --- Beginning demo thing (not really important for this question) Menu --- Displays all current user stats (Having issues with this one)
I got the correct output here. But now I want to generalize my method into a utility class so that I can reuse the same method for setting response data directly to respective beans as given below:-
My question is how will I pass the bean object in my utility class?
public static Object getResponseData(String response,[b]String bean[/b]) throws Exception { ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false); JsonNode root = mapper.readTree(response);
So I want to know how in Java you can pass a unkown type into a method (type can be an int, double, or a user defined object) and return that unkown type.
example of what I want: Java Code: public (unknowntype)[] method2 ((unknowntype)[]) //Process Data //unknowntype.process(); return (unknowntype); } mh_sh_highlight_all('java');
I know in C you can use void pointers and in c++ we have templates but I do not know how java handles this. Also I want to know if it is possible to call a method in the unknowntype.
I just kinda get stuck when it comes to passing values into constructors, using main method or static method functionality. In theory i kind of understand how it work but when i type it, it's totally different! I have to have a junit test too but i guess i could do that in the end.
I have attached the assignment. So, how to proceed with this:
public class Flight { int flight_number, capacity, number_of_seats_left; String origin, destination; String departure_time; double original_price;
Can we pass array as a cmd line argument as follows ?
>java TestRun file[], number if yes, in the main(), how do we capture this array ? public static void main(String [] args){ String [] files = args1 ; // or will it be String [] files = args1[]; }
currently I am doing my java web application project ,and it has following steps 1) Upload the txt files 2) java servlet gets the txt file's url , read the data and do the calculation 3) pass the results
I almost finished the second step , and working on the first step .Since there are so many input files at a given time , i have to use drag and drop method to get the file's location.how to pass file's path to servlet.( servlet code can read the data from the given txt file path )software used - tomcat and netbeans 8.0
I am trying to make a class definition file for an ASCII File.
Ultimately, I want to be able to add methods to allow the image produced by the file to be printed normally, then printed with various manipulations.
However, for some reason, whenever I try to run the program to test my normalPrint method, it terminates without printing anything.
I think this is because the array's values width and height are not within the scope of the method. I tried passing the array as a parameter for the method like so:
Java Code:
public void normalPrint(char [][] poop){ //method here } mh_sh_highlight_all('java');
But it gave me an error that stated
"The method normalPrint(char[][]) in the type asciiFile is not applicable for the arguments ()"
Class Definition:
Java Code:
import java.io.*; import java.util.Scanner; public class asciiFile { int height; int width;
Long story short: The program takes user values (temperature) and converts them to the opposite (C >> F / F >> C)
I originally started this program with three separate arrays but then decided that it would be a good opportunity to use a two-dimensional array and one other.
The two-dimensional array has 2 rows, 10 columns. The second is a normal String array ...
Java Code:
String[][] myTemperatures = new String[2][9]; String inputAssembly[] = new String[9]; mh_sh_highlight_all('java');
I prompt the user for to enter temperature values, using a GUI and jbutton to distinguish F/C. Each time the user clicks 'continue', the values are stored into the two-dimensional array. One row holds the temperature, the other holds the C or F designation.
Java Code:
// CONTINUE BUTTON CLICK ACTIONS class ContinueButtonListener implements ActionListener{ @Override public void actionPerformed(ActionEvent arg0) { // TODO Auto-generated method stub input = view.getTempValue();
[Code] ....
This is where I am experiencing the trouble and I cannot seem to get the Debug to work properly here. When the two-dimensional array is full OR the user clicks 'calculate' instead of 'continue', the Calculate event is performed via an ActionListener.
Java Code:
// CALCULATE BUTTON CLICK ACTIONS class CalculateButtonListener implements ActionListener{ @Override public void actionPerformed(ActionEvent arg0) { // TODO Auto-generated method stub String hold; Double temp;
And I get a ton of errrors ...
Java Code:
Exception in thread "AWT-EventQueue-0" java.lang.NumberFormatException: For input string: "[Ljava.lang.String;@7441b1fd" at java.lang.NumberFormatException.forInputString(Unknown Source) at java.lang.Integer.parseInt(Unknown Source) at java.lang.Integer.parseInt(Unknown Source)
[Code] ....
I imagine the issue lies within how I am handling the two-dimensional array in the CALCULATE event and/or converting the String[][] to String then parsing to an Integer.
Would this be better done is separate arrays (not using one two-dimensional, but storing 34C, 45F ... in one. I think this would be difficult for me to parse for conversions).
how to translate it into Java language due to lack of experience (2 weeks). My solution I've formed in my head is: create a new array for the numbers that are in improvement and then declare a "max" variable. Check which array's length is higher and print that length. What I don't know to do is: I don't know how to create a new array for each numbers that are passing through the condition.
Note: I couldn't find anything on internet about my problem so that's why I'm here.
My code is this one:
class MyClass { static int progresie=0; public static void longest_improvement(Integer[] grades) { for(int i=0;i<grades.length-1;i++){ if(grades[i]<=grades[i+1]){ progresie ++; } } System.out.println(progresie); } }
I am trying to pass an object of type Product p to my editProduct method, however trying to call p.getName(); doesn't work and throws a NullPointerException. The same kind of thing works for my displayRecord method (in a different class) and I can call .getName() on Product p, also passed as an argument to that method. Below is my editProduct class. The NullPointerExcepion is being thrown at line 61 (i.e., nameField.setText(p.getName());).
I don't know if I explained right, so here's a line thing of how the classes relate:
And as a side note: adding the line p = new Product(); fixes it and successfully runs the class (including the Save and Quit parts) but obviously I want it to specifically refer to the Product I pass to the method.
I'm asking a question because I don't understand how Product p could possibly be null, because the argument is passed through my DisplayRecord class, which also takes a Product p argument and works. In that class, I have declared Product prod = p; and prod is what I am passing to editProduct.