Reset author name to chosen name ✨
This commit is contained in:
@@ -1,32 +0,0 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
*/
|
||||
package com.chloefontenot.lab5_chloefontenot;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author chloe
|
||||
*/
|
||||
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"); }
|
||||
}
|
||||
@@ -1,198 +0,0 @@
|
||||
/*
|
||||
* 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.chloefontenot.lab5_chloefontenot;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author chloe
|
||||
*/
|
||||
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 checkArrayList() {
|
||||
Integer[] arr = {3, 1, 2, 3, 6, 3, 4, 6, 3};
|
||||
ArrayList<Integer> list =new ArrayList<Integer>(Arrays.asList(arr));
|
||||
System.out.println(list);
|
||||
Object[] arr3 = list.toArray();
|
||||
for (int i = 0; i < 3; ++i) {
|
||||
System.out.print(arr3[i] + " ");
|
||||
}
|
||||
System.out.println("max is " + Collections.max(list));
|
||||
System.out.println();
|
||||
|
||||
}
|
||||
|
||||
public static void ArrayListGeneric() {
|
||||
ArrayList returnList = new ArrayList();
|
||||
returnList.add(new Person("John Wayne", "123 Sunny Dr. Santa Barabara, 90611", "922-337-3231", "jw@gmail.com"));
|
||||
returnList.add(new Date());
|
||||
returnList.add(new String("Hello, I am a string object."));
|
||||
returnList.add(new Employee("123", 1234567, new Date(), "Mary Poppins", "123 Blake Drive, Lafayette, LA, 70506", "337-123-4567", "mp@gmail.com"));
|
||||
// Print objects in ArrayList
|
||||
for (Object o: returnList) {
|
||||
System.out.println(o);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static ArrayList<Integer> removeDuplicate(ArrayList<Integer> list) {
|
||||
//list.contains();
|
||||
//list.remove();
|
||||
System.out.println(list);
|
||||
ArrayList<Integer> newList = new ArrayList<>();
|
||||
for (int i = 0; i < list.size(); ++i) {
|
||||
if (!newList.contains(list.get(i))) {
|
||||
newList.add(list.get(i));
|
||||
}
|
||||
}
|
||||
return newList;
|
||||
}
|
||||
|
||||
public static void main(String[] args)
|
||||
{
|
||||
Integer[] arr = {3, 1, 2, 3, 6, 3, 4, 6, 3};
|
||||
ArrayList<Integer> list2 =new ArrayList<>(Arrays.asList(arr));
|
||||
System.out.println(removeDuplicate(list2));
|
||||
ArrayListGeneric();
|
||||
|
||||
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{" + "Status=" + this.status + '}';}
|
||||
}
|
||||
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{" + "Office=" + this.office + ", Salary=" + this.salary + ", dateHired=" +this.dateHired + '}';}
|
||||
}
|
||||
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 + '}';}
|
||||
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
/*
|
||||
* 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.chloefontenot.lab5_chloefontenot;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author chloe
|
||||
*/
|
||||
public class lab5_ChloeFontenot {
|
||||
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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user