222 lines
18 KiB
HTML
222 lines
18 KiB
HTML
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
|
||
|
<html>
|
||
|
<head>
|
||
|
<title>Person.java</title>
|
||
|
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
|
||
|
<style type="text/css">
|
||
|
<!--
|
||
|
body {color: #a9b7c6; background-color: #2b2b2b; font-family: monospace; font-weight: bold}
|
||
|
pre {color: #a9b7c6; background-color: #2b2b2b; font-family: monospace; font-weight: bold}
|
||
|
table {color: #888888; background-color: #313335; font-family: monospace; font-weight: bold}
|
||
|
.literal {color: #cc7832}
|
||
|
.string {color: #6a8759}
|
||
|
.number {color: #6897bb}
|
||
|
.comment {color: #808080}
|
||
|
.whitespace {color: #505050}
|
||
|
-->
|
||
|
</style>
|
||
|
</head>
|
||
|
<body>
|
||
|
<table width="100%"><tr><td align="center">/home/caleb/ASDV-Java/Semester 2/Assignments/lab4_CalebFontenot/src/main/java/com/calebfontenot/lab5_calebfontenot/Person.java</td></tr></table>
|
||
|
<pre>
|
||
|
<span class="comment">/*</span>
|
||
|
<span class="comment"> * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license</span>
|
||
|
<span class="comment"> * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template</span>
|
||
|
<span class="comment"> */</span>
|
||
|
<span class="literal">package</span> com.calebfontenot.lab5_calebfontenot;
|
||
|
|
||
|
<span class="literal">import</span> java.util.ArrayList;
|
||
|
<span class="literal">import</span> java.util.Arrays;
|
||
|
<span class="literal">import</span> java.util.Collections;
|
||
|
<span class="literal">import</span> java.util.Date;
|
||
|
|
||
|
<span class="comment">/**</span>
|
||
|
<span class="comment"> *</span>
|
||
|
<span class="comment"> * </span><span class="comment">@author</span> <span class="comment">caleb</span>
|
||
|
<span class="comment">*/</span>
|
||
|
<span class="literal">public</span> <span class="literal">class</span> Person {
|
||
|
<span class="comment">//name, addresss, phone number, and email addresss</span>
|
||
|
|
||
|
<span class="literal">private</span> String name;
|
||
|
<span class="literal">private</span> String address;
|
||
|
<span class="literal">private</span> String phoneNumber;
|
||
|
<span class="literal">private</span> String email;
|
||
|
|
||
|
<span class="literal">public</span> Person(String name, String address, String phoneNumber, String email)
|
||
|
{
|
||
|
<span class="literal">this</span>.name = name;
|
||
|
<span class="literal">this</span>.address = address;
|
||
|
<span class="literal">this</span>.phoneNumber = phoneNumber;
|
||
|
<span class="literal">this</span>.email = email;
|
||
|
}
|
||
|
|
||
|
<span class="literal">public</span> String getEmailAddress() {<span class="literal">return</span> email;}
|
||
|
<span class="literal">public</span> <span class="literal">void</span> setEmailAddress(String email) {<span class="literal">this</span>.email = email;}
|
||
|
<span class="literal">public</span> String getPhoneNumber(){<span class="literal">return</span> phoneNumber;}
|
||
|
<span class="literal">public</span> <span class="literal">void</span> setPhoneNumber(String phoneNumber) {<span class="literal">this</span>.phoneNumber = phoneNumber;}
|
||
|
<span class="literal">public</span> String getAddress() {<span class="literal">return</span> address;}
|
||
|
<span class="literal">public</span> <span class="literal">void</span> setAddress(String address){ <span class="literal">this</span>.address = address;}
|
||
|
<span class="literal">public</span> String getName() {<span class="literal">return</span> name;}
|
||
|
<span class="literal">public</span> <span class="literal">void</span> setName(String name) {<span class="literal">this</span>.name = name;}
|
||
|
|
||
|
@Override
|
||
|
<span class="literal">public</span> String toString()
|
||
|
{
|
||
|
<span class="literal">return</span> <span class="string">"</span><span class="string">Person{</span><span class="string">"</span> + <span class="string">"</span><span class="string">name=</span><span class="string">"</span> + name + <span class="string">'</span><span class="string">}</span><span class="string">'</span>;
|
||
|
}
|
||
|
|
||
|
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> checkArrayList() {
|
||
|
Integer[] arr = {<span class="number">3</span>, <span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">6</span>, <span class="number">3</span>, <span class="number">4</span>, <span class="number">6</span>, <span class="number">3</span>};
|
||
|
ArrayList<Integer> list =<span class="literal">new</span> ArrayList<Integer>(Arrays.asList(arr));
|
||
|
System.out.println(list);
|
||
|
Object[] arr3 = list.toArray();
|
||
|
<span class="literal">for</span> (<span class="literal">int</span> i = <span class="number">0</span>; i < <span class="number">3</span>; ++i) {
|
||
|
System.out.print(arr3[i] + <span class="string">"</span> <span class="string">"</span>);
|
||
|
}
|
||
|
System.out.println(<span class="string">"</span><span class="string">max is </span><span class="string">"</span> + Collections.max(list));
|
||
|
System.out.println();
|
||
|
|
||
|
}
|
||
|
|
||
|
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> ArrayListGeneric() {
|
||
|
ArrayList returnList = <span class="literal">new</span> ArrayList();
|
||
|
returnList.add(<span class="literal">new</span> Person(<span class="string">"</span><span class="string">John Wayne</span><span class="string">"</span>, <span class="string">"</span><span class="string">123 Sunny Dr. Santa Barabara, 90611</span><span class="string">"</span>, <span class="string">"</span><span class="string">922-337-3231</span><span class="string">"</span>, <span class="string">"</span><span class="string">jw@gmail.com</span><span class="string">"</span>));
|
||
|
returnList.add(<span class="literal">new</span> Date());
|
||
|
returnList.add(<span class="literal">new</span> String(<span class="string">"</span><span class="string">Hello, I am a string object.</span><span class="string">"</span>));
|
||
|
returnList.add(<span class="literal">new</span> Employee(<span class="string">"</span><span class="string">123</span><span class="string">"</span>, <span class="number">1234567</span>, <span class="literal">new</span> Date(), <span class="string">"</span><span class="string">Mary Poppins</span><span class="string">"</span>, <span class="string">"</span><span class="string">123 Blake Drive, Lafayette, LA, 70506</span><span class="string">"</span>, <span class="string">"</span><span class="string">337-123-4567</span><span class="string">"</span>, <span class="string">"</span><span class="string">mp@gmail.com</span><span class="string">"</span>));
|
||
|
<span class="comment">// Print objects in ArrayList</span>
|
||
|
<span class="literal">for</span> (Object o: returnList) {
|
||
|
System.out.println(o);
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
<span class="literal">public</span> <span class="literal">static</span> ArrayList<Integer> removeDuplicate(ArrayList<Integer> list) {
|
||
|
<span class="comment">//list.contains();</span>
|
||
|
<span class="comment">//list.remove();</span>
|
||
|
System.out.println(list);
|
||
|
ArrayList<Integer> newList = <span class="literal">new</span> ArrayList<>();
|
||
|
<span class="literal">for</span> (<span class="literal">int</span> i = <span class="number">0</span>; i < list.size(); ++i) {
|
||
|
<span class="literal">if</span> (!newList.contains(list.get(i))) {
|
||
|
newList.add(list.get(i));
|
||
|
}
|
||
|
}
|
||
|
<span class="literal">return</span> newList;
|
||
|
}
|
||
|
|
||
|
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> main(String[] args)
|
||
|
{
|
||
|
Integer[] arr = {<span class="number">3</span>, <span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">6</span>, <span class="number">3</span>, <span class="number">4</span>, <span class="number">6</span>, <span class="number">3</span>};
|
||
|
ArrayList<Integer> list2 =<span class="literal">new</span> ArrayList<>(Arrays.asList(arr));
|
||
|
System.out.println(removeDuplicate(list2));
|
||
|
ArrayListGeneric();
|
||
|
|
||
|
ArrayList list = <span class="literal">new</span> ArrayList();
|
||
|
list.add(<span class="literal">new</span> Person(<span class="string">"</span><span class="string">John Wayne</span><span class="string">"</span>, <span class="string">"</span><span class="string">123 Sunny Dr. Santa Barabara, 90611</span><span class="string">"</span>, <span class="string">"</span><span class="string">922-337-3231</span><span class="string">"</span>, <span class="string">"</span><span class="string">jw@gmail.com</span><span class="string">"</span>));
|
||
|
list.add(<span class="literal">new</span> Date());
|
||
|
list.add(<span class="string">"</span><span class="string">This is a string</span><span class="string">"</span>);
|
||
|
list.add(<span class="literal">new</span> String(<span class="string">"</span><span class="string">This is another string</span><span class="string">"</span>));
|
||
|
list.add(<span class="literal">new</span> Employee(<span class="string">"</span><span class="string">123</span><span class="string">"</span>, <span class="number">1234567</span>, <span class="literal">new</span> Date(), <span class="string">"</span><span class="string">Mary Poppins</span><span class="string">"</span>, <span class="string">"</span><span class="string">123 Blake Drive, Lafayette, LA, 70506</span><span class="string">"</span>, <span class="string">"</span><span class="string">337-123-4567</span><span class="string">"</span>, <span class="string">"</span><span class="string">mp@gmail.com</span><span class="string">"</span>));
|
||
|
<span class="literal">for</span> (<span class="literal">int</span> i = <span class="number">0</span>; i < list.size(); ++i) {
|
||
|
System.out.println(list.get(i));
|
||
|
}
|
||
|
|
||
|
}
|
||
|
}
|
||
|
<span class="literal">class</span> Student <span class="literal">extends</span> Person {
|
||
|
|
||
|
<span class="literal">private</span> Status status;
|
||
|
<span class="literal">public</span> Status getStatus() {<span class="literal">return</span> status;}
|
||
|
<span class="literal">public</span> <span class="literal">void</span> setStatus(Status status) {<span class="literal">this</span>.status = status;}
|
||
|
|
||
|
<span class="literal">public</span> Student(Status status, String name, String address, String phoneNumber, String email)
|
||
|
{
|
||
|
<span class="literal">super</span>(name, address, phoneNumber, email);
|
||
|
<span class="literal">this</span>.status = status;
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
<span class="literal">public</span> String toString() {<span class="literal">return</span> <span class="literal">super</span>.toString() + <span class="string">"</span><span class="string">Student{</span><span class="string">"</span> + <span class="string">"</span><span class="string">Status=</span><span class="string">"</span> + <span class="literal">this</span>.status + <span class="string">'</span><span class="string">}</span><span class="string">'</span>;}
|
||
|
}
|
||
|
<span class="literal">class</span> Employee <span class="literal">extends</span> Person {
|
||
|
<span class="comment">// office, salary, and data hired</span>
|
||
|
<span class="literal">private</span> String office;
|
||
|
<span class="literal">private</span> <span class="literal">double</span> salary;
|
||
|
<span class="literal">private</span> Date dateHired;
|
||
|
|
||
|
<span class="literal">public</span> Employee(String office, <span class="literal">double</span> salary, Date dateHired, String name, String address, String phoneNumber, String email)
|
||
|
{
|
||
|
<span class="literal">super</span>(name, address, phoneNumber, email);
|
||
|
<span class="literal">this</span>.office = office;
|
||
|
<span class="literal">this</span>.salary = salary;
|
||
|
<span class="literal">this</span>.dateHired = dateHired;
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
<span class="literal">public</span> Date getDateHired() {<span class="literal">return</span> dateHired;}
|
||
|
<span class="literal">public</span> <span class="literal">double</span> getSalary() {<span class="literal">return</span> salary;}
|
||
|
<span class="literal">public</span> <span class="literal">void</span> setSalary(<span class="literal">double</span> salary) {<span class="literal">this</span>.salary = salary;}
|
||
|
<span class="literal">public</span> String getOffice() {<span class="literal">return</span> office;}
|
||
|
<span class="literal">public</span> <span class="literal">void</span> setOffice(String office) {<span class="literal">this</span>.office = office;}
|
||
|
|
||
|
@Override
|
||
|
<span class="literal">public</span> String toString() {<span class="literal">return</span> <span class="literal">super</span>.toString() + <span class="string">"</span><span class="string">, Employee{</span><span class="string">"</span> + <span class="string">"</span><span class="string">Office=</span><span class="string">"</span> + <span class="literal">this</span>.office + <span class="string">"</span><span class="string">, Salary=</span><span class="string">"</span> + <span class="literal">this</span>.salary + <span class="string">"</span><span class="string">, dateHired=</span><span class="string">"</span> +<span class="literal">this</span>.dateHired + <span class="string">'</span><span class="string">}</span><span class="string">'</span>;}
|
||
|
}
|
||
|
<span class="literal">class</span> Faculty <span class="literal">extends</span> Employee {
|
||
|
|
||
|
<span class="literal">private</span> String officeHours;
|
||
|
<span class="literal">private</span> <span class="literal">int</span> rank;
|
||
|
|
||
|
<span class="literal">public</span> Faculty(String officeHours, <span class="literal">int</span> rank, String office, <span class="literal">double</span> salary, Date dateHired, String name, String address, String phoneNumber, String email)
|
||
|
{
|
||
|
<span class="literal">super</span>(office, salary, dateHired, name, address, phoneNumber, email);
|
||
|
<span class="literal">this</span>.officeHours = officeHours;
|
||
|
<span class="literal">this</span>.rank = rank;
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
<span class="literal">public</span> <span class="literal">int</span> getRank(){<span class="literal">return</span> rank;}
|
||
|
<span class="literal">public</span> <span class="literal">void</span> setRank(<span class="literal">int</span> rank) {<span class="literal">this</span>.rank = rank;}
|
||
|
<span class="literal">public</span> String getOfficeHours() {<span class="literal">return</span> officeHours;}
|
||
|
<span class="literal">public</span> <span class="literal">void</span> setOfficeHours(String officeHours) {<span class="literal">this</span>.officeHours = officeHours;}
|
||
|
|
||
|
@Override
|
||
|
<span class="literal">public</span> String toString() {<span class="literal">return</span> <span class="string">"</span><span class="string">Faculty{name=</span><span class="string">"</span> + <span class="literal">this</span>.getName() + <span class="string">"</span><span class="string">, </span><span class="string">"</span> +<span class="string">"</span><span class="string">rank=</span><span class="string">"</span> + rank + <span class="string">'</span><span class="string">}</span><span class="string">'</span>;}
|
||
|
|
||
|
}
|
||
|
<span class="literal">class</span> Staff <span class="literal">extends</span> Employee {
|
||
|
|
||
|
<span class="literal">private</span> String title;
|
||
|
|
||
|
<span class="literal">public</span> Staff(String title, String office, <span class="literal">double</span> salary, Date dateHired, String name, String address, String phoneNumber, String email)
|
||
|
{
|
||
|
<span class="literal">super</span>(office, salary, dateHired, name, address, phoneNumber, email);
|
||
|
<span class="literal">this</span>.title = title;
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
<span class="literal">public</span> String getTitle() {<span class="literal">return</span> title;}
|
||
|
<span class="literal">public</span> <span class="literal">void</span> setTitle(String title) {<span class="literal">this</span>.title = title;}
|
||
|
|
||
|
@Override
|
||
|
<span class="literal">public</span> String toString() {<span class="literal">return</span> <span class="string">"</span><span class="string">Staff{name=</span><span class="string">"</span> + <span class="literal">this</span>.getName() + <span class="string">"</span><span class="string">, </span><span class="string">"</span> +<span class="string">"</span><span class="string">title=</span><span class="string">"</span> + title + <span class="string">'</span><span class="string">}</span><span class="string">'</span>;}
|
||
|
}
|
||
|
<span class="literal">class</span> Status {
|
||
|
|
||
|
<span class="literal">final</span> <span class="literal">private</span> String status;
|
||
|
<span class="literal">public</span> Status(String status) { <span class="literal">this</span>.status = status;}
|
||
|
<span class="literal">public</span> String getStatus()
|
||
|
{
|
||
|
<span class="literal">return</span> status;
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
<span class="literal">public</span> String toString() {<span class="literal">return</span> <span class="string">"</span><span class="string">Status{</span><span class="string">"</span> + <span class="string">"</span><span class="string">status=</span><span class="string">"</span> + status + <span class="string">'</span><span class="string">}</span><span class="string">'</span>;}
|
||
|
|
||
|
}
|
||
|
</pre></body>
|
||
|
</html>
|