Question

In: Computer Science

Java Programmig Enumeration Assignment. What Will You Learn Using enumerations to ensure data integrity and using...

Java Programmig Enumeration Assignment.

What Will You Learn

Using enumerations to ensure data integrity and using enumerations for making business decisions.

Deliverables

  • Person.java
  • Student.java
  • StudentAthlete.java
  • App.java
  • Address.java
  • (Optional) AddressType.java

Contents

Using inheritance and the classes (below)

  • The Person class has
    • first name
    • last name
    • age
    • hometown
    • a list of addresses
  • The Student class is a person with
    • an id and
    • a major and
    • a GPA
    • Student has to call super passing the parameters for the super class constructor
  • The StudentAthlete class is a student with
    • a sports (football, or track, or soccer, volleyball, etc.)and
    • a ranking (a random number between 0 and 100)
    • StudentAthlete has to call super passing the parameters for the super class constructor
  • An Address class
    • a street address
    • a city
    • a country
    • a postal code
    • an address type
  • AddressType can be stand alone or can be a member of the Address class
    • This should enforce data integrity by making sure an illegal type cannot be used

Create an application (main or app) that:

  • Creates two people. Each person should be in a different level in the inheritance hierarchy (i.e. - One Student, One StudentAthlete)
  • Add two addresses to each person, one of type LOCAL one of type PERMANENT
    • The address types should not be able to be assigned an illegal value
  • For each of the two people look at each address
    • If the address is of type LOCAL
      • Print out the street address, city, country and postal code
  • Uses the classes
    • App
    • Person
    • Student inheriting from person
    • StudentAthlete inheriting from student
    • Address
      • AddressType

Solutions

Expert Solution

Solution:

Givendata:

Please create a package name app and create following class in this package

AddressType is enum

Compile All classes and run only App class

/*******************************Person.java*******************************/

package app;

import java.util.ArrayList;
import java.util.List;

/**
* @author
*
* class Person
*/
public class Person {

   private String firstName;
   private String lastName;
   private int age;
   private String homeTown;
   private List<Address> address;

   /**
   * Default constructor to initialize instance variable to initial value
   */
   public Person() {

       this.firstName = "";
       this.lastName = "";
       this.age = 0;
       this.homeTown = "";
       this.address = new ArrayList<Address>();
   }

   /**
   * Parameterized constructor to initialize instance variables to given
   * parameters
   *
   * @param firstName
   * @param lastName
   * @param age
   * @param homeTown
   * @param address
   */
   public Person(String firstName, String lastName, int age, String homeTown, List<Address> address) {

       this.firstName = firstName;
       this.lastName = lastName;
       this.age = age;
       this.homeTown = homeTown;
       this.address = address;
   }

   // return first name
   public String getFirstName() {
       return firstName;
   }

   // set first name
   public void setFirstName(String firstName) {
       this.firstName = firstName;
   }

   // return last name
   public String getLastName() {
       return lastName;
   }

   // set last name
   public void setLastName(String lastName) {
       this.lastName = lastName;
   }

   // return age
   public int getAge() {
       return age;
   }

   // set age
   public void setAge(int age) {
       this.age = age;
   }

   // return home town
   public String getHomeTown() {
       return homeTown;
   }

   // set home town
   public void setHomeTown(String homeTown) {
       this.homeTown = homeTown;
   }

   // return address
   public List<Address> getAddress() {
       return address;
   }

   // set address
   public void setAddress(List<Address> address) {
       this.address = address;
   }

   /*
   * toString method to get the information of person
   */
   @Override
   public String toString() {
       String s = "";
       for (Address address2 : address) {

           s += address2 + "\t";
       }
       return "Name: " + firstName + " " + lastName + "\nAge: " + age + " Years\nHome Town: " + homeTown + "\nAddress: "
               + s;
   }

}// end class Person

/***********************************Address.java************************************/


package app;

/**
* @author
*
* class Address
*/
public class Address {

   /*
   * Instance variables to store the Address
   */
   private String streetAddress;
   private String city;
   private String country;
   private int postalCode;
   private AddressType type;

   /**
   * Parameterized constructor to initialize instance variables to given
   * parameters
   *
   * @param streetAddress
   * @param city
   * @param country
   * @param postalCode
   * @param type
   */
   public Address(String streetAddress, String city, String country, int postalCode, AddressType type) {
       this.streetAddress = streetAddress;
       this.city = city;
       this.country = country;
       this.postalCode = postalCode;
       this.type = type;
   }

   // return street address
   public String getStreetAddress() {
       return streetAddress;
   }

   // set street address
   public void setStreetAddress(String streetAddress) {
       this.streetAddress = streetAddress;
   }

   // return city
   public String getCity() {
       return city;
   }

