Home Answers Viewqa Java-Beginners Determine if string is in class

 
 


BOB
Determine if string is in class
1 Answer(s)      9 months ago
Posted in : Java Beginners

I have an input of a string and a Car class. The string is the name of the car, which i have multiple in my linked list. I need to be able to go through my linked list of cars and determine which car to call by using the input string. I'm not sure if there's a .equal method to do this for i've tried the traditional way.

View Answers

July 27, 2012 at 12:12 PM


Here is a code where we have created a class Car. Then we have created another class in which we have stored the car object into linkedlist with some values. The code will then accept the car name from the user and display the price along with the car name.

import java.util.*;

class Car { 
    private String name; 
    private int price;

    public Car(String name, int price) {
            this.name = name;
            this.price = price;
    }

    public String getName() {
            return name;
    }

    public int getPrice() {
            return price;
    }
}

public class CarsList {
    public static void main(String args[]) {
    LinkedList<Car> carlist = new LinkedList<Car>();
    carlist.add(new Car("Tata Nano", 100440));
    carlist.add(new Car("Alto",  234230));
    carlist.add(new Car("Swift", 466450));
    carlist.add(new Car("Fusion" , 465656));
    carlist.add(new Car("IKon",   664460)); 
    carlist.add(new Car("Scorpio",705775)); 

    Scanner input = new Scanner(System.in);
    System.out.print("Enter car name: ");
    String carname = input.nextLine();
    for(Car s : carlist){
        if (carname.equals(s.getName())) {
            System.out.println(s.getName() + "=> " + s.getPrice());
        }
    }
   } 
 }









