Automotive rental system encapsulation. Inheritance and polymorphism, car rental Polymorphism
Summary: class methods, constructor, value type, and reference type are used in the car rental system.
Store data using a set, and use encapsulation, inheritance, polymorphism creation, and Operation classes
1. Car Rental.. Display all the taxis in the system. Select the taxi you want to rent and enter the taxi user
The Code is as follows:
1 public Dictionary <string, Vehicle> vehicles; // The set of rental vehicles to save 2 public Dictionary <string, Vehicle> effectvehicles; // save 3 private void Form1_Load (object sender, EventArgs e) 4 {5 // load data to 6 vehiclee () in the rental car set (); 7 // The default text box of the loaded weight is not available 8 this.txt zai. readOnly = true; 9} 10 // construct two cars and two trucks 11 public void vehiclee () 12 {13 // instantiate a collection of unrented Dictionary types 14 vehicles = new Dictionary <string, Vehicle> (); 15 Car dd = new Car ("pink", 99999, "Beijing P1111", "Jaguar TK07", 1); 16 Truck ds = new Truck ("blue", 150, "Yu C6644", "Yangtze River cargo", 2, 40); 17 vehicles. add (dd. licenseNo, dd); 18 vehicles. add (ds. licenseNo, ds); 19 // instantiate the 20 rows tvehicles = new Dictionary of the rented Dictionary type <string, Vehicle> (); 21 // taxi out 22 Car = new car ("white", 240, "Beijing PC9K11", "Audi A8", 3 ); 23 Truck truck = new Truck ("black", 582, "Jing AP6666", "Optimus Prime", 5, 30); 24 hour tvehicles. add (car. licenseNo, car); 25 effectvehicles. add (truck. licenseNo, truck); 26 car. login User = this.txt name. text; 27 28} 29 public void PrintVehicles (Dictionary <string, Vehicle> rnotrent, ListView lvshow) 30 {31 lvshow. items. clear (); 32 foreach (Vehicle item in rnotrent. values) 33 {34 ListViewItem lvitem = new ListViewItem (item. licenseNo); 35 if (item is Car) 36 {37 lvitem. subItems. add (item. name); 38 lvitem. subItems. add (item. color. toString (); 39 lvitem. subItems. add (item. yearsOfService. toString (); 40 lvitem. subItems. add (item. dailyRent. toString (); 41 42} 43 if (item is Truck) 44 {45 lvitem. subItems. add (item. name); 46 lvitem. subItems. add (item. color. toString (); 47 lvitem. subItems. add (item. yearsOfService. toString (); 48 lvitem. subItems. add (item. dailyRent. toString (); 49 lvitem. subItems. add (Truck) item ). load. toString (); 50} 51 lvshow. items. add (lvitem); 52} 53}
54 // Car Rental 55 private void button2_Click (object sender, EventArgs e) 56 {57 if (txtname. text = "") 58 {59 MessageBox. show ("Please enter the name of the user to rent again! Oh "); 60 return; 61} 62 // remove the A63 from the referable vehicle set // Add A to the referable vehicle set 64 if (listView1.SelectedItems. count> 0) 65 {66 string number = listView1.SelectedItems [0]. text; 67 Vehicle ve = vehicles [number]; 68 vehicles. remove (number); 69 PrintVehicles (vehicles, listView1); // rebind ListView70 javastvehicles. add (number, ve); 71 MessageBox. show ("rented. "," Prompt! ", MessageBoxButtons. OK, MessageBoxIcon. information); 72} 73} 74 // refresh 75 private void button#click (object sender, EventArgs e) 76 {77 PrintVehicles (vehicles, listView1); 78}
1 // Close form 2 private void button6_Click (object sender, EventArgs e) 3 {4 this. Close (); 5}
2. return the car. Select the vehicle information in the return list, enter the number of rental days, and calculate the rent
// Settlement private void button3_Click (object sender, EventArgs e) {if (textBox2.Text = string. Empty) {MessageBox. Show ("Enter the rental time! "); Return;} // 01. remove car A from the rented collection // 02 and add car A to the rented car string number = listView2.SelectedItems [0]. text; Vehicle ve = fig [number]; fig. remove (number); PrintVehicles (effectvehicles, listView2); // rebind ListView vehicles. add (number, ve); ve. required date = Convert. toInt32 (textBox2.Text); double money = 0; money = ve. calcPrice (); MessageBox. show ("you need to pay" + money + "");} // refresh private void button4_Click (object sender, EventArgs e) {PrintVehicles (effectvehicles, listView2 );}
3. warehouse receiving for new users. Enter the license plate number, model, color usage time, and daily rent of the vehicle. If a truck needs to input the truck's load,
1 // warehouse receiving 2 private void button5_Click (object sender, EventArgs e) 3 {4 if (txthao. text = string. empty | txtxing. text = string. empty | cmdse. text = string. empty | txtshijan. text = string. empty 5 | txtmei. text = string. empty) 6 {7 MessageBox. show ("Please enter all in the warehouse! "); 8} 9 else10 {11 string linno = txthao. text; 12 string xing = txtxing. text; 13 string color = cmdse. text; 14 int time = Convert. toInt32 (txtshijan. text); 15 double zu = Convert. toDouble (txtmei. text); 16 if (radioButton1.Checked) 17 {18 Car dd = new Car (color, zu, linno, xing, time); 19 vehicles. add (linno, dd); 20} 21 if (radioButton2.Checked) 22 {23 24 int load = Convert. toInt32 (txtzai. text); 25 Truck ds = New Truck (color, zu, linno, xing, time, load); 26 vehicles. Add (linno, ds); 27} 28 MessageBox. Show ("added successfully @! "); 29} 30} 31 // switch to auto load to a 32 private void radioButton1_CheckedChanged (object sender, EventArgs e) 33 {34 this.txt zai. readOnly = true; 35} 36 // switch to the truck and add clear all text boxes 37 private void radioButton2_CheckedChanged (object sender, EventArgs e) 38 {39 this.txt hao. text = string. empty; 40 this.txt mei. text = string. empty; 41 this.txt name. text = string. empty; 42 this.txt shijan. text = string. empty; 43 this.txt xing. text = string. empty; 44 this.txt zai. text = string. empty; 45 this.txt zai. readOnly = false; 46}