Java Programming Assignment: Core Concepts, Design, and Error Analysis
VerifiedAdded on 2021/04/17
|9
|1726
|33
Practical Assignment
AI Summary
This Java programming assignment solution delves into fundamental Java concepts, including constructors, getters and setters, packages, loops, and exception handling. It explores object-oriented design principles such as encapsulation and abstraction, demonstrating class design and visibility of methods and fields through code examples and screenshots. The assignment analyzes various error types encountered during development, such as issues with equals() and hashCode(), newline characters in scanner input, and log4j initialization. It also details the design and implementation of a method for rescheduling events, including logic and usage. Furthermore, the assignment covers exception handling and input validation, providing examples of how to handle invalid user input and ensure data integrity using try-catch blocks and range checks. The solution is well-referenced with sources from various Java programming books and online resources.

Section 1: Core concept
Figure 1.1
Figure 1.2
Figure 1.1 shows the concepts of Constructors, getters and setters. Getters and setters are used for
setting up value of a variable and retreiving that value. Instance members of a class are private
mostly and their values are accessed by using getters and setters. Constructors are used for
initialization of an object when it is created. We can have parameterized and empty constructors.
The main work of constructors is initialization of value and they have no return type.
Figure 1.2 shows the concept of packages, Loops, Exception Handling, methods etc. Package are
used in java for grouping of classes. Loops are used for iteration purpose. When we have to perform
a task again and again, we can do that by using loops. We use try- catch to handle exceptions.
Figure 1.1
Figure 1.2
Figure 1.1 shows the concepts of Constructors, getters and setters. Getters and setters are used for
setting up value of a variable and retreiving that value. Instance members of a class are private
mostly and their values are accessed by using getters and setters. Constructors are used for
initialization of an object when it is created. We can have parameterized and empty constructors.
The main work of constructors is initialization of value and they have no return type.
Figure 1.2 shows the concept of packages, Loops, Exception Handling, methods etc. Package are
used in java for grouping of classes. Loops are used for iteration purpose. When we have to perform
a task again and again, we can do that by using loops. We use try- catch to handle exceptions.
Paraphrase This Document
Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser

Exception is the superclass of all the exceptions. Methods are used for dividing our code into small
parts. Methods are also used because they can be used again and again. A method is responsible for
carrying a single task and any part of the calss can use it any number of times.
References :
Belloc, H. (1967). On. Freeport, N.Y.: Books for Libraries Press.
Bloch, J. (2018). Effective Java. Upper Saddle River, NJ: Addison-Wesley.
Burd, B. (n.d.). Java.
Collins, W. (2011). Data structures and the Java collections framework. Hoboken, N.J: Wiley.
Section 2: Design of classes according to OO paradigm
Figure 2.1
parts. Methods are also used because they can be used again and again. A method is responsible for
carrying a single task and any part of the calss can use it any number of times.
References :
Belloc, H. (1967). On. Freeport, N.Y.: Books for Libraries Press.
Bloch, J. (2018). Effective Java. Upper Saddle River, NJ: Addison-Wesley.
Burd, B. (n.d.). Java.
Collins, W. (2011). Data structures and the Java collections framework. Hoboken, N.J: Wiley.
Section 2: Design of classes according to OO paradigm
Figure 2.1

Figure2.2
Figure 2.1 shows the concept of Encapsulation. All the fields and methods of the Object are bundled
together in a single entity called class. We can say that each Object of the class will then have same
type of attributes and behaviours.
Figure 2.2 shows the concept of Abstraction. I have used Interface for making my Main Program.
This interface is then implemented by my main class which is then implementing all these methods
and performing this functionality.
References:
Deitel, P. and Deitel, H. (2015). Java. Upper Saddle River, N.J.: Pearson.
Grand, M. (1997). Java language reference. Sebastopol, Calif.: O'Reilly.
Hutton, P., Allan, J., Invernizzi, L. and Hoefer, H. (1993). Java. [Hong Kong]: APA Publication.
Section 3 : Visibility of classes, methods and fields
Figure 2.1 shows the concept of Encapsulation. All the fields and methods of the Object are bundled
together in a single entity called class. We can say that each Object of the class will then have same
type of attributes and behaviours.
Figure 2.2 shows the concept of Abstraction. I have used Interface for making my Main Program.
This interface is then implemented by my main class which is then implementing all these methods
and performing this functionality.
References:
Deitel, P. and Deitel, H. (2015). Java. Upper Saddle River, N.J.: Pearson.
Grand, M. (1997). Java language reference. Sebastopol, Calif.: O'Reilly.
Hutton, P., Allan, J., Invernizzi, L. and Hoefer, H. (1993). Java. [Hong Kong]: APA Publication.
Section 3 : Visibility of classes, methods and fields
⊘ This is a preview!⊘
Do you want full access?
Subscribe today to unlock all pages.

Trusted by 1+ million students worldwide

