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

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>lab4_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.lab4_calebfontenot.Lab4_CalebFontenot</exec.mainClass>
</properties>
</project>

View File

@@ -0,0 +1,51 @@
/*
* 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.lab4_calebfontenot;
/**
*
* @author caleb
*/
public class Circle extends GeometricObject {
private double radius;
public Circle() {
}
public Circle(double radius) {
this.radius = radius;
}
/** Return radius */
public double getRadius() {
return radius;
}
/** Set a new radius */
public void setRadius(double radius) {
this.radius = radius;
}
@Override /** Return area */
public double getArea() {
return radius * radius * Math.PI;
}
/** Return diameter */
public double getDiameter() {
return 2 * radius;
}
@Override /** Return perimeter */
public double getPerimeter() {
return 2 * radius * Math.PI;
}
/* Print the circle info */
public void printCircle() {
System.out.println("The circle is created " + getDateCreated() +
" and the radius is " + radius);
}
}

View File

@@ -0,0 +1,65 @@
/*
* 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.lab4_calebfontenot;
/**
*
* @author caleb
*/
public abstract class GeometricObject {
private String color = "white";
private boolean filled;
private java.util.Date dateCreated;
/** Construct a default geometric object */
protected GeometricObject() {
dateCreated = new java.util.Date();
}
/** Construct a geometric object with color and filled value */
protected GeometricObject(String color, boolean filled) {
dateCreated = new java.util.Date();
this.color = color;
this.filled = filled;
}
/** Return color */
public String getColor() {
return color;
}
/** Set a new color */
public void setColor(String color) {
this.color = color;
}
/** Return filled. Since filled is boolean,
* the get method is named isFilled */
public boolean isFilled() {
return filled;
}
/** Set a new filled */
public void setFilled(boolean filled) {
this.filled = filled;
}
/** Get dateCreated */
public java.util.Date getDateCreated() {
return dateCreated;
}
@Override
public String toString()
{
return "GeometricObject{" + "color=" + color + ", filled=" + filled + ", dateCreated=" + dateCreated + '}';
}
/** Abstract method getArea */
public abstract double getArea();
/** Abstract method getPerimeter */
public abstract double getPerimeter();
}

View File

@@ -0,0 +1,16 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
*/
package com.calebfontenot.lab4_calebfontenot;
/**
*
* @author caleb
*/
public class Lab4_CalebFontenot {
public static void main(String[] args) {
System.out.println("Hello World!");
}
}

View File

@@ -0,0 +1,52 @@
/*
* 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.lab4_calebfontenot;
/**
*
* @author caleb
*/
public class Rectangle extends GeometricObject {
private double width;
private double height;
public Rectangle() {
}
public Rectangle(double width, double height) {
this.width = width;
this.height = height;
}
/** Return width */
public double getWidth() {
return width;
}
/** Set a new width */
public void setWidth(double width) {
this.width = width;
}
/** Return height */
public double getHeight() {
return height;
}
/** Set a new height */
public void setHeight(double height) {
this.height = height;
}
@Override /** Return area */
public double getArea() {
return width * height;
}
@Override /** Return perimeter */
public double getPerimeter() {
return 2 * (width + height);
}
}

View File

@@ -0,0 +1,48 @@
/*
* 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.lab4_calebfontenot;
/**
*
* @author caleb
*/
public class TestCircleRectangle {
public static void main(String[] args) {
Circle circle = new Circle(1);
System.out.println(circle);
/*
CircleFromSimpleGeometricObject circle =
new CircleFromSimpleGeometricObject(1);
System.out.println("A circle " + circle.toString());
System.out.println("The color is " + circle.getColor());
System.out.println("The radius is " + circle.getRadius());
System.out.println("The area is " + circle.getArea());
System.out.println("The diameter is " + circle.getDiameter());
RectangleFromSimpleGeometricObject rectangle =
new RectangleFromSimpleGeometricObject(2, 4);
System.out.println("\nA rectangle " + rectangle.toString());
System.out.println("The area is " + rectangle.getArea());
System.out.println("The perimeter is " +
rectangle.getPerimeter());
*/
}
class Apple extends Fruit {
}
class Fruit {
public Fruit () {}
public Fruit(String name) {
System.out.println("Fruit's constructior is invoked.");
}
}
}

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();
}
}