ArrayList time

This commit is contained in:
2023-03-02 11:56:47 -06:00
parent aaf966ed6a
commit 397f12dc2a
31 changed files with 1984 additions and 0 deletions

Binary file not shown.

View File

@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.calebfontenot</groupId>
<artifactId>lab5_CalebFontenot</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<exec.mainClass>com.calebfontenot.lab5_calebfontenot.Lab5_CalebFontenot</exec.mainClass>
</properties>
</project>

View File

@@ -0,0 +1,32 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
*/
package com.calebfontenot.lab5_calebfontenot;
/**
*
* @author caleb
*/
public class A {
public A() { System.out.println("A constructor was called"); }
public A(String msg) {System.out.println(msg);}
public A(String msg1, String msg2) {
this (msg1 + "; " + msg2);
System.out.println("A 2-parm constructor was called");
}
public void instanceMethod1() { System.out.println("Instance method1 called from A"); }
public void instanceMethod2() { System.out.println("Instance method2 called from A"); }
public static void staticMethod() {System.out.println("Static method 2 called from A"); }
}
class B extends A {
public B() {System.out.println("B constructor called");}
public B(String msg)
{
System.out.println("B constructor called");
System.out.println(msg);
}
public void instanceMethod1() { System.out.println("Instance method1 called from B"); }
public void instanceMethod2() { System.out.println("Instance method2 called from B"); }
public static void staticMethod() {System.out.println("Static method 2 called from B"); }
}

View File

@@ -0,0 +1,152 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package com.calebfontenot.lab5_calebfontenot;
import java.util.ArrayList;
import java.util.Date;
/**
*
* @author caleb
*/
public class Person {
//name, addresss, phone number, and email addresss
private String name;
private String address;
private String phoneNumber;
private String email;
public Person(String name, String address, String phoneNumber, String email)
{
this.name = name;
this.address = address;
this.phoneNumber = phoneNumber;
this.email = email;
}
public String getEmailAddress() {return email;}
public void setEmailAddress(String email) {this.email = email;}
public String getPhoneNumber(){return phoneNumber;}
public void setPhoneNumber(String phoneNumber) {this.phoneNumber = phoneNumber;}
public String getAddress() {return address;}
public void setAddress(String address){ this.address = address;}
public String getName() {return name;}
public void setName(String name) {this.name = name;}
@Override
public String toString()
{
return "Person{" + "name=" + name + '}';
}
public static void main(String[] args)
{
ArrayList list = new ArrayList();
list.add(new Person("John Wayne", "123 Sunny Dr. Santa Barabara, 90611", "922-337-3231", "jw@gmail.com"));
list.add(new Date());
list.add("This is a string");
list.add(new String("This is another string"));
list.add(new Employee("123", 1234567, new Date(), "Mary Poppins", "123 Blake Drive, Lafayette, LA, 70506", "337-123-4567", "mp@gmail.com"));
for (int i = 0; i < list.size(); ++i) {
System.out.println(list.get(i));
}
}
}
class Student extends Person {
private Status status;
public Status getStatus() {return status;}
public void setStatus(Status status) {this.status = status;}
public Student(Status status, String name, String address, String phoneNumber, String email)
{
super(name, address, phoneNumber, email);
this.status = status;
}
@Override
public String toString() {return super.toString() + "Student{" + '}';}
}
class Employee extends Person {
// office, salary, and data hired
private String office;
private double salary;
private Date dateHired;
public Employee(String office, double salary, Date dateHired, String name, String address, String phoneNumber, String email)
{
super(name, address, phoneNumber, email);
this.office = office;
this.salary = salary;
this.dateHired = dateHired;
}
public Date getDateHired() {return dateHired;}
public double getSalary() {return salary;}
public void setSalary(double salary) {this.salary = salary;}
public String getOffice() {return office;}
public void setOffice(String office) {this.office = office;}
@Override
public String toString() {return super.toString() + "Employee{" + '}';}
}
class Faculty extends Employee {
private String officeHours;
private int rank;
public Faculty(String officeHours, int rank, String office, double salary, Date dateHired, String name, String address, String phoneNumber, String email)
{
super(office, salary, dateHired, name, address, phoneNumber, email);
this.officeHours = officeHours;
this.rank = rank;
}
public int getRank(){return rank;}
public void setRank(int rank) {this.rank = rank;}
public String getOfficeHours() {return officeHours;}
public void setOfficeHours(String officeHours) {this.officeHours = officeHours;}
@Override
public String toString() {return "Faculty{name=" + this.getName() + ", " +"rank=" + rank + '}';}
}
class Staff extends Employee {
private String title;
public Staff(String title, String office, double salary, Date dateHired, String name, String address, String phoneNumber, String email)
{
super(office, salary, dateHired, name, address, phoneNumber, email);
this.title = title;
}
public String getTitle() {return title;}
public void setTitle(String title) {this.title = title;}
@Override
public String toString() {return "Staff{name=" + this.getName() + ", " +"title=" + title + '}';}
}
class Status {
final private String status;
public Status(String status) { this.status = status;}
public String getStatus()
{
return status;
}
@Override
public String toString() {return "Status{" + "status=" + status + '}';}
}

View File

@@ -0,0 +1,38 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package com.calebfontenot.lab5_calebfontenot;
/**
*
* @author caleb
*/
public class lab5_CalebFontenot {
public static void main(String[] args)
{
//B b = new B("hi");
//A a = new A("msg1: The 2-parm constructor of A uses \"this\"",
// "msg2: to call the 1-parm constructor of A ");
//A a1 = new A();
//B b1 = new B();
//a.instanceMethod1();
//a.instanceMethod2();
//A.staticMethod();
//b.instanceMethod1();
//b.instanceMethod2();
//B.staticMethod();
//A a3 = new B();
//a3.instanceMethod1();
//testPolymorphism(a1);
//testPolymorphism(b1);
B b2 = (B) new A();
}
public static void testPolymorphism(A a) {
a.instanceMethod1();
}
}