   // set city
   public void setCity(String city) {
       this.city = city;
   }

   // return country
   public String getCountry() {
       return country;
   }

   // set city
   public void setCountry(String country) {
       this.country = country;
   }

   // return postal code
   public int getPostalCode() {
       return postalCode;
   }

   // set postal code
   public void setPostalCode(int postalCode) {
       this.postalCode = postalCode;
   }

   // get Address type
   public AddressType getType() {
       return type;
   }

   // set address type
   public void setType(AddressType type) {
       this.type = type;
   }

   @Override
   public String toString() {
       return streetAddress + ", " + city + ", " + country + ", " + postalCode + ", Address type: " + type.toString();
   }

}// end class Address


/*******************************************AddressType.java*****************************/


package app;

/**
* @author
*
* enum AddressType
*/
public enum AddressType {

   LOCAL, PERMANENT
}

/***************************************Student.java*****************************/


package app;

import java.util.List;

/**
* @author
*
* class Student
*/
public class Student extends Person {

   private String id;
   private String major;
   private double gpa;

   /**
   * Constructor to initialize variables
   *
   * @param firstName
   * @param lastName
   * @param age
   * @param homeTown
   * @param address
   * @param id
   * @param major
   * @param gpa
   */
   public Student(String firstName, String lastName, int age, String homeTown, List<Address> address, String id,
           String major, double gpa) {
       super(firstName, lastName, age, homeTown, address);
       this.id = id;
       this.major = major;
       this.gpa = gpa;
   }

   // return id
   public String getId() {
       return id;
   }

   // set id
   public void setId(String id) {
       this.id = id;
   }

   // return major
   public String getMajor() {
       return major;
   }

   // set major
   public void setMajor(String major) {
       this.major = major;
   }

   // get gpa
   public double getGpa() {
       return gpa;
   }

   // set gpa
   public void setGpa(double gpa) {
       this.gpa = gpa;
   }

   @Override
   public String toString() {
       return super.toString() + "\nStudnet ID: " + id + "\nMajor: " + major + "\nGPA: " + gpa;

   }

}// end class Student

/***************************************StudentAthlete.java********************************/


package app;

import java.util.List;
import java.util.Random;

/**
* @author
*
* class StudentAthlete
*/
public class StudentAthlete extends Student {

   /*
   * private data field
   */
   private String sports;
   private int ranking;

   /**
   * Constructor to initialize object with these parameters
   *
   * @param firstName
   * @param lastName
   * @param age
   * @param homeTown
   * @param address
   * @param id
   * @param major
   * @param gpa
   * @param sports
   * @param ranking
   */
   public StudentAthlete(String firstName, String lastName, int age, String homeTown, List<Address> address, String id,
           String major, double gpa, String sports) {
       super(firstName, lastName, age, homeTown, address, id, major, gpa);
       this.sports = sports;
       this.ranking = new Random().nextInt(100);
   }

   // return sport name
   public String getSports() {
       return sports;
   }

   // set sport name
   public void setSports(String sports) {
       this.sports = sports;
   }

   // return ranking
   public int getRanking() {
       return ranking;
   }

   // set ranking
   public void setRanking(int ranking) {
       this.ranking = ranking;
   }

   /*
   * toString method to get the information of Athlete Student
   */
   @Override
   public String toString() {
       return super.toString() + "\nSports: " + sports + "\nRanking: " + ranking;
   }

}// end class Athlete Student

/***************************************App.java*****************************/


package app;

import java.util.ArrayList;
import java.util.List;

/**
* @author
*
* class main App
*/
public class App {

   public static void main(String[] args) {

       // create some address object and add to list
       List<Address> address = new ArrayList<Address>();
       address.add(new Address("B-84,Bajaj Nagar", "Jaipur", "India", 302015, AddressType.LOCAL));
       address.add(new Address("MD", "SWM", "INDIA", 322028, AddressType.PERMANENT));
       // create person object
       Person p1 = new Student("Ajay", "Saini", 27, "Jaipur", address, "ST1234", "CSE", 8.8);

       // create some address object for other person and add to list
       List<Address> address1 = new ArrayList<Address>();
       address1.add(new Address("Red fort street", "Delhi", "India", 302015, AddressType.LOCAL));
       address1.add(new Address("Sawai Madhopur", "SWM", "INDIA", 322028, AddressType.PERMANENT));
       // create person object
       Person p2 = new StudentAthlete("Virat", "Kohli", 33, "SWM", address1, "ST2344", "ECE", 5.6, "Football");

       // print details of object we created
       System.out.println("Person 1 details: ");
       System.out.println(p1.toString());
       System.out.println("\nPerson 2 details: ");
       System.out.println(p2.toString());
   }
}// end class App

/*****************************output*********************************/