Figure 3.1
Figure 3.2
Figure 3.1 is the screenshot of a POJO class. It is a plain java Entity which defines an Event. A
class is mostly public because it is used in other classes outside the base package also. Fogure 3.2 is
a screenshot of the main class which contains a menu and multiple methods to perform the
functionality of those menus. There are some methods which are used only in the class where it is
defined. Those methods are private by nature. You can see the startPrg method in Figure3.2. its is
used only in that class and will never be called from outside. So it is private in nature. Other
methods which are to be called from outside the class are public in nature. Fields in a class are
mostly private. We generally use getters and setters to set and retrieve their value.
Figure 3.2
Figure 3.1 is the screenshot of a POJO class. It is a plain java Entity which defines an Event. A
class is mostly public because it is used in other classes outside the base package also. Fogure 3.2 is
a screenshot of the main class which contains a menu and multiple methods to perform the
functionality of those menus. There are some methods which are used only in the class where it is
defined. Those methods are private by nature. You can see the startPrg method in Figure3.2. its is
used only in that class and will never be called from outside. So it is private in nature. Other
methods which are to be called from outside the class are public in nature. Fields in a class are
mostly private. We generally use getters and setters to set and retrieve their value.
Paraphrase This Document
Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser

References:
Karumanchi, N. (n.d.). Data structures and algorithms made easy in Java.
Langsam, Y., Augenstein, M. and Tenenbaum, A. (2003). Data structures using Java. Upper Saddle River, N.J.:
Pearson Prentice Hall.
Liang, Y. (n.d.). Introduction to Java programming and data structures.
Section 4: Error types
Error1. Error without equals and HashCode
In JUNIT while comparing two objects in assertEquals i was getting an error that objects do not
match and the test case was failing. When i inspected the difference between the actual and
Expected result, i found that both actual and expected values are same. I researched over Internet
and found that i need to implement equals and hashcode method So that the objects can match on
the basis of attributes.
Error 2. Error due to newline(\n) in sc.nextLine
Karumanchi, N. (n.d.). Data structures and algorithms made easy in Java.
Langsam, Y., Augenstein, M. and Tenenbaum, A. (2003). Data structures using Java. Upper Saddle River, N.J.:
Pearson Prentice Hall.
Liang, Y. (n.d.). Introduction to Java programming and data structures.
Section 4: Error types
Error1. Error without equals and HashCode
In JUNIT while comparing two objects in assertEquals i was getting an error that objects do not
match and the test case was failing. When i inspected the difference between the actual and
Expected result, i found that both actual and expected values are same. I researched over Internet
and found that i need to implement equals and hashcode method So that the objects can match on
the basis of attributes.
Error 2. Error due to newline(\n) in sc.nextLine

while running my program and was asking the user for Inpu name, description etc. After integer
input. The instruction was getting skipped and a ]n was getting stored in the String. It took quite a
large amount of time for me to figure out that the nextInt() function in scanner object was leaving
the newline character as it is and it was then read as a String in the Scanner.nextLine() function
because the nextLine() function needs a newLine character to terminate reading screen. I had to use
extra nextLine() to skip that newline left after reading integer value.
Error3. log4j:WARN Please initialize the log4j system properly
input. The instruction was getting skipped and a ]n was getting stored in the String. It took quite a
large amount of time for me to figure out that the nextInt() function in scanner object was leaving
the newline character as it is and it was then read as a String in the Scanner.nextLine() function
because the nextLine() function needs a newLine character to terminate reading screen. I had to use
extra nextLine() to skip that newline left after reading integer value.
Error3. log4j:WARN Please initialize the log4j system properly
⊘ This is a preview!⊘
Do you want full access?
Subscribe today to unlock all pages.

Trusted by 1+ million students worldwide

While using the logger, i was getting this Warning message that ”log4j:WARN Please initialize the
log4j system properly.”. I tried placing the log4j.properties file at various location in my intellij
project but was still facing the issue. I googled the problem and after some time got the solution to
use PropertyConfigurator.configure() method by passing the log4j properties file path
as argument.
Section 5: design of a method
Purpose of Method: This method reschedules an event. Suppose that an event is going to occur on
6th position in a Programme. The user can reschedule it to any possible position before or after its
current position. Here oldIndex is the old position of the event in the events array -1. And new
position is the new position where this event is to be moved now -1.
Design Of Methoddesign, implementation, logic and its usage. : First of all we will get two
integers oldIndex and newIndex. Both these indexes start from 1. So we will have to dcrease one
from them wherever we want to operate on them. Then we will remove the Event at the old index of
the ArrayList and store it into a new Event object. Now the event is removed from its previous old
position and now we will insert this removed Event object at the new Index. There is a method of
ArrayList list.insert(index, object). We will use this method and add this detached Event object
back into ArrayList by passing the new Index -1 and the Event object that we took while removing
it from old index. Again, we are using index-1 as the input is passed as index starting from 1. After
this operation, the event will get removed from its old position and added to its new position.
Section 6: Exception handling and validation
Example 1
log4j system properly.”. I tried placing the log4j.properties file at various location in my intellij
project but was still facing the issue. I googled the problem and after some time got the solution to
use PropertyConfigurator.configure() method by passing the log4j properties file path
as argument.
Section 5: design of a method
Purpose of Method: This method reschedules an event. Suppose that an event is going to occur on
6th position in a Programme. The user can reschedule it to any possible position before or after its
current position. Here oldIndex is the old position of the event in the events array -1. And new
position is the new position where this event is to be moved now -1.
Design Of Methoddesign, implementation, logic and its usage. : First of all we will get two
integers oldIndex and newIndex. Both these indexes start from 1. So we will have to dcrease one
from them wherever we want to operate on them. Then we will remove the Event at the old index of
the ArrayList and store it into a new Event object. Now the event is removed from its previous old
position and now we will insert this removed Event object at the new Index. There is a method of
ArrayList list.insert(index, object). We will use this method and add this detached Event object
back into ArrayList by passing the new Index -1 and the Event object that we took while removing
it from old index. Again, we are using index-1 as the input is passed as index starting from 1. After
this operation, the event will get removed from its old position and added to its new position.
Section 6: Exception handling and validation
Example 1
Paraphrase This Document
Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser

