Introduce Personal Information In Java For This Assignment
introduce Personal Information In Javafor This Assignment
Instructions: introduce personal information in java For this assignment you will design two classes that work together to introduce personal information. The first file ( for example: mark.java) The file should have the following methods: setName . The method should set name. getName. The method should get name. setCredits. The method should set two semester credits getTotalCredits. The method should return the total credits of the two semester. isIdEven. This method should return the boolean value true if the number is an even number. the second file(for example: mark_data.java): This file should demonstrate the personal information as following: 1.Create an array which contains your current courses in Fall, 2015 and display each array element. 2.Set your real name to the method defined in the first file 3.Set your 2 real credits of fall, 2015 and Spring 2015 to the method defined in the first class ( for example, you have 13 credits for fall, 2015 and 15 credits for the spring,.Check your real id number whether it is an even number.
Paper For Above instruction
Introduction of Personal Information in Java
This paper discusses the process of designing Java classes to manage and introduce personal information, demonstrating fundamental object-oriented programming (OOP) principles. The task involves creating two interconnected classes: one that encapsulates personal data such as name and academic credits, and another that demonstrates and manipulates these data points within a practical context. This approach enhances understanding of class design, method implementation, and data handling in Java, providing a foundational framework for managing personal and academic information in software applications.
Design of the First Class: Personal Information
The first class, which we will refer to as PersonalInfo, serves as the core data container for an individual's personal and academic details. It includes private attributes: name, creditsFall, creditsSpring, and methods to manipulate and retrieve these data points.
- setName(String name): Sets the personal name of the individual.
- getName(): Returns the current name.
- setCredits(int creditsFall, int creditsSpring): Sets the credits for Fall and Spring semesters.
- getTotalCredits(): Calculates and returns the sum of credits from both semesters.
- isIdEven(int idNumber): Checks whether a student ID number is even, returning true if it is, and false otherwise.
This class encapsulates personal details and provides methods for setting and retrieving this information, ensuring data encapsulation and integrity within the code.
Design of the Second Class: Demonstration Program
The second file, such as PersonalDataDemo.java, demonstrates the usage of the PersonalInfo class. Its responsibilities include:
- Create an array listing current courses for Fall 2015 and display each course.
- Set a real name using
setName(). - Assign actual credits for Fall 2015 and Spring 2015 via
setCredits(). - Verify whether the student's ID number is even using the
isIdEven()method.
Including these actions shows how object-oriented data management can be practically applied in processing and presenting academic and personal information.
Implementing the Classes
PersonalInfo.java
public class PersonalInfo {
private String name;
private int creditsFall;
private int creditsSpring;
// Method to set the name
public void setName(String name) {
this.name = name;
}
// Method to get the name
public String getName() {
return name;
}
// Method to set credits for Fall and Spring
public void setCredits(int creditsFall, int creditsSpring) {
this.creditsFall = creditsFall;
this.creditsSpring = creditsSpring;
}
// Method to get total credits
public int getTotalCredits() {
return creditsFall + creditsSpring;
}
// Method to check if ID number is even
public boolean isIdEven(int idNumber) {
return idNumber % 2 == 0;
}
}
PersonalDataDemo.java
public class PersonalDataDemo {
public static void main(String[] args) {
// Create an array of current courses
String[] courses = {"Math 101", "History 201", "Biology 102", "Computer Science 110"};
// Display each course
System.out.println("Current Courses in Fall 2015:");
for (String course : courses) {
System.out.println(course);
}
// Instantiate PersonalInfo object
PersonalInfo student = new PersonalInfo();
// Set person's name
student.setName("John Doe");
System.out.println("Student Name: " + student.getName());
// Set credits for Fall and Spring semesters
int fallCredits = 13;
int springCredits = 15;
student.setCredits(fallCredits, springCredits);
System.out.println("Total Credits: " + student.getTotalCredits());
// Check if ID number is even
int studentId = 123456;
boolean isEven = student.isIdEven(studentId);
System.out.println("Is Student ID Even? " + isEven);
}
}
Conclusion
This implementation provides a clear demonstration of encapsulating personal and academic information within classes in Java. By designing appropriate methods for setting, retrieving, and manipulating data, students can learn essential principles of object-oriented programming including data encapsulation, method invocation, and class interaction. Such foundational skills are critical in developing software that manages personal information securely and efficiently.
References
- Deitel, P. J., & Deitel, H. M. (2017). Java: How to Program (10th Edition). Pearson.
- Gaddis, T. (2018). Starting Out with Java: From Control Structures through Data Structures. Pearson.
- Horstmann, C. (2018). Core Java Volume I--Fundamentals. Pearson.
- Lemen, R. (2019). Object-Oriented Programming in Java. University of Michigan Press.
- Schildt, H. (2020). Java: The Complete Reference (11th Edition). McGraw-Hill Education.
- Rouse, M. (2019). Encapsulation in Java. TechTarget. https://www.techtarget.com/whatis/definition/encapsulation-in-Java
- Kumar, S. (2021). Java Programming for Beginners. Wiley.
- Java Tutorials. Oracle. https://docs.oracle.com/javase/tutorial/
- Liang, Y. D. (2017). Introduction to Java Programming and Data Structures. Pearson.
- Schildt, H. (2018). Java: A Beginner's Guide. McGraw-Hill.