如何通过匹配价格获取特定名称
在此如何通过从用户输入价格来获取汽车名称。
public static void main(String[] args) {
Car toyota = new Car("Toyota", "$10000", "300" + "2003");
Car nissan = new Car("Nissan", "$22000", "300" + "2011");
Car ford = new Car("Ford", "$15000", "350" + "2010");
ArrayList<Car> cars = new ArrayList<Car> ();
cars.add(toyota);
cars.add(nissan);
cars.add(ford);
}
In this how to get car name by entering price from user.
public static void main(String[] args) {
Car toyota = new Car("Toyota", "$10000", "300" + "2003");
Car nissan = new Car("Nissan", "$22000", "300" + "2011");
Car ford = new Car("Ford", "$15000", "350" + "2010");
ArrayList<Car> cars = new ArrayList<Car> ();
cars.add(toyota);
cars.add(nissan);
cars.add(ford);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
关于价格搜索的事情是,除非您可以使用价格范围搜索,否则搜索某些东西确实不好恰好是您正在搜索的项目。此外,价格并不总是四舍五入到最接近的一千,因此,如果您想根据价格为10000(无论是面额)的物品搜索物品,那么您会错过那些10324、10156.99等的物品但是。当然,您可以通过代码将其源为自动应用范围,从而为所提供的价格提供上限值。如果需要,下面可运行的方法实际上可以做到这一点。
在代码中阅读评论:
汽车类:
The thing about price searching is that it really is no good to search for something unless you can search with a price range, unless of course you happen to know exactly what the price happens to be for the item(s) you're searching. Also, prices are not always rounded to the nearest thousand, so if you want to carry out a search for an item based on say a price of 10000 (whatever denomination) then you will miss those items that are 10324, 10156.99, etc, etc. A range however of: 10000-10999 would most likely be a more viable option. Of course you can source this in code to automatically apply a range by providing an upper range value to the price supplied. The method provided in the runnable below can actually do this if so desired.
Read the comments in code:
The Car Class:
如果使用Java版本&gt; = 8,则可以使用流。
If you are using java version >= 8, you can use streams.