lab2 \& 3

master
Chloe Fontenot 🏳️‍⚧️ 2023-01-24 20:03:45 +07:00
parent a42477e983
commit c233baa498
10 changed files with 254 additions and 1 deletions

2
.gitignore vendored

@ -98,3 +98,5 @@
/Semester 2/Assignments/lab-2D-arrays-sort_CalebFontenot/target/
/Semester 2/Assignments/lab3_CalebFontenot/target/
/Semester 2/Assignments/MP1_CalebFontenot/target/
/Semester 2/Assignments/MP2_CalebFontenot/target/
/Semester 2/Assignments/lab2_CalebFontenot/target/

@ -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>MP2_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.mp2_calebfontenot.MP2_CalebFontenot</exec.mainClass>
</properties>
</project>

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

@ -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>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<exec.mainClass>com.calebfontenot.lab5_calebfontenot.Lab5_CalebFontenot</exec.mainClass>
</properties>
</project>

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

@ -0,0 +1,86 @@
/*
* 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.Date;
/**
*
* @author caleb
*/
public class TrueFalseQuestion {
private String question;
private boolean isTrue;
private Date whenLastUsed;
public TrueFalseQuestion(){}
public TrueFalseQuestion(String question, boolean isTrue, Date whenLastUsed) {
this.question = question;
this.isTrue = isTrue;
this.whenLastUsed = whenLastUsed;
}
/**
* Get the value of whenLastUsed
*
* @return the value of whenLastUsed
*/
public Date getWhenLastUsed()
{
return whenLastUsed;
}
/**
* Set the value of whenLastUsed
*
* @param whenLastUsed new value of whenLastUsed
*/
public void setWhenLastUsed(Date whenLastUsed)
{
this.whenLastUsed = whenLastUsed;
}
/**
* Get the value of isTrue
*
* @return the value of isTrue
*/
public boolean isIsTrue()
{
return isTrue;
}
/**
* Set the value of isTrue
*
* @param isTrue new value of isTrue
*/
public void setIsTrue(boolean isTrue)
{
this.isTrue = isTrue;
}
/**
* Get the value of question
*
* @return the value of question
*/
public String getQuestion()
{
return question;
}
/**Sets the question to a new question.
*
* @param question the new question
*/
public void setQuestion(String question)
{
this.question = question;
}
}

@ -0,0 +1,53 @@
/*
* 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.Date;
/**
*
* @author caleb
*/
public class TrueFalseQuiz {
int currentQuestion;
TrueFalseQuestion[] trueFalseQuestions;
public TrueFalseQuiz() {
trueFalseQuestions = new TrueFalseQuestion[5];
trueFalseQuestions[0] =
new TrueFalseQuestion("The Pacific Ocean is larger than the Atlantic Ocean.",
true, new Date());
trueFalseQuestions[1] =
new TrueFalseQuestion("The Suez Canal connects the Red Sea and the Indian Ocean.", false, new Date());
trueFalseQuestions[2] =
new TrueFalseQuestion("The source of the nile River is in Egypt.", false, new Date());
trueFalseQuestions[3] =
new TrueFalseQuestion("Lake Baikal is the world\'s oldest and deepest freshwater lake.", true, new Date());
trueFalseQuestions[4] =
new TrueFalseQuestion("The Amazon River is the longest river in the Americas.", true, new Date());
this.currentQuestion = 0;
}
public TrueFalseQuiz(String[] questions, boolean[] trueFalse) {
//> Create an array of REFERENCES of size questions.length
//the references are initializesed to null
trueFalseQuestions = new TrueFalseQuestion[questions.length];
//> assign to each reference of the array an object of type TrueFalseQuestion
for(int i = 0, j = 0; i < questions.length; ++i,++j) {
trueFalseQuestions[i] = new TrueFalseQuestion(
questions[i],
trueFalse[j],
new Date());
//> set the index of the first question
this.currentQuestion = 0;
}
}
}

@ -18,13 +18,15 @@ public class Circle {
public Circle()
{
numberOfObjectsRunning++;
this(0);
numberOfObjectsRunning++;
}
public Circle(double radius)
{
numberOfObjectsRunning++;
this.radius = radius;
this.dateOfCreation = new Date();
}
/**
@ -59,6 +61,11 @@ public class Circle {
return dateOfCreation;
}
public Circle getCircle() {
return this;
}
/**
* Set the value of dateOfCreation
*
@ -114,6 +121,31 @@ public class Circle {
System.out.println(new java.util.Random().nextInt());
System.out.println(c1);
System.out.println(c1.toString());
System.out.println();
printMultiples(c1, 4);
System.out.println();
Circle[] ar = new Circle[3];
ar[0] = c1;
ar[1] = new Circle(10);
ar[2] = new Circle(3.8);
Circle.printArray(ar);
System.out.println(c1.getCircle());
}
public static void printArray(Circle[] ar)
{
for (Circle ar1: ar) {
System.out.println(ar1);
}
}
public static void printMultiples(Circle c, int howManyTimes) {
for (int i = 0; i < howManyTimes; ++i) {
System.out.println(c);
}
}
}

@ -0,0 +1,20 @@
/*
* 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 jan17;
/**
*
* @author caleb
*/
public class TestImmutable {
public static void main(String[] args)
{
Circle c = new Circle(10);
System.out.println(c);
Circle c1 = c.getCircle();
c1.getDateOfCreation().setTime(1234567);
System.out.println(c1);
}
}