-
Notifications
You must be signed in to change notification settings - Fork 8
/
RentDriver.java
94 lines (94 loc) · 4.05 KB
/
RentDriver.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
//*******************************************************
// RentDriver.java.
// tester for the rent class
// Author: liron mizrahi
//*******************************************************
import java.util.Scanner;
public class RentDriver
{
public static void main(String[] args)
{
// creat scanner object
Scanner scanner = new Scanner(System.in);
// print to user
System.out.println(" Please enter the name, car, pick date, return date");
String name = scanner.nextLine();
// take user input for car object
System.out.println("Please enter Car information: \n ID:(have to be seven digits) \n Type: (A,B,C,D) \n Brand:(car brand) \n Is Manual:(true or false)");
int id = scanner.nextInt();
char type = scanner.next().charAt(0);
System.out.println("now string");
String brand = scanner.next();
boolean isManual = scanner.nextBoolean();
Car car = new Car(id, type, brand, isManual);
// take input for pick date
System.out.println("Please enter the day, month, year" + " of the pick date");
// take user input
int pickDay = scanner.nextInt();
int pickMonth = scanner.nextInt();
int pickYear = scanner.nextInt();
// making Date object
Date pickDate = new Date(pickDay, pickMonth, pickYear);
// take input for return date
System.out.println("Please enter the day, month, year" + " of the return date");
// take user input
int returnDay = scanner.nextInt();
int returnMonth = scanner.nextInt();
int returnYear = scanner.nextInt();
// making Date object
Date returnDate = new Date(returnDay, returnMonth, returnYear);
// make a rent object
Rent rent = new Rent(name, car, pickDate, returnDate);
// print to user
System.out.println(" Please enter the name, car, pick date, return date");
String name1 = scanner.next();
// take user input for car object
System.out.println("Please enter Car information: \n ID:(have to be seven digits) \n Type: (A,B,C,D) \n Brand:(car brand) \n Is Manual:(true or false)");
int id1 = scanner.nextInt();
char type1 = scanner.next().charAt(0);
System.out.println("now string");
String brand1 = scanner.next();
boolean isManual1 = scanner.nextBoolean();
Car car1 = new Car(id1, type1, brand1, isManual1);
// take input for pick date
System.out.println("Please enter the day, month, year" + " of the pick date");
// take user input
int pickDay1 = scanner.nextInt();
int pickMonth1 = scanner.nextInt();
int pickYear1 = scanner.nextInt();
// making Date object
Date pickDate1 = new Date(pickDay1, pickMonth1, pickYear1);
// take input for return date
System.out.println("Please enter the day, month, year" + " of the return date");
// take user input
int returnDay1 = scanner.nextInt();
int returnMonth1 = scanner.nextInt();
int returnYear1 = scanner.nextInt();
// making Date object
Date returnDate1 = new Date(returnDay1, returnMonth1, returnYear1);
// make a rent object
Rent rent1 = new Rent(name1, car1, pickDate1, returnDate1);
// chek the equals method
if (rent.equals(rent1))
{
System.out.println("Same");
}
else
{
System.out.println("not the same");
}
// check toString method
System.out.println(rent.toString());
System.out.println(rent1.toString());
// check how much rent day left
System.out.println("the days left is: " + rent.howManyDays());
// get the price of the rent
System.out.println("rent price is: " + rent.getPrice());
System.out.println("rent1 price is: " + rent1.getPrice());
// check the overlap method
Rent overlapRent = rent.overlap(rent1);
System.out.println("overlap rent: " + overlapRent.toString());
// close the scanner object
scanner.close();
}// end of method main
}// end of class RentDriver