Related Pages:
Determine if string is in class
Determine if string is in class  I have an input of a string and a Car class. The string is the name of the car, which i have multiple in my linked.... import java.util.*; class Car { private String name; private int price
Determine Average by removing Largest and Smallest Number
Determine Average by removing Largest and Smallest Number In this section, you... and then determine the average. For this, an user is allowed to input 10 numbers...: import java.util.*; class Calculate { public static int
Determining the Word Boundaries in a Unicode String
will learn how to determine the word boundaries in a unicode string. Generally, we use split() method and StringTokenizer class to break the string into words... java.text.*; public class WordBoundaries { public static void main(String
Determining the Character Boundaries in a Unicode String
Determining the Character Boundaries in a Unicode String In this section,  you will learn how to determine the character boundaries in a string. By determining the character boundaries, you will be able to break the string
Determining the Sentence Boundaries in a Unicode String
Determining the Sentence Boundaries in a Unicode String In this section, you will learn how to determine the sentence boundaries in a unicode string. From the previous section, you all are aware of BreakIterator class. This class
Given a code listing, determine whether it is a legal and appropriate way to programmatically access a caller's security context.
Given a code listing, determine...;Next    Given a code listing, determine whether... class // to access security information: // Returns the principal
(ii) String and String Buffer Class
String and String Buffer Class  differences between : String and String Buffer Class
(ii) String and String Buffer Class
(ii) String and String Buffer Class  difference between String and String Buffer Class
(ii) String and String Buffer Class
String and String Buffer Class  difference between String and String Buffer Class... between String and StringBuffer 1) String object is immutable
String
String  how to add spaces with string functions.?   Hi Friend, Try the following code: class AddSpacesToString { public static String addSpaceToRight(String s, int n) { return String.format("%1$-" + n + "s
string
string  a java program using string function to input any string and print the same in alphabetical order   import java.util.*; class ArrangeStringAlphabetically { public static void main(String[] args
string
Friend, Either you can use split() method: import java.util.*; class ExtractWords { public static void main(String[] args) { Scanner input=new Scanner(System.in); System.out.print("Enter String
String
characters in string?   import java.util.*; class RemoveDuplicateCharatcersFromString { public static String removeDuplicates(String s... < s.length(); i++) { String st = s.substring(i, i + 1
string
*; import java.io.*; public class FirstLetter{ public static String capitalizeFirstLetter( String str ) { final StringTokenizer st = new StringTokenizer( str...string  a java program to input a string and display the string
string
; public class StringTest { public static void main(String [] args...string   just i want to a program in a short form to the given string in buffered reader for example input string: Suresh Chandra Gupta output: S. C
string
and also displaying that contain word? Like I want to find "a" in the string... and a character. It then count the occurrence of that character in the string and display the words that contains that character. import java.util.*; public class
string
string  program for String reverse and replace in c,c++,java... code: import java.util.*; class ArrayReverse { public static void main(String[] args) { String array[]=new String[5]; Scanner input
String Class implementation in API
String Class implementation in API  Hi all, I was confused ,when am looking into java String class single argument constructor into that we... we send String as argument for String class
String tokenizer class
String tokenizer class  Hai... What is string tokenizer class? & what's its purpose
String tokenizer class
String tokenizer class  Hai... What is string tokenizer class? & what's its purpose
String tokenizer class
String tokenizer class  Hai... What is string tokenizer class? & what's its purpose
String intern()
the intern() method of String class. We are going to use intern() method of String...; operator to determine which Strings are equal. Basically an intern string is the one.... The String class maintains a pool of strings privately, which is empty initially
FontMetrics
Java NotesFontMetrics The java.awt.FontMetrics class is used to determine... of a character or string. ascentThe distance above the baseline of a character or string. descentThe distance below the baseline of a character or string
Class
Class, Object and Methods       Class : Whatever we can see in this world all the things... is termed as a class. All the objects are direct interacted with its class
Identify the interface and method for each of the following: retrieve the session bean's remote home interface, retrieve the session bean's local component interface, determine if the sessio
local component interface, determine if the session bean's caller has..., retrieve the session bean's local component interface, determine...(); java.security.Principal getCallerPrincipal(); boolean isCallerInRole(String roleName
String End with Example
String End with Example       This section tells you, how to determine the given string ends with specified string. The following program helps you to check whether the given
java class string - Java Beginners
java class string  Write a program that reads three strings; then appends to the first string the string formed when extracting from the second string all the characters until the first occurrence of the third string
Convert String to Class - JSP-Servlet
. Reading job name, class name, day & time using xml file only. Problem is while reading class name, retrieve as a string format but Quartz required in "Class" format...Convert String to Class  Hi all, I am using Quartz as a scheduler
String Class in Action Script3
.style1 { font-size: medium; } String Class in Action Script3:- String class is a data type. String class provides methods for access... types of String class objects. String class have different types of constructors
wrapper class concept
wrapper class concept  Write a Java class that stores an integer item id, a string item name and a float price. Store all these in a String member... these different types to the String member. Provide a get method to retrieve
Determining the type of Character
to determine the type of a character. You can use the methods of Character class to determine the properties of a character. This class provides several methods.... To determine the character type we have used some static method of Character
To Determine whether the Session is New or Old
To Determine whether the Session is New or Old       In this program we are going to make one....  To make this program firstly we need to make one class named
how to pass a string from one class to another
how to pass a string from one class to another  hi all, Good morning. I am trying to develop a coding pass a string from one class and declare in other class. the string which i need to pass is the data from an file and i want
Date Class with Single String parameter constructor example
.style1 { font-size: medium; } Date class with single string parameters to the Date() constructor example:- The Date class have a single string parameterized constructor. If user pass a string parameter in the date class
MovieRating class - Java Beginners
class to determine whether the child can watch the movie. 14.Add...*; class Child extends Human { String cName ="Joe"; int childAge...(String MovieRating); } There is some missing in the Code in class Family
Writing code with multiple Class Methods and String Arrays
Writing code with multiple Class Methods and String Arrays  So what I... input. It has to have multiple classes so I will have a main class, and a class... In these classes I need to create string arrays that contain artist names, and be able
Writing code with multiple Class Methods and String Arrays
Writing code with multiple Class Methods and String Arrays  So what I... input. It has to have multiple classes so I will have a main class, and a class... In these classes I need to create string arrays that contain artist names, and be able
class Math - Java Beginners
to you. public class MathFunction { public static void main(String s...class Math  "Helo man&sir can you share or gave me a java code hope... the ceil(),floor(),and abs() methods to determine the smallest whole number
String lastIndexOf(String str)
the lastIndexOf(String str) method of String class. We are going to use lastIndexOf(String str) method of String class in Java. The description of the code... String lastIndexOf(String str)     
String Compression using Deflater class in java
String Compression using Deflater class in java. In this tutorial, we will define the use of Deflater class. The Deflater class is used to compressed data by using ZLIB library. The Deflater class is available in java.util.zip package
string wap
string wap  WAP to convert stack trace in to a String . Write that Stack Trace in Error Log File along with the class name and Method Name that has thrown the error.in java language
String equalsIgnoreCase(String Str)
explanation about the equalsIgnoreCase(String Str) method of String class. We are going to use equalsIgnoreCase(String Str) method of String... String equalsIgnoreCase(String Str)   
String indexOf(String str)
the indexOf(String str) method of String class. We are going to use indexOf(String str) method of String class in Java. The description of the code is given below... String indexOf(String str)     
reversing a string
reversing a string  how to reverse a string without using string function   class ReverseString { public static void main(String[] args) { String str="Hello World"; String st[]=str.split
C String length
C String length       In this section, you will learn how to determine the length of a String in C. You can see in the given example, we have declared a string and initialize
reverse string
reverse string  how to reverse a string without changing its place   Hi Friend, Try this: import java.util.*; public class ReverseString{ public static void main(String[]args){ Scanner input=new Scanner
searching string
searching string   how to write a program for searching a string   Hi Friend, Try this: import java.util.*; class SearchString{ public static void main(String[] args){ Scanner input=new Scanner(System.in
String question
String question  which method is used in java to eliminate the duplicate elements in String?   import java.util.*; class RemoveDuplicates{ public static void main(String[] args){ String[] str = new String[] { "Where
string related
string related  As with any other object, you can create String objects by using the new keyword and a constructor. The String class has thirteen constructors that allow you to provide the initial value of the string using
Java file basename
Java file basename In this section, you will learn how to determine... used built in function getName() of File class to  get the base name for the given file path. Here is the code: import java.io.File; public class

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.