Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize car Rental system by Java

2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly explains "Java how to achieve car rental system", the content of the article is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in depth, together to study and learn "Java how to achieve car rental system" bar!

Topic: design a simple car rental system, realize car rental, and count the type of car, the number of passengers, the number of passengers, and the total rental price.

1. Program analysis

Step1: create a car class

Step2: create a rental class to complete the car rental task

2. Program realization

Car.java

Package Jack_Cui;/* * Project: Lease System * Comments: basic class of automobiles, passenger cars, trucks and pick-up trucks * JDK version used: JDK1.8 * Author: Jack-Cui * Create Date: 2016-8-29 * / public class Car {private String name private int i_price / / car rental price / * out-of-class access, you need to write / read data members s_name, i_price*/public String getName () {return name;} public void setName (String name) {this.s_name = name;} public int getPrice () {return itemprice;} public void setPrice (int price) {this.i_price = price;} via set and get methods

Lease.java

Package Jack_Cui;import java.util.Scanner / / Import Scanner Obtain user input information / * * Project: Lease System * Comments: rental * JDK version used: JDK1.8 * Author: Jack-Cui * Create Date: 2016-8-29 * / public class Lease {public static void main (String [] args) {System.out.println ("Welcome to the answer car rental system\ ndo you want to rent a car: 1 Yes\ t0 No") / / print prompt int i_finalPrice = 0; / / final total price int i_finalPersonNum = 0; / / final total carrying capacity int i_finalGoodsNum = 0; / / final total carrying capacity StringBuffer bufer_sBusName = new StringBuffer (); / / record the name of the rental car StringBuffer bufer_sTrunkName = new StringBuffer () / / record the name of the rental car Scanner input = new Scanner (System.in); / / get the user input information if (input.nextInt ()! = 1) {System.out.println ("Thank you for coming, goodbye!") ; input.close (); / / close the user to enter return;} System.out.println ("the type of car you can rent and its price list:\ n serial number\ t car name\ t rent\ t capacity"); Bus car1 = new Bus ("Audi A4", 500Quin4) / / instantiate Audi A4Bus car2 = new Bus ("Mazda 6", 400jur4); / / instantiate Mazda 6Bus car3 = new Bus ("Golden Dragon", 800jury20); / / instantiate Jinlong Trunk car4 = new Trunk ("Songhua River", 400magin4); / / instantiate Songhua River Trunk car5 = new Trunk ("Iveco", 10001,520) / / instantiate Iveco Pickup car6 = new Pickup ("pickup Snow 6", 450 cars 4); / / instantiate pickup snow 6Car [] cars = {car1,car2,car3,car4,car5,car6}; / * display vehicle information * / for (pickup I = 0; I

< cars.length; i++){ System.out.println((i + 1) + ".\t" + cars[i].toString()); } System.out.println("请输入您要租汽车的数量:");int i_num = input.nextInt(); //记录租车数量int[] i_car = new int[i_num]; //记录租车序号for(int i = 0; i < i_num; i++){ System.out.println("请输入第" + (i + 1) + "辆车的序号:");int i_key = input.nextInt();if(i_key >

= 1 & & i_key

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report