Professional Documents
Culture Documents
CS4001NI Programming
I confirm that I understand my coursework needs to be submitted online via Google Classroom under the
relevant module page before the deadline in order for my assignment to be accepted and marked. I am
fully aware that late submissions will be treated as non-submission and a marks of zero will be awarded.
Contents
1) Introduction ................................................................................................................. 1
2) Class Diagrams: .......................................................................................................... 2
3) Pseudocodes .............................................................................................................. 6
a. Vehicle class pseudocode ...................................................................................... 6
• Vehicle Constructor Method ............................................................................... 6
• Method getVehicleID () ...................................................................................... 6
o Method getVehicleName ()................................................................................. 7
• Method getVehicleWeight () ............................................................................... 7
• Method getVehicleColor ().................................................................................. 7
• Method getVehicleSpeed () ................................................................................ 8
• Method setVehicleWeight () ............................................................................... 8
• Method display ()................................................................................................ 8
b. Autorickshaw Methods Pseudocodes ...................................................................... 9
• Autorickshaw Constructor Method ..................................................................... 9
• Method getEngineDisplacement () ................................................................... 10
• Method getTorque () ........................................................................................ 10
• Method getNumberofSeats () ........................................................................... 11
• Method getFuelTankCapacity () ....................................................................... 11
• Method getGroundClearance ()........................................................................ 11
• Method getChargeAmount () ............................................................................ 12
• Method getBookedDate () ................................................................................ 12
• Method getisBooked () ..................................................................................... 13
• Method setChargeAmount () ............................................................................ 13
• Method setNumberofSeats () ........................................................................... 13
• Method Book ()................................................................................................. 14
• Method Display () ............................................................................................. 14
c. Electric Scooter Methods Pseudocodes ................................................................ 15
• Electric Scooter Constructor Method................................................................ 15
• Method getRange () ......................................................................................... 16
• Method getBatteryCapacity ()........................................................................... 16
• Method getPrice ()............................................................................................ 17
• Method getChargingTime () ............................................................................. 17
• Method getBrand () .......................................................................................... 18
• Method getMileage () ....................................................................................... 18
• Method gethasPurchased () ............................................................................. 18
• Method gethasSold () ....................................................................................... 19
• Method setPrice () ............................................................................................ 19
• Method setBrand () .......................................................................................... 19
• Method sell () ................................................................................................... 20
• Method display ().............................................................................................. 21
4) Methods and their Descriptions ................................................................................. 21
Vehicle Class Constructor Method............................................................................. 22
Vehicle Class Getter Methods ................................................................................... 22
Vehicle Class Setter Methods .................................................................................... 23
Vehicle Class Display Method ................................................................................... 23
Autorickshaw Class Constructor Method ................................................................... 23
Autorickshaw Class Getter Methods .......................................................................... 24
Autorickshaw Class Setter Methods .......................................................................... 24
Autorickshaw Class Book Method ............................................................................. 25
Autorickshaw Class Display Method .......................................................................... 25
Electric Scooter Class Constructor Method ............................................................... 25
Electric Scooter Getter Method .................................................................................. 26
Electric Scooter Setter Method .................................................................................. 26
Electric Scooter Purchase Method............................................................................. 27
Electric Scooter Sell Method ...................................................................................... 27
Electric Scooter Display Method ................................................................................ 28
5) Inspections ................................................................................................................ 28
i. Test 1 ...................................................................................................................... 28
Screenshots ........................................................................................................... 29
ii. Test 2 ..................................................................................................................... 32
Screenshots ........................................................................................................... 33
iii. Test 3 .................................................................................................................... 37
Screenshots ........................................................................................................... 37
iv. Test 4 .................................................................................................................... 39
Screenshots ........................................................................................................... 40
6) Error Detection and Correction ................................................................................. 43
Error 1........................................................................................................................ 43
Error 1 Correction ...................................................................................................... 44
Error 2........................................................................................................................ 44
Error 2 Correction ...................................................................................................... 45
Error 3........................................................................................................................ 46
Error 3 Correction ...................................................................................................... 47
7) Conclusion. ............................................................................................................... 47
8) Appendix ................................................................................................................... 48
Vehicle Class Code ................................................................................................... 48
Autorickshaw Class Code .......................................................................................... 50
Electric Scooter Class Code ...................................................................................... 54
Bibliography .................................................................................................................. 58
List of Figures
Java is also a free to download software hence it is easily accessible for the public to
use it. Java is also known as an object-oriented programming language where the
programs are considered as “objects”. It is mostly used in developing Java applications
for various devices like laptops, computers, phones, supercomputers, etc.
“Java Platform is a collection of programs that help programmers to develop and run
Java programming applications efficiently. It includes an execution engine, a compiler,
and a set of libraries in it. It is a set of computer software and specifications. James
Gosling developed the Java platform at Sun Microsystems, and the Oracle Corporation
later acquired it.” (Hartman, 2022)
1
SHASHANK LAMA
2) Class Diagrams:
2
SHASHANK LAMA
Figure 2 Autorickshaw Class Figure
3
SHASHANK LAMA
4
SHASHANK LAMA
Figure 3 ElectricScooter Class Figure
5
SHASHANK LAMA
Figure 4 Combined Figure of all three Classes
3) Pseudocodes
CREATE a vehicle class with 5 parameters: ID of integer type, name of String type,
weight of String type, colour of String type and speed of String type.
DO
DO END
• Method getVehicleID ()
CREATE getVehicleID () method with int output type and no input parameters.
DO
6
SHASHANK LAMA
RETURN VehicleID
DO END
o Method getVehicleName ()
CREATE getVehicleName () method with String output type and no input parameters.
DO
RETRUN VehicleName
DO END
• Method getVehicleWeight ()
CREATE getVehicleWeight () method with String output type and no input parameters.
DO
RETURN VehicleWeight
DO END
• Method getVehicleColor ()
CREATE getVehicleColor () method with String output type with no input parameters.
DO
RETURN VehicleColor
7
SHASHANK LAMA
DO END
• Method getVehicleSpeed ()
DO
RETURN VehicleSpeed
DO END
• Method setVehicleWeight ()
CREATE setVehicleWeight () method with String input parameter and void output type.
DO
DO END
• Method display ()
CREATE display () method with void output datatype and no input parameters.
DO
DISPLAY VehicleID
DISPLAY VehicleName
8
SHASHANK LAMA
DISPLAY VehicleWeight
DISPLAY VehicleColor
DISPLAY VehicleSpeed
IF VehicleWeight = “ “
ELSE
PRINT VehicleWeight
IF END
DO END
DO
9
SHASHANK LAMA
CALL super class constructor with 5 parameters: VehicleID, VehicleName,
VehicleWeight, VehicleColor, VehicleSpeed.
DO END
• Method getEngineDisplacement ()
DO
RETRUN EngineDisplacement
DO END
• Method getTorque ()
CREATE getTorque () method with String output data type and no input parameter.
DO
10
SHASHANK LAMA
RETRUN Torque
DO END
• Method getNumberofSeats ()
CREATE getNumberofSeats () method with integer data type with no input parameter.
DO
RETURN NumberofSeats
DO END
• Method getFuelTankCapacity ()
CREATE getFuelTankCapacity () method with integer as output data type and no input
parameter.
DO
RETURN FuelTankCapacity
DO END
• Method getGroundClearance ()
CREATE getGroundClearance () method with String as output data type and no input
parameter.
11
SHASHANK LAMA
DO
RETURN GroundClearance
DO END
• Method getChargeAmount ()
CREATE getChargeAmount () method with integer as output data type and no input
parameter.
DO
RETURN ChargeAmount
DO END
• Method getBookedDate ()
CREATE getBookedDate () method with String as output data type and no input
parameter.
DO
RETURN BookedDate
DO END
12
SHASHANK LAMA
• Method getisBooked ()
CREATE getisBooked () method with boolean as output data type and no input
parameter.
DO
RETURN isBooked
DO END
• Method setChargeAmount ()
CREATE getChargeAmount () method with integer as input data type void as output
data type.
DO
DO END
• Method setNumberofSeats ()
13
SHASHANK LAMA
CREATE getNumberofSeats () method with integer as input data type void as output
data type.
DO
DO END
• Method Book ()
CREATE Book () method with only one parameter as BookedDate with String data type
for input and void for output.
DO
IF BookedDate = “ “
ELSE
PRINT “ “
IF END
DO END
• Method Display ()
14
SHASHANK LAMA
CREATE display () method with void output type and no input parameters.
DO
IF isBooked = true
IF END
DO END
DO
15
SHASHANK LAMA
SET Range attribute value to 0
DO END
• Method getRange ()
CREATE getRange () method with integer as output data type and no input parameters.
DO
RETURN Range
DO END
• Method getBatteryCapacity ()
16
SHASHANK LAMA
CREATE getBatteryCapacity () method with integer as output data type and no input
parameters.
DO
RETURN BatteryCapacity
DO END
• Method getPrice ()
CREATE getBrand () method with integer as output data type and no input parameters.
DO
RETURN Price
DO END
• Method getChargingTime ()
CREATE getChargingTime () method with String as output data type and no input
parameters.
DO
RETURN ChargingTime
DO END
17
SHASHANK LAMA
• Method getBrand ()
CREATE getBrand () method with String as output data type and no input parameters.
DO
RETURN Brand
DO END
• Method getMileage ()
CREATE getMileage () method with String as output data type and no input parameters.
DO
RETURN Mileage
DO END
• Method gethasPurchased ()
CREATE gethasPurchased () method with boolean as output data type and no input
parameters.
DO
RETURN hasPurchased
DO END
18
SHASHANK LAMA
• Method gethasSold ()
CREATE gethasSold () method with boolean as output data type and no input
parameters.
DO
RETURN hasSold
DO END
• Method setPrice ()
CREATE setPrice () method with integer data type as input parameter and void data
type output .
DO
DO END
• Method setBrand ()
CREATE setBrand () method with String data type as input parameter and void data
type output.
DO
19
SHASHANK LAMA
IF hasPurchased = false
ELSE
IF END
DO END
• Method sell ()
CREATE sell () method with Price as integer data type as input parameter and void data
type output.
DO
IF hasSold = false
SET Range = 0
SET Mileage = “ “
20
SHASHANK LAMA
ELSE
IF END
DO END
• Method display ()
CREATE display () method with no input parameters and void as output data type.
DO
IF hasPurchased = true
DISPLAY Brand
DISPLAY BatteryCapacity
DISPLAY Mileage
DISPLAY Range
DISPLAY ChargingTime
IF END
DO END
21
SHASHANK LAMA
Vehicle Class Constructor Method
The Vehicle Constructor accepts 5 input parameters which are VehicleID, VehicleName,
VehicleWeight, VehicleColor, VehicleSpeed. The VehicleID holds the input data type as
integer and the rest hold the values as String data type. Constructors are made to
assign the class attributes to their respective parameter values.
getVehicleID ()
getVehicleName ()
getVehicleWeight ()
getVehicleColor ()
getVehicleSpeed ()
The getter methods of the class is used for accessing the attributes of the class whose
access modifiers are initiated to private. Since private attributes cannot be accessed
easily like public, we strictly use getter methods. They always return the same data type
that that is accessed by itself. They access the attributes by using the ‘this’ keyword.
22
SHASHANK LAMA
Vehicle Class Setter Methods
Vehicle class contains a single setter method which is setVehicleWeight. Setter method
takes input and here it takes String as input. It sets the value to its current class’s
VehicleWeight.
The display method in the Vehicle class prints the values of VehicleID, VehicleName,
VehicleWeight, VehicleColor, VehicleSpeed. And if the VehicleWeight field is empty,
then the result “This field is empty” is printed.
Autorickshaw Class accepts 8 input parameters and they are int EngineDisplacement,
String Torque, int NumberofSeats, int FuelTankCapacity, String GroundClearance, int
ChargeAmount, int ChargeAmount, boolean isBooked. Inside the method, we also call
the parent class attributes using ‘super’ keyword. Using ‘super’ keyword, we call the
attributes VehicleID, VehicleName, VehicleWeight, VehicleColor, VehicleSpeed. And
lastly, the method assigns the values of EngineDisplacement to EngineDisplacement,
23
SHASHANK LAMA
Autorickshaw Class Getter Methods
getEngineDisplacement ()
getTorque ()
getNumberofSeats ()
getFuelTankCapacity ()
getGroundClearance ()
getChargeAmount ()
getBookedDate ()
getisBooked ()
Getter methods that have been used above is the accessor which accesses the private
attributes of the Autorickshaw class and returns its output with their data types.
In the Autorickshaw class, we have two setter methods which are setChargeAmount
and setNumberofSeats. The data type of ChargeAmount and NumberofSeats is integer
and their return type is void. This means that they take in input but do not return any
value since it uses void.
24
SHASHANK LAMA
Autorickshaw Class Book Method
Here, the Book Method takes in 3 parameters which are BookedDate, ChargeAmount,
and NumberofSeats. The datatype of BookedDate is String and the data type of both
ChargeAmount and NumberofSeats is integer. If the BookedDate here is not empty,
then we assign the corresponding values and the details are displayed. But if the
booked date is empty, then the appropriate message is displayed.
The display method does not have any input parameters and no output type either.
Here, if the is Booked value is set to true, them the values of Engine Displacement,
Torque, FuelTankCapacity and Ground Clearance is displayed to the user. Again, if the
Charge Amount and Number of Seats are assigned to 0, then the message is displayed
saying they are empty. And if they are not empty, then the values of Charge Amount
and Number of Seats are assigned to them.
The electric scooter constructor method takes in 6 parameters which are Vehicle ID,
Vehicle Name, Vehicle Weight, Vehicle Colour and Vehicle Speed. The data type
Vehicle ID is int and the rest of the data type for each of them is String. The method
also calls the parent class methods attributes by using the ‘ extends’ keyword. The
25
SHASHANK LAMA
method also assigns the attributes like Range, Battery Capacity, Price, Charging Time,
Brand, Mileage, has Purchased and has Sold. The data types of Range, Battery
Capacity and Price is set to integer. The data type of Charging Time, Brand and
Mileage is set to String and has Purchased and has Sold has been set to Boolean.
getRange ()
getBatterCapacity ()
getPrice ()
getCharginTime ()
getBrand ()
getMileage ()
gethasPurchased ()
gethasSold ()
The above methods are used to access the private attributes of the Electric Scooter
Class. They access the attributes and then simply return the values through the output.
Here, the setter methods that are used are setChargeAmount and setNumberofSeats.
And they are used for assigning new values to the given attributes. It assigns the value
to the attribute only if the has Purchased has been set to false but if it has been set to
true, then appropriate message is displayed to the user.
26
SHASHANK LAMA
Electric Scooter Purchase Method
The purchased method accepts three parameters which are Brand of String datatype,
Price of String data type and Charging time of String data type, Mileage of String data
type and Range of int data type. Here, if the electric scooter has not been bought , then
we set the Brand attribute to its corresponding value and the same for Price, Charging
Time, Mileage and Range. Their values are assigned to their corresponding attributes
and lastly has Purchased is set to true indicating that the electric scooter has been
purchased. But if the electric scooter is already bought then a message is displayed to
the user.
The Sell method has single input parameter which is Price of integer datatype and the
output data type is set to void as it returns no value. The method firstly assigns the Price
value to the price attribute. Now, if the car has not been sold then the values of Range
and Battery Capacity is assigned to 0. The values of Charging Time and Mileage is
assigned to “ “. And the values of has Sold is set to true and has purchased is set to
false. However, if the electric scooter is already sold, then a message is displayed to the
user saying it is already sold.
27
SHASHANK LAMA
Electric Scooter Display Method
The display method does not have any input parameters and the output data type is
also set to void. The method firstly calls the super class display method. And if the value
of has Purchased is set to true, then the method displays the values of Brand, Battery
Capacity, Mileage, Range and Charging Time attributes.
5) Inspections
i. Test 1
Test 1
Objective Inspect Auto-Rickshaw class, book the
Auto-Rickshaw, and re-
inspect the Auto-Rickshaw Class
Actions Inspect Autorickshaw Class
Book the Autorickshaw with following
parameters:
BookedDate: “2020-12-10”
Re-inspect the autorickshaw class
Expected Results The constructor will call the parent class
constructor to fill the vehicle details and
the attributes must be set to their
assigned values. The number of seats
28
SHASHANK LAMA
and charged amount is filled with their
values and isBooked is set to true.
Screenshots
29
SHASHANK LAMA
Figure 6 Inspecting Autorickshaw
30
SHASHANK LAMA
Figure 7 Autorickshaw Booking method
31
SHASHANK LAMA
Figure 8 Re-Inspect Autorickshaw Class
ii. Test 2
Test 2
Objective Inspect ElectricScooter, purchase an electric
scooter and re-inspect the ElectricScooter
Class
32
SHASHANK LAMA
Screenshots
33
SHASHANK LAMA
Figure 10 Inspecting Electric Scooter Class
34
SHASHANK LAMA
Figure 11 Electric Scooter Purchase Method Call
35
SHASHANK LAMA
Figure 12 Re-Inspect Electric Scooter Class
36
SHASHANK LAMA
iii. Test 3
Test 3
Objective Inspect ElectricScooter class again, change
the status of hasPurchased to false, and re-
inspect the ElectricScooter class
Actions Inspect Electric Scooter Class
The purchase method is called to change
the hasPurchased status to false by passing
new parameters which are:
VehicleID= 2
VehicleName = Aviator
VehicleWeight= 100kg
VehicleColor= Black
VehicleSpeed= 20km/h
BatteryCapacity= 900
Re-inspect the ElectricScooter class
Expected Results The status of hasPurchased will be set to
false because we inserted new values to the
electric scooter class.
Actual Results The details were filled without errors and the
hasPurchased method was changed to
false properly.
Conclusion The test was a success.
Screenshots
37
SHASHANK LAMA
Figure 13 Electric Scooter new Object Creation
38
SHASHANK LAMA
iv. Test 4
Test 4
Objective Display the details of Autorickshaw and
Electric scooter class.
39
SHASHANK LAMA
Screenshots
40
SHASHANK LAMA
Figure 16 Displaying the Details of Autorickshaw Class
41
SHASHANK LAMA
Figure 17 Object Creation in Electric Scooter Class
42
SHASHANK LAMA
Figure 18 Displaying the details of Electric Scooter Class
Error detection and correction is the process of finding out problems and solving them
one by one. In computing terms, we call it debugging. Debugging is the processing of
fixing bugs and problems which causes the program to malfunction. There are mainly
three types of errors: Syntax error, Semantic errors and logical error. Syntax errors are
those errors which occurs in the programming language. Semantic errors occur in the
meaning of the code and logical errors is not understanding the logic behind the
program.
Error 1
The first error we will be talking about is the syntax error. It is a very simple and
recurring error which is made by everyone especially beginners. Here, the error was
made when we called the wrong setter function name. The setter method should have
been called by “setChargeAmount” but since we used “setchargeamount”, the error
“cannot find symbol” occurred.
Figure 19 Error 1
43
SHASHANK LAMA
Error 1 Correction
We simple correct the first error by calling the setter method with the appropriate
function name i.e. “setChargeAmount”.
Error 2
The second error we will be discussing about is the semantics error. The semantic error
occurred when the values of integer data type was assigned to String data type. The
attributes Range and Price should have been assigned to integer datatype but instead
we assigned it to the String data type which is “ “ and that is why the semantic error
occurred showing us “incompatible types: java.lang.String cannot be converted to int”.
44
SHASHANK LAMA
Figure 21 Error 2
Error 2 Correction
The simple solution to error 2 is that we assign integer values like 0,1,2, etc to the
integer data type attribute.
45
SHASHANK LAMA
Error 3
The third error we have in hand is the logical error. It comes from a logical
misunderstanding. The error occurred because we used the “this” keyword for
displaying the parent class method instead of “super” keyword. We cannot use the “this”
keyword because it is used only for accessing the methods of the current class.
Figure 22 Error 3
46
SHASHANK LAMA
Error 3 Correction
The error was fixed by simply using the super keyword for parent class call instead of
this keyword.
7) Conclusion.
This coursework showed us the ways in which the programs are inspected and tested
throughout the process. We also learned about the inheritance of attributes in the
classes. It also gave us an insight into what error detection and error correction was.
Overall, this coursework helped me put everything I learned in the lecture and tutorial
47
SHASHANK LAMA
classes into use. It made me learn the more practical side of the things we learned
about in our classes.
And in conclusion, this project was very informative and helpful for me in so many ways
like learning the basics of JAVA, how it functions and the many inner workings of JAVA.
Hence, I can say with confidence that this coursework was of great help to me since it
widened my knowledge about the programming language JAVA.
8) Appendix
Vehicle Class Code
public class Vehicle{
//Class Attributes
private int VehicleID;
private String VehicleName;
private String VehicleWeight;
private String VehicleColor;
private String VehicleSpeed;
//assigning parameter values
public Vehicle(int VehicleID, String VehicleName, String VehicleWeight, String
VehicleColor, String VehicleSpeed)
{
this.VehicleID = VehicleID;
this.VehicleName = VehicleName;
this.VehicleWeight = " ";
this.VehicleColor = VehicleColor;
this.VehicleSpeed = VehicleSpeed;
}
//corresponding accessor methods
public int getVehicleID(){
48
SHASHANK LAMA
return this.VehicleID;
}
public String getVehicleName(){
return this.VehicleName;
}
public String getvehicleWeight(){
return this.VehicleWeight;
}
public String getVehicleColor(){
return this.VehicleColor;
}
public String getVehicleSpeed(){
return this.VehicleSpeed;
}
public String setVehicleColor(String VehicleColor){
return this.VehicleColor = VehicleColor;
}
49
SHASHANK LAMA
if (this.VehicleWeight ==""){
System.out.println("This field is empty");
}
else{
System.out.println(this.VehicleWeight);
}
}
50
SHASHANK LAMA
this.EngineDisplacement=EngineDisplacement ;
this.FuelTankCapacity= FuelTankCapacity;
this.GroundClearance= GroundClearance;
this.isBooked = false;
}
//corresponding methods of each accessor method
public int getEngineDisplacement(){
return this.EngineDisplacement;
}
public String getTorque(){
return this.Torque;
}
public int getNumberofSeats(){
return this.NumberofSeats;
}
public int getFuelTankCapacity(){
return this.FuelTankCapacity;
}
public String getGroundClearance(){
return this.GroundClearance;
}
public int getChargeAmount(){
return this.ChargeAmount;
}
51
SHASHANK LAMA
public String getBookedDate(){
return this.BookedDate;
}
public boolean getisBooked(){
return this.isBooked;
}
public void setChargeAmount( int ChargeAmount){
this.ChargeAmount= ChargeAmount;
}
public void setNumberofSeats(int NumberofSeats){
this.NumberofSeats= NumberofSeats;
}
public void Book( String BookedDate, int ChargeAmount, int NumberofSeats){
if (BookedDate != " " )
{
this.BookedDate = BookedDate;
this.ChargeAmount = ChargeAmount;
this.NumberofSeats = NumberofSeats;
this.isBooked = true;
System.out.println("The vehicleId says that it is booked ");
}
else{
System.out.println("The Autorickshaw is already booked ");
52
SHASHANK LAMA
}
}
public void display(){
super.display();
if (isBooked = true ){
System.out.println("EngineDisplacement:" + this.getEngineDisplacement());
System.out.println("Torque:" + this.getTorque());
System.out.println("FuelTankCapacity:" + getFuelTankCapacity());
System.out.println("GroundClearance:" + getGroundClearance());
}
if (this.ChargeAmount ==0 && this.NumberofSeats == 0){
System.out.println("No charge amount");
System.out.println("Seat number not set");
}
else {
System.out.println("Charge amount is " + getChargeAmount());
System.out.println("Number of seats is " + getNumberofSeats());
}
}
}
53
SHASHANK LAMA
Electric Scooter Class Code
public class ElectricScooter extends Vehicle
{
//Class Attributes
private int Range;
private int BatteryCapacity;
private int Price;
private String ChargingTime;
private String Brand;
private String Mileage;
private boolean hasPurchased;
private boolean hasSold;
//assigning parameter values
public ElectricScooter( int VehicleID, String VehicleName, String VehicleWeight,
String VehicleSpeed,
String VehicleColor, int BatteryCapacity){
super(VehicleID, VehicleName, VehicleColor, VehicleWeight, VehicleSpeed);
this.Range = 0;
this.Price = 0;
this.Brand = " ";
this.Mileage = "";
this.ChargingTime= "";
this.hasPurchased= false;
this.hasSold= false;
}
//corresponding methods of each accessor method
public int getRange (){
return this.Range;
}
54
SHASHANK LAMA
public int getBatteryCapacity(){
return this.BatteryCapacity;
}
public int getPrice(){
return this.Price;
}
public String getChargingTime(){
return this.ChargingTime;
}
public String getBrand(){
return this.Brand;
}
public String getMileage(){
return this.Mileage;
}
public boolean gethasPurchased(){
return this.hasPurchased;
}
public boolean gethasSold(){
return this.hasSold;
}
public void setPrice( int Price){
this.Price = Price;
}
public void setBrand( String Brand){
if (this.hasPurchased == false){
this.Brand = Brand;
55
SHASHANK LAMA
}
else {
System.out.println( "Scooter has been sold already");
}
}
public void purchase(String Brand,int price, String ChargingTime,
String Mileage, int Range){
if (this.hasPurchased== false)
{
this.setBrand(Brand);
this.Price = Price;
this.ChargingTime = ChargingTime;
this.Mileage = Mileage;
this.Range= Range;
this.hasPurchased=true;
}
else{
System.out.println("The electric scooter is already bought");
}
}
public void sell( int Price){
this.setPrice(Price);
if(this.hasSold == false){
this.Range = 0;
this.ChargingTime= " ";
56
SHASHANK LAMA
this.Mileage= " " ;
this.BatteryCapacity= 0 ;
this.hasSold= true;
this.hasPurchased= false;
}
else
{
System.out.println("Electric Scooter is already sold");
}
}
public void display()
{
super.display(); //calling parent class display method
if (hasPurchased = true){
System.out.println("Brand Name:" + this.Brand);
System.out.println("Battery Capacity:" + this.BatteryCapacity);
System.out.println("Mileage:" + this.Mileage);
System.out.println("Range:" + this.Range);
System.out.println("Charging Time:" + this.ChargingTime);
}
}
}
57
SHASHANK LAMA
Bibliography
Hartman, J. (2022, April 26). guru99. Retrieved from Definiton of Java:
https://www.guru99.com/java-platform.html
Java. (2007, May 23). Java/what is java. Retrieved from Java official website:
https://www.java.com/en/download/help/whatis_java.html
58
SHASHANK LAMA