Here, we using validation check at two places. At first place, we are showing the list of all the
events to the user and asking him to select one of these. So the list has a definite index starting from
1 to size of list. Here we have taken the index starting from 1. So the maximum value that the user
can select must be between 1 and the size of list. We have added a check which checks whether or
not the user has entered a value within that range or not. If the value is within the range, then it is
Ok and the control proceeds to the next statement but if this check fails and the user has entered any
other value which is not within the index range then the program will print an error message and
return back from this method.
At the second place also, the same check is there but this is for the List of Scoring Systems. So i
have kept this in mind at every place that the user enters the index value only within the allowed
range and not outside that.
Example 2
In this case, the Programme is expecting an Integer Input from the user. But sometimes if the user
enters an invalid input, which can be a String a double or any other symbol etc. Then the program
events to the user and asking him to select one of these. So the list has a definite index starting from
1 to size of list. Here we have taken the index starting from 1. So the maximum value that the user
can select must be between 1 and the size of list. We have added a check which checks whether or
not the user has entered a value within that range or not. If the value is within the range, then it is
Ok and the control proceeds to the next statement but if this check fails and the user has entered any
other value which is not within the index range then the program will print an error message and
return back from this method.
At the second place also, the same check is there but this is for the List of Scoring Systems. So i
have kept this in mind at every place that the user enters the index value only within the allowed
range and not outside that.
Example 2
In this case, the Programme is expecting an Integer Input from the user. But sometimes if the user
enters an invalid input, which can be a String a double or any other symbol etc. Then the program

was crashing and getting to a halt. Then i used a try- catch statement to handle that. Now, i have
shifted that statement of Integer input to a try block, So if the user enters any invalid choice, the
program will throw an Exception which will get caught in the catch block as the Exception is
superclass of all the exceptions and can catch every type of exception. Once the exception is caught,
the program will print an error message and the program will not terminate and continue its
execution.
References:
Liang, Y. (n.d.). Introduction to Java programming and data structures.
McAllister, W. (2009). Data structures and algorithms using Java. Sudbury, Mass [u.a.]: Jones and Bartlett
Publishers.
Morgan, J., Good, M., Dadhaniya, D., Dadhaniya, D., Dadhaniya, D., Dadhaniya, D., Dadhaniya, D., Dadhaniya,
D., Dadhaniya, D., Dadhaniya, D., Dadhaniya, D., Dadhaniya, D. and Dadhaniya, D. (2018). Java web
development tutorials. [online] Mkyong.com. Available at: http://www.mkyong.com/ [Accessed 10 Mar. 2018].
Oey, E. (1997). Java. [Hong Kong]: Periplus Editions.
shifted that statement of Integer input to a try block, So if the user enters any invalid choice, the
program will throw an Exception which will get caught in the catch block as the Exception is
superclass of all the exceptions and can catch every type of exception. Once the exception is caught,
the program will print an error message and the program will not terminate and continue its
execution.
References:
Liang, Y. (n.d.). Introduction to Java programming and data structures.
McAllister, W. (2009). Data structures and algorithms using Java. Sudbury, Mass [u.a.]: Jones and Bartlett
Publishers.
Morgan, J., Good, M., Dadhaniya, D., Dadhaniya, D., Dadhaniya, D., Dadhaniya, D., Dadhaniya, D., Dadhaniya,
D., Dadhaniya, D., Dadhaniya, D., Dadhaniya, D., Dadhaniya, D. and Dadhaniya, D. (2018). Java web
development tutorials. [online] Mkyong.com. Available at: http://www.mkyong.com/ [Accessed 10 Mar. 2018].
Oey, E. (1997). Java. [Hong Kong]: Periplus Editions.
⊘ This is a preview!⊘
Do you want full access?
Subscribe today to unlock all pages.

Trusted by 1+ million students worldwide
1 out of 9

Your All-in-One AI-Powered Toolkit for Academic Success.
+13062052269
info@desklib.com
Available 24*7 on WhatsApp / Email
Unlock your academic potential
Copyright © 2020–2025 A2Z Services. All Rights Reserved. Developed and managed by ZUCOL.