You are on page 1of 64

Module Code & Module Title

CS4001NI Programming

Assessment Weightage & Type


30% Individual Coursework

Year and Semester


2021 - 22 Spring - 2

Student Name: Shashank Lama


London Met ID:
College ID: np01cp4s220112
Assignment Due Date: 20th May 2022
Assignment Submission Date: 20th May 2022

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

Figure 1 Vehicle Class Figure ......................................................................................... 2


Figure 2 Autorickshaw Class Figure ................................................................................ 3
Figure 3 ElectricScooter Class Figure ............................................................................. 5
Figure 4 Combined Figure of all three Classes ............................................................... 6
Figure 5 Autorickshaw Calling through Object .............................................................. 29
Figure 6 Inspecting Autorickshaw ................................................................................. 30
Figure 7 Autorickshaw Booking method ........................................................................ 31
Figure 8 Re-Inspect Autorickshaw Class....................................................................... 32
Figure 9 Inspecting Electric Scooter class object Creation............................................ 33
Figure 10 Inspecting Electric Scooter Class .................................................................. 34
Figure 11 Electric Scooter Purchase Method Call ......................................................... 35
Figure 12 Re-Inspect Electric Scooter Class ................................................................. 36
Figure 13 Electric Scooter new Object Creation ............................................................ 38
Figure 14 Re-Inspect Electric Scooter Class ................................................................. 38
Figure 15 Autorickshaw Class Object Creation ............................................................. 40
Figure 16 Displaying the Details of Autorickshaw Class................................................ 41
Figure 17 Object Creation in Electric Scooter Class ..................................................... 42
Figure 18 Displaying the details of Electric Scooter Class ............................................ 43
Figure 19 Error 1 ........................................................................................................... 43
Figure 20 Error 1 Correction .......................................................................................... 44
Figure 21 Error 2 ........................................................................................................... 45
Figure 22 Error 3 ........................................................................................................... 46
Figure 23 Error 3 Correction .......................................................................................... 47
List of Tables
Table 1Table 2

Table 1Table 2 ................................................................................................................ 6


Table 3 Table for Test 1 ................................................................................................ 29
Table 4 Table for test 2 ................................................................................................. 32
Table 5 Table for test 3 ................................................................................................. 37
Table 6 Table for test 4 ................................................................................................. 39
1) Introduction
Java is a programming language. It is the modern programming language that is used
all over the technology world in order to create various software and programs.” Java is
a programming language and computing platform first released by Sun Microsystems in
1995. It has evolved from humble beginnings to power a large share of today’s digital
world, by providing the reliable platform upon which many services and applications are
built. New, innovative products and digital services designed for the future continue to
rely on Java, as well.”(Java, 2007)

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:

Figure 1 Vehicle Class Figure

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

a. Vehicle class pseudocode

• Vehicle Constructor Method

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

SET VehicleID attribute value to the parameter VehicleID.

SET VehicleName attribute value to the parameter VehicleName.

SET VehicleWeight attribute value to the parameter VehicleWeight.

SET VehicleColor attribute value to the parameter VehicleColor.

SET VehicleSpeed attribute value to the parameter VehicleSpeed.

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 ()

CREATE getVehicleSpeed () method with String output datatype and no input


parameters.

DO

RETURN VehicleSpeed

DO END

• Method setVehicleWeight ()

CREATE setVehicleWeight () method with String input parameter and void output type.

DO

SET VehicleWeight value with the parameter value

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 = “ “

PRINT “This field is empty”

ELSE

PRINT VehicleWeight

IF END

DO END

b. Autorickshaw Methods Pseudocodes

• Autorickshaw Constructor Method

CREATE Autorickshaw constructor method with 8 parameters: Engine Displacement as


Integer data type, torque as String data type, number of seats as integer data type, fuel
tank capacity as integer data type, ground clearance as String data type, charge
amount as integer data type, booked date as String data type, isbooked as Boolean
data type.

DO

9
SHASHANK LAMA
CALL super class constructor with 5 parameters: VehicleID, VehicleName,
VehicleWeight, VehicleColor, VehicleSpeed.

SET EngineDisplacement attribute value to EngingDisplacement

SET FuelTankCapacity attribute value to FuelTankCapacity

SET GroundClearance attribute value to GroundClearance

SET isBooked attribute value to false

DO END

• Method getEngineDisplacement ()

CREATE getEngingDisplacement () method with integer output datatype and no input


parameter

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

SET ChargeAmount value with the parameter value

DO END

• Method setNumberofSeats ()

13
SHASHANK LAMA
CREATE getNumberofSeats () method with integer as input data type void as output
data type.

DO

SET NumberofSeats value with the parameter value

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 = “ “

SET BookedDate value using setter method

SET isBooked value using setter method

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

DISPLAY EngineDisplacement using getter method

DISPLAY Torque using getter method

DISPLAY FuelTankCapacity using getter method

DISPLAY GroundClearance using getter method

IF END
DO END

c. Electric Scooter Methods Pseudocodes

• Electric Scooter Constructor Method

CREATE a Electric Scooter Method with 8 parameters : range as integer, battery


capacity as integer, price as integer, charging time as String, brand as String, mileage
as String, has purchased as boolean, has sold as boolean.

DO

CALL super class VehicleID, VehicleName, VehicleWeight, VehicleColor,


VehicleSpeed

15
SHASHANK LAMA
SET Range attribute value to 0

SET Price attribute value to 0

SET Brand attribute value to “ “

SET Mileage attribute value to “ “

SET ChargingTime attribute value to “ “

SET Range attribute value to 0

SET hasPurchased attribute value to false

SET hasSold attribute value to false

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

SET Price value with parameter value

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

SET Brand value with parameter value

ELSE

PRINT “Scooter has been sold already”

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 Charging Time = “ “

SET Mileage = “ “

SET Battery Capacity = 0

SET hasSold= true

SET hasPurchased= false

20
SHASHANK LAMA
ELSE

PRINT “Electric Scooter has already sold”

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

4) Methods and their Descriptions

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.

Vehicle Class Getter Methods

The getter methods of the Vehicle class are as follows :

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.

Here, getVehicleID () accesses the VehicleID attribute, getVehicleName () accesses the


VehicleName attribute, getVehicleWeight () accesses the VehicleWeight attribute,
getVehicleColor () accesses the VehicleColor attribute, getVehicleSpeed () accesses
the VehicleSpeed attribute.

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.

Vehicle Class Display Method

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 Constructor Method

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,

FuelTankCapacity to FuelTankCapacity, GroundClearance to GroundClearance and


isBooked to false.

23
SHASHANK LAMA
Autorickshaw Class Getter Methods

The following are the getter methods of the Autorickshaw Class:

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.

Autorickshaw Class Setter Methods

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.

Autorickshaw Class Display Method

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.

Electric Scooter Class Constructor Method

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.

Electric Scooter Getter Method

The getter methods of electric scooter methods are as follows:

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.

Electric Scooter Setter Method

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.

Electric Scooter Sell Method

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.

Actual Results The details were filled without errors and


the BookedDate method functioned
properly.

Conclusion The test was a success.

Table 3 Table for Test 1

Screenshots

Figure 5 Autorickshaw Calling through Object

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

Actions Inspect Electric Scooter Class


Purchase the Electric Scooter with following
parameters:
Brand = Dio
Price = 125000
Charging Time = 6 hours
Mileage = 6km
Range = 109
Re-inspect the ElectricScooter class
Expected Results The electric scooter class should be filled and
the purchase method should show the details
of brand, price, etc and the hasPurchased is
set to true.
Actual Results The details were filled without errors and the
hasPurchased method functioned properly.

Conclusion The test was a success.

Table 4 Table for test 2

32
SHASHANK LAMA
Screenshots

Figure 9 Inspecting Electric Scooter class object Creation

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.

Table 5 Table for test 3

Screenshots

37
SHASHANK LAMA
Figure 13 Electric Scooter new Object Creation

Figure 14 Re-Inspect Electric Scooter Class

38
SHASHANK LAMA
iv. Test 4
Test 4
Objective Display the details of Autorickshaw and
Electric scooter class.

Actions Inspect the Autorickshaw class


Call autorickshaw display method
Inspect electric scooter class
Call Electric Scooter display method

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.

Table 6 Table for test 4

39
SHASHANK LAMA
Screenshots

Figure 15 Autorickshaw Class Object Creation

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

6) Error Detection and Correction

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”.

Figure 20 Error 1 Correction

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.

Figure 23 Error 3 Correction

7) Conclusion.

The completion of this coursework mainly introduced us to the process of programming


in java. It helped us learn about how codes are executed. Even though JAVA is a simple
language, this coursework for me, showed us how difficult the programming language
is. It helped me gain a better understanding of java syntax, methods, objects, classes,
data types, etc.

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;
}

public void display(){


System.out.println(this.VehicleID);
System.out.println(this.VehicleName);
System.out.println(this.VehicleWeight);
System.out.println(this.VehicleColor);
System.out.println(this.VehicleSpeed);

49
SHASHANK LAMA
if (this.VehicleWeight ==""){
System.out.println("This field is empty");
}
else{
System.out.println(this.VehicleWeight);
}
}

Autorickshaw Class Code


public class AutoRickshaw extends Vehicle
{
//Class Attributes
private int EngineDisplacement;
private String Torque;
private int NumberofSeats;
private int FuelTankCapacity;
private String GroundClearance;
private int ChargeAmount;
private String BookedDate;
private boolean isBooked;
//assigning parameter values
public AutoRickshaw(int VehicleID, String VehicleName, String VehicleWeight, String
VehicleColor, String VehicleSpeed, int EngineDisplacement,
String Torque, int FuelTankCapacity, String GroundClearance)
{
super(VehicleID, VehicleName, VehicleWeight, VehicleColor, VehicleSpeed);

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

You might also like