Person 1 details:
Name: Ajay Saini
Age: 27 Years
Home Town: Jaipur
Address: B-84,Bajaj Nagar, Jaipur, India, 302015, Address type: LOCAL   MD, SWM, INDIA, 322028, Address type: PERMANENT  
Studnet ID: ST1234
Major: CSE
GPA: 8.8

Person 2 details:
Name: Virat Kohli
Age: 33 Years
Home Town: SWM
Address: Red fort street, Delhi, India, 302015, Address type: LOCAL   Sawai Madhopur, SWM, INDIA, 322028, Address type: PERMANENT  
Studnet ID: ST2344
Major: ECE
GPA: 5.6
Sports: Football
Ranking: 27

PLEASE GIVE ME THUMBUP.......


Related Solutions

How does CAN protocol ensure the integrity of the data frame, making it suitable for the...
How does CAN protocol ensure the integrity of the data frame, making it suitable for the harsh environment like an automobile?
Using JAVA and NETBEANS Assignment Content For this assignment, you will develop "starter" code. After you...
Using JAVA and NETBEANS Assignment Content For this assignment, you will develop "starter" code. After you finish, your code should access an existing text file that you have created, create an input stream, read the contents of the text file, sort and store the contents of the text file into an ArrayList, then write the sorted contents via an output stream to a separate output text file. Copy and paste the following Java™ code into a JAVA source file in...
For this assignment you will write a Java program using a loop that will play a...
For this assignment you will write a Java program using a loop that will play a simple Guess The Number game. Create a new project named GuessANumber and create a new Java class in that project named GuessANumber.java for this assignment. The program will randomly generate an integer between 1 and 200 (including both 1 and 200 as possible choices) and will enter a loop where it will prompt the user for a guess. If the user has guessed the...
0. Introduction. In this assignment you will implement a stack as a Java class, using a...
0. Introduction. In this assignment you will implement a stack as a Java class, using a linked list of nodes. Unlike the stack discussed in the lectures, however, your stack will be designed to efficiently handle repeated pushes of the same element. This shows that there are often many different ways to design the same data structure, and that a data structure should be designed for an anticipated pattern of use. 1. Theory. The most obvious way to represent a...
Programming Language: JAVA In this assignment you will be sorting an array of numbers using the...
Programming Language: JAVA In this assignment you will be sorting an array of numbers using the bubble sort algorithm. You must be able to sort both integers and doubles, and to do this you must overload a method. Bubble sort work by repeatedly going over the array, and when 2 numbers are found to be out of order, you swap those two numbers. This can be done by looping until there are no more swaps being made, or using a...
using java For this assignment, you will write a program that guesses a number chosen by...
using java For this assignment, you will write a program that guesses a number chosen by your user. Your program will prompt the user to pick a number from 1 to 10. The program asks the user yes or no questions, and the guesses the user’s number. When the program starts up, it outputs a prompt asking the user to choose a number from 1 to 10. It then proceeds to ask a series of questions requiring a yes or...
Purpose: The purpose of this assignment is to learn the content of a 10K report using...
Purpose: The purpose of this assignment is to learn the content of a 10K report using a real company. It is also a requirement for ACC 230. Audience: Your audience is someone who wants to know more about this company (ex: potential investor or employee). Background: Publicly traded companies in the United States are required to file a 10K report with the Securities Exchange Commission (SEC), which gives an overview of the company's financial position. Directions: You have already been...
1.What process is used to ensure that evidence is kept secure and it's integrity is maintained...
1.What process is used to ensure that evidence is kept secure and it's integrity is maintained from collection to destruction? 2.Blank image is an exact copy without the addition of any compression or metadata. 3.What is the part of the hard drive that is not easily accessible to the user or the operating system? 4. A firewall log is an example of a computer______ record while a budget spreadsheet is an example of a computer_____record.
Assignment #2 (JAVA) In assignment 1 you had used the data structure called Stack to evaluate...
Assignment #2 (JAVA) In assignment 1 you had used the data structure called Stack to evaluate arithmetic expressions by first converting the given infixed expressions to postfixed expressions, and then evaluated the post fixed expression. Repeat the exercise for this assignment (assignment 2) by using the data structure called Binary Trees. Your output must display the original expression, the postfixed expression representing the Binary tree, and the evaluated result. Please bear in mind that a given expression could result in...
Review the three attributes you learned in Cybersecurity: Confidentiality, Integrity and Availability. Learn Information Assurance and...
Review the three attributes you learned in Cybersecurity: Confidentiality, Integrity and Availability. Learn Information Assurance and understand why two more attributes, Authentication and Nonrepudiation, should be involved in the Security Services dimension, and what the Time dimension for information security and assurance discusses. Write a short paper to discuss and describe your understanding.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT