Some update
This commit is contained in:
parent
7d33040c6e
commit
7fb0671ceb
BIN
html-java-script/week13/APPS Lab Submission Example.docx
Normal file
BIN
html-java-script/week13/APPS Lab Submission Example.docx
Normal file
Binary file not shown.
37
html-java-script/week13/discussion.org
Normal file
37
html-java-script/week13/discussion.org
Normal file
@ -0,0 +1,37 @@
|
||||
* 3 new
|
||||
** 1
|
||||
Despite using the same technologies, mobile websites tend to differ from desktop websites.
|
||||
|
||||
The designers need to consider things such as, screen size, processing power available, and data.
|
||||
|
||||
While I've seen plenty of that in regards to screen size, I have seen plenty of data and power waste when browsing mobile sites. The old mobile sites used to be super basic and didn't use much, but lately, I still see things like video pop ups autoloading and following me around the screen.
|
||||
|
||||
** 2
|
||||
Web browsers send information to servers that identify itself so that the web pages can display information more appropriate to the device or specific web browser.
|
||||
** 3
|
||||
Subresource Integrity. I seem to remember reading about the web browsers only trusting JavaScript that came from the same domain. This kinda reminds me of a horror of troubles I ran into when I had to be on Windows (VB). Mark of the web. Hell of an error message to spit at someone when you're just trying to do class work. Anyway, I'm thinking that this subresource integrity concept is a much better version of that.
|
||||
|
||||
If I understand it correctly, subresource integrity allows us to pull JavaScript from other domains that allow it to be treated as if it's from our own domain for security purposes.
|
||||
|
||||
* 2 Interesting
|
||||
** 1
|
||||
Didn't realize that jQuery has been around since 2006. Of course, I was just a stupid teenager when it came out (Wait, did I just date myself? Am I old enough now to think about that?), and probably didn't even realize that JavaScript was much of a thing yet. Then again, it probably wasn't. Everyone finally was done (well...) with java applets and we were charging right in with a steaming pile of flash.
|
||||
** 2
|
||||
Instead of:
|
||||
$(document).ready( () => {});
|
||||
|
||||
We can shorthand it as:
|
||||
$(() => {});
|
||||
|
||||
I'm not sure I care for that. I enjoy concise, and it's certainly nice for minifiying, but readability is gone. Which, probably doesn't matter much, but still. Though, I do like how I feel like I'm using a half-baked lisp with the shorthand method.
|
||||
|
||||
|
||||
* 1 unclear
|
||||
I suppose what's least clear is the responsive/reactive/adaptave ideas. Aren't they mostly just progressions of the same concept? We started out responding to screen sizes with media queries that caused jerkiness while resizing windows and what not, but then we progressed to scaling more smoothly and such. Why do we need all of these things still?
|
||||
|
||||
|
||||
|
||||
NOTE: 12:33 may hold all answers for assignment
|
||||
SRI checking at 1625
|
||||
|
||||
At 45 mins
|
BIN
html-java-script/week13/expand_collapse/expand_collapse.zip
Normal file
BIN
html-java-script/week13/expand_collapse/expand_collapse.zip
Normal file
Binary file not shown.
70
html-java-script/week13/expand_collapse/index.html
Normal file
70
html-java-script/week13/expand_collapse/index.html
Normal file
@ -0,0 +1,70 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>Expand/Collapse</title>
|
||||
<link rel="stylesheet" href="subset_expansion.css">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<main id="jdom">
|
||||
<h1>Murach's HTML5 and CSS3 (4th Edition)</h1>
|
||||
<h2>Book description</h2>
|
||||
<div>
|
||||
<p>Murach's HTML5 and CSS3 provides all HTML and CSS a professional needs, and it
|
||||
adds coverage of Flexible Box and Grid Layout, two new CSS3 ways to implement page
|
||||
layouts. So whether you're a web designer, a JavaScript programmer, a server-side
|
||||
programmer, or a rookie, this book delivers all the HTML and CSS skills that you
|
||||
need on the job. It begins with an 8-chapter hands-on course that teaches you HTML
|
||||
and CSS from scratch, including the latest HTML5 and CSS3 features.</p>
|
||||
</div>
|
||||
<div class="hide">
|
||||
<p>After that, you'll learn how to use Flexible Box and Grid Layout, and how to work
|
||||
with forms and data validation. Then you'll learn how to enhance a site with video
|
||||
clips, CSS3 transitions, transforms, and animations. You'll learn how to design and
|
||||
deploy a website, as well as other professional skills like how to use JavaScript and
|
||||
jQuery and how to use development tools like Bootstrap, SASS, and Emmet. And after
|
||||
you've learned all the skills that you need, this book becomes the best on-the-job
|
||||
reference you've ever used.</p>
|
||||
</div>
|
||||
<a href="#">Show more</a>
|
||||
|
||||
<h2>About the authors</h2>
|
||||
<div>
|
||||
<p><strong>Anne Boehm</strong> has over 30 years of experience as an enterprise programmer. She got
|
||||
started with Visual Basic in the days of VB5 and has been programming on .NET since
|
||||
its inception. She added C# to her programming repertoire in the mid-2000s, and she's
|
||||
authored or co-authored our books on Visual Basic, C#, ADO.NET, ASP.NET, and HTML5/CSS3.</p>
|
||||
</div>
|
||||
<div class="hide">
|
||||
<p><strong>Zak Ruvalcaba</strong> has been researching, designing, and developing for the web since
|
||||
1995. His skill set ranges from HTML5/CSS3 and JavaScript/jQuery to .NET with VB
|
||||
and C#, and he's created web applications for companies like HP, Toshiba, IBM,
|
||||
Gateway, Intuit, Peachtree, Dell, and Microsoft. He has authored or co-authored our
|
||||
books on HTML5/CSS3, jQuery, and Dreamweaver CC.</p>
|
||||
</div>
|
||||
<a href="#">Show more</a>
|
||||
|
||||
<h2>Who this book is for</h2>
|
||||
<div>
|
||||
<p>Due to our unique presentation methods and this book's modular organization,
|
||||
this is the right book for any web developer who wants to use HTML5 and CSS3 effectively. That
|
||||
includes:</p>
|
||||
<ul>
|
||||
<li>budding web developers</li>
|
||||
<li>web developers who haven't yet upgraded their websites to HTML5 and CSS3</li>
|
||||
<li>web developers who need to expand and enhance their skillsets</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="hide">
|
||||
<p>As we see it, mastering HTML5 and CSS3 will make any web developer at any level more
|
||||
effective.</p>
|
||||
</div>
|
||||
<a href="#">Show more</a>
|
||||
|
||||
</main>
|
||||
<script src="https://code.jquery.com/jquery-3.4.1.slim.min.js"></script>
|
||||
<script src="subset_expansion.js"></script>
|
||||
</body>
|
||||
</html>
|
35
html-java-script/week13/expand_collapse/subset_expansion.css
Normal file
35
html-java-script/week13/expand_collapse/subset_expansion.css
Normal file
@ -0,0 +1,35 @@
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
body {
|
||||
font-family: Verdana, Arial, Helvetica, sans-serif;
|
||||
font-size: 87.5%;
|
||||
width: 650px;
|
||||
margin: 0 auto;
|
||||
padding: 15px 25px;
|
||||
border: 3px solid blue;
|
||||
}
|
||||
h1 {
|
||||
font-size: 150%;
|
||||
}
|
||||
h2 {
|
||||
font-size: 120%;
|
||||
padding: .25em 0 .25em 25px;
|
||||
}
|
||||
div.hide {
|
||||
display: none;
|
||||
}
|
||||
ul {
|
||||
padding-left: 45px;
|
||||
}
|
||||
li {
|
||||
padding-bottom: .4em;
|
||||
}
|
||||
p, a {
|
||||
padding-bottom: .4em;
|
||||
padding-left: 25px;
|
||||
}
|
||||
a, a:focus, a:hover {
|
||||
color: blue;
|
||||
}
|
23
html-java-script/week13/expand_collapse/subset_expansion.js
Normal file
23
html-java-script/week13/expand_collapse/subset_expansion.js
Normal file
@ -0,0 +1,23 @@
|
||||
"use strict"
|
||||
$(document).ready( () => {
|
||||
//Grab all div next sibiling a
|
||||
// Actually, could just do all a tags for this page
|
||||
//Make the a toggle the hide class of it's previous sibiling element
|
||||
|
||||
$("a").click( evt => {
|
||||
const a = evt.currentTarget;
|
||||
$(a).prev().toggleClass("hide");
|
||||
|
||||
//If hidden, show more. Else, show less
|
||||
|
||||
if ($(a).prev().hasClass("hide")){
|
||||
//Show More
|
||||
$(a).text("Show More");
|
||||
|
||||
}
|
||||
else{
|
||||
//Show less
|
||||
$(a).text("Show Less");
|
||||
}
|
||||
});
|
||||
});
|
BIN
html-java-script/week13/flexbox/LAB Recipe with flexbox.zip
Normal file
BIN
html-java-script/week13/flexbox/LAB Recipe with flexbox.zip
Normal file
Binary file not shown.
BIN
html-java-script/week13/flexbox/oatmealCookie_small.jpg
Normal file
BIN
html-java-script/week13/flexbox/oatmealCookie_small.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 95 KiB |
94
html-java-script/week13/flexbox/oatmeal_cookies.html
Normal file
94
html-java-script/week13/flexbox/oatmeal_cookies.html
Normal file
@ -0,0 +1,94 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>binary eats - Oatmeal Coconut Pantry Cookies</title>
|
||||
<link href="styles.css" rel="stylesheet">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<header>
|
||||
<div class="logo">binary eats</div>
|
||||
<div>
|
||||
<a href="">sign-in</a>
|
||||
<a href="">search</a>
|
||||
</div>
|
||||
</header>
|
||||
<div class="content">
|
||||
<div class="main-content">
|
||||
<div class="title">
|
||||
<h1>OATMEAL COCONUT PANTRY COOKIES</h1>
|
||||
<p>Chef Roman, August 24, 2018</p>
|
||||
</div>
|
||||
<div class="summary">
|
||||
<img src="oatmealCookie_small.jpg" alt="Photo of two of the world's best oatmeal cookies">
|
||||
<div>
|
||||
<div>
|
||||
<p>Prep Time:</p>
|
||||
<p>30 minutes</p>
|
||||
</div>
|
||||
<div>
|
||||
<p>Cooking Time:</p>
|
||||
<p>9-13 minutes</p>
|
||||
</div>
|
||||
<div>
|
||||
<p>Skill level:</p>
|
||||
<p>Easy</p>
|
||||
</div>
|
||||
<div>
|
||||
<p>Makes:</p>
|
||||
<p>24 cookies</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="ingredients">
|
||||
<h2>Ingredients</h2>
|
||||
<ul>
|
||||
<li>⅔ cup granulated sugar</li>
|
||||
<li>⅔ cup packed brown sugar</li>
|
||||
<li>1 cup butter</li>
|
||||
<li>2 eggs</li>
|
||||
<li>1 teaspoon vanilla</li>
|
||||
<li>1 teaspoon baking soda</li>
|
||||
<li>½ teaspoon baking powder</li>
|
||||
<li>½ teaspoon salt</li>
|
||||
<li>3 cups quick-cooking or old-fashioned oats</li>
|
||||
<li>1 cup all-purpose flour</li>
|
||||
<li>1 ½ cup Toasted Coconut*</li>
|
||||
<li>½ cup golden raisins</li>
|
||||
<li>½ cup chopped walnuts</li>
|
||||
<li>½ cup mini chocolate chips</li>
|
||||
</ul>
|
||||
<p>* Now with more coconut</p>
|
||||
</div>
|
||||
<div class="directions">
|
||||
<h2>Directions</h2>
|
||||
<ol>
|
||||
<li>Toast coconut at 350° F for about 10-15 minutes. Stir/toss every 5 minutes. Coconut should be golden brown. Be careful...coconut can go from golden brown to burnt very quickly. Cool completely.</li>
|
||||
<li>Beat sugar, butter, vanilla, and eggs.</li>
|
||||
<li>Mix all other ingredients together. The flour should coat all the ingredients. Then mix into the wet ingredients.</li>
|
||||
<li>Scoop cookies and press the dough firmly the ensure the shape is held.</li>
|
||||
<li>Bake at 375° F for about 9-13 minutes. This really depends on how big you made the cookies. Start at 9 minutes, and then just keep checking until they are done.</li>
|
||||
</ol>
|
||||
</div>
|
||||
</div>
|
||||
<div class="related-content">
|
||||
<div>
|
||||
<h4>010 RELATED RECIPES:</h4>
|
||||
<ul>
|
||||
<li>Melt-in-the-mouth Cookies</li>
|
||||
<li>German Chocolate Cake</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div>
|
||||
<h4>TOP 011 RECIPES:</h4>
|
||||
<ul>
|
||||
<li>Umeboshi Chicken</li>
|
||||
<li>Battleship Curry</li>
|
||||
<li>Gran Marnier Souffle</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
82
html-java-script/week13/flexbox/styles.css
Normal file
82
html-java-script/week13/flexbox/styles.css
Normal file
@ -0,0 +1,82 @@
|
||||
/* Add your styles here */
|
||||
|
||||
/* Given CSS rules below */
|
||||
body {
|
||||
margin: 0;
|
||||
font-family: Helvetica, sans-serif;
|
||||
}
|
||||
|
||||
header {
|
||||
border-bottom: 2px solid #93B5C6;
|
||||
background-color: #DDEDAA;
|
||||
padding: 8px;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
}
|
||||
|
||||
.logo {
|
||||
color: #BD4F6C;
|
||||
font-size: 18px;
|
||||
}
|
||||
|
||||
.content {
|
||||
margin-left: 30px;
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
.main-content {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
flex-grow: 1;
|
||||
flex-basis: 70%;
|
||||
}
|
||||
|
||||
.title {
|
||||
border-bottom: 1px dashed #93B5C6;
|
||||
display: flex;
|
||||
align-items: baseline;
|
||||
}
|
||||
|
||||
.title h1 {
|
||||
color: #BD4F6C;
|
||||
}
|
||||
|
||||
.title p {
|
||||
color: #93B5C6;
|
||||
margin-left: 30px;
|
||||
}
|
||||
|
||||
.summary {
|
||||
margin-top: 30px;
|
||||
display: flex;
|
||||
justify-content: space-evenly;
|
||||
flex-grow: 1;
|
||||
flex-basis: 100%;
|
||||
}
|
||||
|
||||
.summary > div {
|
||||
background-color: #DDEDAA;
|
||||
border: 2px solid #93B5C6;
|
||||
border-radius: 5px;
|
||||
color: #BD4F6C;
|
||||
padding: 5px;
|
||||
width: 210px;
|
||||
}
|
||||
|
||||
.summary > div > div{
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
|
||||
}
|
||||
|
||||
.related-content {
|
||||
margin-left: 100px;
|
||||
flex-grow: 1;
|
||||
flex-basis: 20%;
|
||||
}
|
||||
|
||||
.ingredients, .directions{
|
||||
flex-grow: 1;
|
||||
flex-basis: 45%;
|
||||
}
|
||||
|
1
java/final-project/.#Cvstranslate.java
Symbolic link
1
java/final-project/.#Cvstranslate.java
Symbolic link
@ -0,0 +1 @@
|
||||
logen@logen.3256:1618517739
|
@ -2,211 +2,326 @@ import java.util.ArrayList;
|
||||
import java.util.Scanner;
|
||||
import java.io.FileInputStream;
|
||||
import java.util.Collections;
|
||||
|
||||
|
||||
import java.io.*;
|
||||
import java.sql.*;
|
||||
|
||||
public class CovidDatabase {
|
||||
private ArrayList<CovidEntry> list;
|
||||
private static final int SAFE = 5;
|
||||
|
||||
|
||||
public CovidDatabase() {
|
||||
list = new ArrayList<CovidEntry>();
|
||||
}
|
||||
|
||||
private void transferCovidData(String filename){
|
||||
|
||||
|
||||
}
|
||||
private ArrayList<CovidEntry> list;
|
||||
private static final int SAFE = 5;
|
||||
private static final String covidDB = "covid.db";
|
||||
private static final String jdbcURL = "jdbc:sqlite:" + covidDB;
|
||||
|
||||
public ArrayList <CovidEntry> topTenDeaths(int m, int d){
|
||||
ArrayList<CovidEntry> result = new ArrayList<CovidEntry>();
|
||||
ArrayList<CovidEntry> temp = getDailyDeaths(m, d);
|
||||
public CovidDatabase() {
|
||||
list = new ArrayList<CovidEntry>();
|
||||
transferCovidData("covid_data.csv");
|
||||
}
|
||||
|
||||
Collections.sort(temp);
|
||||
if (temp.size() ==0){
|
||||
private void transferCovidData(String filename) {
|
||||
|
||||
String csvFilePath = filename;
|
||||
|
||||
int batchSize = 20;
|
||||
|
||||
Connection connection = null;
|
||||
|
||||
try {
|
||||
|
||||
connection = DriverManager.getConnection(jdbcURL);
|
||||
connection.setAutoCommit(false);
|
||||
Statement makeTable = connection.createStatement();
|
||||
makeTable.executeUpdate("drop table if exists entry");
|
||||
makeTable.executeUpdate(
|
||||
"create table entry (id integer, state string, month integer, day integer, daily_infections integer, daily_deaths integer, total_infections integer, total_deaths integer)");
|
||||
|
||||
String sql = "INSERT INTO entry (id, state, month, day, daily_infections, daily_deaths, total_infections, total_deaths) VALUES (?, ?, ?, ?, ?, ?, ?, ?)";
|
||||
PreparedStatement statement = connection.prepareStatement(sql);
|
||||
|
||||
BufferedReader lineReader = new BufferedReader(new FileReader(csvFilePath));
|
||||
String lineText = null;
|
||||
|
||||
int count = 0;
|
||||
|
||||
lineReader.readLine(); // skip header line
|
||||
int id = 0;
|
||||
|
||||
while ((lineText = lineReader.readLine()) != null) {
|
||||
String[] data = lineText.split(",");
|
||||
String state = data[0];
|
||||
int month = Integer.parseInt(data[1]);
|
||||
int day = Integer.parseInt(data[2]);
|
||||
int daily_infections = Integer.parseInt(data[3]);
|
||||
int daily_deaths = Integer.parseInt(data[4]);
|
||||
int total_infections = Integer.parseInt(data[5]);
|
||||
int total_deaths = Integer.parseInt(data[6]);
|
||||
|
||||
statement.setInt(1, id);
|
||||
statement.setString(2, state);
|
||||
statement.setInt(3, month);
|
||||
statement.setInt(4, day);
|
||||
statement.setInt(5, daily_infections);
|
||||
statement.setInt(6, daily_deaths);
|
||||
statement.setInt(7, total_infections);
|
||||
statement.setInt(8, total_deaths);
|
||||
|
||||
statement.addBatch();
|
||||
id += 1;
|
||||
|
||||
if (count % batchSize == 0) {
|
||||
statement.executeBatch();
|
||||
}
|
||||
|
||||
}
|
||||
lineReader.close();
|
||||
|
||||
// Print out the database for great justice
|
||||
/*
|
||||
* sql = "select * from entry";
|
||||
*
|
||||
* statement = connection.prepareStatement(sql); ResultSet rs =
|
||||
* statement.executeQuery();
|
||||
*
|
||||
* while(rs.next()) { System.out.print("ID = " + rs.getString("id") + " ");
|
||||
* System.out.print("State = " + rs.getString("state") + " ");
|
||||
* System.out.print("Month = " + rs.getString("month") + " ");
|
||||
* System.out.print("Day = " + rs.getString("day") + " ");
|
||||
* System.out.print("Daily infected = " + rs.getString("daily_infections") +
|
||||
* " "); System.out.print("Daily Death = " + rs.getString("daily_deaths") +
|
||||
* " "); System.out.print("Total infected = " + rs.getString("total_infections")
|
||||
* + " "); System.out.println("Total death = " + rs.getString("total_deaths"));
|
||||
* }
|
||||
*/
|
||||
// execute the remaining queries
|
||||
statement.executeBatch();
|
||||
|
||||
connection.commit();
|
||||
connection.close();
|
||||
|
||||
} catch (IOException ex) {
|
||||
System.err.println(ex);
|
||||
} catch (SQLException ex) {
|
||||
ex.printStackTrace();
|
||||
|
||||
try {
|
||||
connection.rollback();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public ArrayList<CovidEntry> topTenDeaths(int m, int d) {
|
||||
ArrayList<CovidEntry> result = new ArrayList<CovidEntry>();
|
||||
ArrayList<CovidEntry> temp = getDailyDeaths(m, d);
|
||||
|
||||
Collections.sort(temp);
|
||||
if (temp.size() == 0) {
|
||||
return result;
|
||||
}
|
||||
|
||||
for (int i = 0; i < 10; i++) {
|
||||
result.add(temp.get(i));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
for (int i = 0; i < 10; i++){
|
||||
result.add(temp.get(i));
|
||||
public ArrayList<CovidEntry> safeToOpen(String st) {
|
||||
ArrayList<CovidEntry> result = new ArrayList<CovidEntry>();
|
||||
int match = 0;
|
||||
int previousDailyInfections = -1;
|
||||
|
||||
for (CovidEntry c : list) {
|
||||
if (c.getState().equalsIgnoreCase(st)) {
|
||||
if (previousDailyInfections == -1) {
|
||||
previousDailyInfections = c.getDailyInfections();
|
||||
match += 1;
|
||||
} else if (c.getDailyInfections() < previousDailyInfections) {
|
||||
match += 1;
|
||||
} else {
|
||||
match = 1;
|
||||
result.clear();
|
||||
}
|
||||
result.add(c);
|
||||
|
||||
previousDailyInfections = c.getDailyInfections();
|
||||
}
|
||||
if (match == SAFE) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public ArrayList <CovidEntry> safeToOpen(String st){
|
||||
ArrayList<CovidEntry> result = new ArrayList<CovidEntry>();
|
||||
int match = 0;
|
||||
int previousDailyInfections = -1;
|
||||
public ArrayList<CovidEntry> listMinimumDailyInfections(int m, int d, int min) {
|
||||
ArrayList<CovidEntry> result = new ArrayList<CovidEntry>();
|
||||
|
||||
for (CovidEntry c: list){
|
||||
if (c.getState().equalsIgnoreCase(st)) {
|
||||
if (previousDailyInfections == -1) {
|
||||
previousDailyInfections = c.getDailyInfections();
|
||||
match += 1;
|
||||
for (CovidEntry c : list) {
|
||||
if (c.getMonth() == m && c.getDay() == d && c.getDailyInfections() >= min) {
|
||||
result.add(c);
|
||||
}
|
||||
}
|
||||
else if (c.getDailyInfections() < previousDailyInfections) {
|
||||
match += 1;
|
||||
} else {
|
||||
match = 1;
|
||||
result.clear();
|
||||
}
|
||||
result.add(c);
|
||||
|
||||
previousDailyInfections = c.getDailyInfections();
|
||||
}
|
||||
if (match == SAFE) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public ArrayList <CovidEntry>
|
||||
listMinimumDailyInfections(int m, int d, int min){
|
||||
ArrayList<CovidEntry> result = new ArrayList<CovidEntry>();
|
||||
|
||||
for (CovidEntry c: list){
|
||||
if (c.getMonth() == m && c.getDay() == d && c.getDailyInfections() >= min){
|
||||
result.add(c);
|
||||
}
|
||||
public int countRecords() {
|
||||
return list.size();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public int countRecords(){
|
||||
return list.size();
|
||||
}
|
||||
|
||||
public int getTotalDeaths(){
|
||||
int result = 0;
|
||||
public int getTotalDeaths() {
|
||||
int result = 0;
|
||||
|
||||
for (CovidEntry c: list){
|
||||
result += c.getDailyDeaths();
|
||||
for (CovidEntry c : list) {
|
||||
result += c.getDailyDeaths();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public int getTotalInfections(){
|
||||
int result = 0;
|
||||
public int getTotalInfections() {
|
||||
int result = 0;
|
||||
|
||||
for (CovidEntry c: list){
|
||||
result += c.getDailyInfections();
|
||||
for (CovidEntry c : list) {
|
||||
result += c.getDailyInfections();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public int countTotalInfections(int m, int d){
|
||||
int result = 0;
|
||||
public int countTotalInfections(int m, int d) {
|
||||
int result = 0;
|
||||
|
||||
for (CovidEntry c: list){
|
||||
if (c.getMonth() == m && c.getDay() == d){
|
||||
result += c.getDailyInfections();
|
||||
}
|
||||
for (CovidEntry c : list) {
|
||||
if (c.getMonth() == m && c.getDay() == d) {
|
||||
result += c.getDailyInfections();
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public int countTotalDeaths(int m, int d){
|
||||
int result = 0;
|
||||
public int countTotalDeaths(int m, int d) {
|
||||
int result = 0;
|
||||
|
||||
for (CovidEntry c: list){
|
||||
if (c.getMonth() == m && c.getDay() == d){
|
||||
result += c.getDailyDeaths();
|
||||
}
|
||||
for (CovidEntry c : list) {
|
||||
if (c.getMonth() == m && c.getDay() == d) {
|
||||
result += c.getDailyDeaths();
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public ArrayList <CovidEntry> getDailyDeaths(int m, int d){
|
||||
ArrayList<CovidEntry> result = new ArrayList<CovidEntry>();
|
||||
public ArrayList<CovidEntry> getDailyDeaths(int m, int d) {
|
||||
ArrayList<CovidEntry> result = new ArrayList<CovidEntry>();
|
||||
|
||||
for (CovidEntry c: list){
|
||||
if (c.getMonth() == m && c.getDay() == d){
|
||||
result.add(c);
|
||||
}
|
||||
for (CovidEntry c : list) {
|
||||
if (c.getMonth() == m && c.getDay() == d) {
|
||||
result.add(c);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
//State
|
||||
// State
|
||||
public CovidEntry peakDailyDeaths(String st) {
|
||||
//iterate over our database
|
||||
//find highest deathcount that matches our state (st)
|
||||
CovidEntry result = null;
|
||||
int max = 0;
|
||||
// iterate over our database
|
||||
// find highest deathcount that matches our state (st)
|
||||
CovidEntry result = null;
|
||||
int max = 0;
|
||||
|
||||
for(CovidEntry c : list){
|
||||
if( c.getState().equalsIgnoreCase(st)){
|
||||
if( c.getDailyDeaths() > max){
|
||||
max = c.getDailyDeaths();
|
||||
result = c;
|
||||
}
|
||||
for (CovidEntry c : list) {
|
||||
if (c.getState().equalsIgnoreCase(st)) {
|
||||
if (c.getDailyDeaths() > max) {
|
||||
max = c.getDailyDeaths();
|
||||
result = c;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
return result;
|
||||
}
|
||||
|
||||
//Month day
|
||||
public CovidEntry peakDailyDeaths(int m, int d) {
|
||||
//iterate over our database
|
||||
//find highest deathcount that matches our state (st)
|
||||
CovidEntry result = null;
|
||||
int max = 0;
|
||||
// Month day
|
||||
public CovidEntry peakDailyDeaths(int m, int d) {
|
||||
// iterate over our database
|
||||
// find highest deathcount that matches our state (st)
|
||||
CovidEntry result = null;
|
||||
int max = 0;
|
||||
|
||||
for(CovidEntry c : list){
|
||||
if (c.getMonth() == m && c.getDay() == d) {
|
||||
if (c.getDailyDeaths() > max) {
|
||||
max = c.getDailyDeaths();
|
||||
result = c;
|
||||
}
|
||||
for (CovidEntry c : list) {
|
||||
if (c.getMonth() == m && c.getDay() == d) {
|
||||
if (c.getDailyDeaths() > max) {
|
||||
max = c.getDailyDeaths();
|
||||
result = c;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public CovidEntry mostTotalDeaths(){
|
||||
CovidEntry result = null;
|
||||
int max = 0;
|
||||
|
||||
for(CovidEntry c : list){
|
||||
if( c.getTotalDeaths() > max){
|
||||
max = c.getTotalDeaths();
|
||||
result = c;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public void readCovidData(String filename){
|
||||
Scanner scnr = null;
|
||||
FileInputStream fs = null;
|
||||
try{
|
||||
fs = new FileInputStream(filename);
|
||||
scnr = new Scanner(fs);
|
||||
scnr.useDelimiter("[,\r\n]+");
|
||||
scnr.nextLine();
|
||||
while(scnr.hasNext()){
|
||||
String state = scnr.next();
|
||||
int month = scnr.nextInt();
|
||||
int day = scnr.nextInt();
|
||||
int di = scnr.nextInt();
|
||||
int dd = scnr.nextInt();
|
||||
int ti = scnr.nextInt();
|
||||
int td = scnr.nextInt();
|
||||
|
||||
CovidEntry c = new CovidEntry(state,
|
||||
month, day, di, dd, ti, td);
|
||||
list.add(c);
|
||||
}
|
||||
fs.close();
|
||||
}
|
||||
catch(Exception e){
|
||||
System.out.println("File error with " + filename);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public CovidEntry mostTotalDeaths() {
|
||||
CovidEntry result = null;
|
||||
int max = 0;
|
||||
|
||||
for (CovidEntry c : list) {
|
||||
if (c.getTotalDeaths() > max) {
|
||||
max = c.getTotalDeaths();
|
||||
result = c;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
* public void readCovidData(String filename){ Scanner scnr = null;
|
||||
* FileInputStream fs = null; try{ fs = new FileInputStream(filename); scnr =
|
||||
* new Scanner(fs); scnr.useDelimiter("[,\r\n]+"); scnr.nextLine();
|
||||
* while(scnr.hasNext()){ String state = scnr.next(); int month =
|
||||
* scnr.nextInt(); int day = scnr.nextInt(); int di = scnr.nextInt(); int dd =
|
||||
* scnr.nextInt(); int ti = scnr.nextInt(); int td = scnr.nextInt();
|
||||
*
|
||||
* CovidEntry c = new CovidEntry(state, month, day, di, dd, ti, td);
|
||||
* list.add(c); } fs.close(); } catch(Exception e){
|
||||
* System.out.println("File error with " + filename); }
|
||||
*
|
||||
* }
|
||||
*
|
||||
* }
|
||||
*/
|
||||
public void readCovidData() {
|
||||
CovidEntry entry;
|
||||
|
||||
Connection connection = null;
|
||||
try {
|
||||
|
||||
connection = DriverManager.getConnection(jdbcURL);
|
||||
connection.setAutoCommit(false);
|
||||
|
||||
String sql = "select * from entry";
|
||||
|
||||
PreparedStatement statement = connection.prepareStatement(sql);
|
||||
ResultSet rs = statement.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
String state = rs.getString("state");
|
||||
int month = rs.getInt("month");
|
||||
int day = rs.getInt("day");
|
||||
int di = rs.getInt("daily_infections");
|
||||
int dd = rs.getInt("daily_deaths");
|
||||
int ti = rs.getInt("total_infections");
|
||||
int td = rs.getInt("total_deaths");
|
||||
|
||||
entry = new CovidEntry(state, month, day, di, dd, ti, td);
|
||||
list.add(entry);
|
||||
}
|
||||
|
||||
connection.commit();
|
||||
connection.close();
|
||||
}
|
||||
|
||||
catch (SQLException ex) {
|
||||
ex.printStackTrace();
|
||||
|
||||
try {
|
||||
connection.rollback();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,41 +1,41 @@
|
||||
public class CovidDatabaseTest {
|
||||
public static void main (String[] args) {
|
||||
System.out.println ("Testing starts");
|
||||
CovidDatabase db = new CovidDatabase() ;
|
||||
db.readCovidData("covid_data.csv");
|
||||
// check number of records, total infections, and total deaths
|
||||
assert db.countRecords() == 10346 : "database should have 10,346";
|
||||
|
||||
assert db.getTotalDeaths() == 196696 : "Total deaths should be: 196,696";
|
||||
assert db.getTotalInfections() == 7032090 : "infections should be: 7,032,090";
|
||||
// check peak daily deaths for 5/5
|
||||
CovidEntry mostDeaths = db.peakDailyDeaths(5, 5);
|
||||
assert mostDeaths.getState().equals("PA") : "State with most deaths for 5/5 is PA";
|
||||
assert mostDeaths.getDailyDeaths() == 554 : "Deaths for 5/5 is PA: 554";
|
||||
// test other methods
|
||||
public static void main(String[] args) {
|
||||
System.out.println("Testing starts");
|
||||
CovidDatabase db = new CovidDatabase();
|
||||
db.readCovidData();
|
||||
// check number of records, total infections, and total deaths
|
||||
assert db.countRecords() == 10346 : "database should have 10,346";
|
||||
|
||||
// Check highest deaths
|
||||
CovidEntry highestTX = db.peakDailyDeaths("TX");
|
||||
assert highestTX.getDailyDeaths() == 675 : "Highest texas deaths is: 675";
|
||||
assert db.getTotalDeaths() == 196696 : "Total deaths should be: 196,696";
|
||||
assert db.getTotalInfections() == 7032090 : "infections should be: 7,032,090";
|
||||
// check peak daily deaths for 5/5
|
||||
CovidEntry mostDeaths = db.peakDailyDeaths(5, 5);
|
||||
assert mostDeaths.getState().equals("PA") : "State with most deaths for 5/5 is PA";
|
||||
assert mostDeaths.getDailyDeaths() == 554 : "Deaths for 5/5 is PA: 554";
|
||||
// test other methods
|
||||
|
||||
// Most total deaths
|
||||
assert db.mostTotalDeaths().getTotalDeaths() == 25456 : "Highest deaths is 25456";
|
||||
assert db.mostTotalDeaths().getState().equals("NY") : "Highest deaths state: NY";
|
||||
// Check highest deaths
|
||||
CovidEntry highestTX = db.peakDailyDeaths("TX");
|
||||
assert highestTX.getDailyDeaths() == 675 : "Highest texas deaths is: 675";
|
||||
|
||||
// Peak daily deaths
|
||||
assert db.peakDailyDeaths("MI").getDailyDeaths() == 169 : "Highest MI Deaths: 169";
|
||||
assert db.peakDailyDeaths(5, 5).getDailyDeaths() == 554 : "Highest 5/5 deaths: PA";
|
||||
// Most total deaths
|
||||
assert db.mostTotalDeaths().getTotalDeaths() == 25456 : "Highest deaths is 25456";
|
||||
assert db.mostTotalDeaths().getState().equals("NY") : "Highest deaths state: NY";
|
||||
|
||||
// Top ten deaths
|
||||
assert db.topTenDeaths(5, 5).size() == 10 : "Top ten deaths should be 10";
|
||||
assert db.topTenDeaths(5, 5).get(0).getState().equals("PA") : "First Top ten deaths should be PA";
|
||||
// Peak daily deaths
|
||||
assert db.peakDailyDeaths("MI").getDailyDeaths() == 169 : "Highest MI Deaths: 169";
|
||||
assert db.peakDailyDeaths(5, 5).getDailyDeaths() == 554 : "Highest 5/5 deaths: PA";
|
||||
|
||||
// Safe to open
|
||||
assert db.safeToOpen("MI").get(0).getDailyInfections() == 443 : "First entry should have 443 infections";
|
||||
// Top ten deaths
|
||||
assert db.topTenDeaths(5, 5).size() == 10 : "Top ten deaths should be 10";
|
||||
assert db.topTenDeaths(5, 5).get(0).getState().equals("PA") : "First Top ten deaths should be PA";
|
||||
|
||||
//list min daily infections
|
||||
assert db.listMinimumDailyInfections(6,12,1000).get(0).getState().equals("TX") : "First entry should be TX";
|
||||
// Safe to open
|
||||
assert db.safeToOpen("MI").get(0).getDailyInfections() == 443 : "First entry should have 443 infections";
|
||||
|
||||
System.out.println ("Testing ends");
|
||||
}
|
||||
// list min daily infections
|
||||
assert db.listMinimumDailyInfections(6, 12, 1000).get(0).getState().equals("TX") : "First entry should be TX";
|
||||
|
||||
System.out.println("Testing ends");
|
||||
}
|
||||
}
|
||||
|
@ -2,50 +2,63 @@ import java.text.DecimalFormat;
|
||||
|
||||
public class CovidEntry implements Comparable {
|
||||
|
||||
//Private vars
|
||||
private String state;
|
||||
private int month, day;
|
||||
private int dailyDeaths, dailyInfections;
|
||||
private int totalDeaths, totalInfections;
|
||||
private static DecimalFormat df;
|
||||
// Private vars
|
||||
private String state;
|
||||
private int month, day;
|
||||
private int dailyDeaths, dailyInfections;
|
||||
private int totalDeaths, totalInfections;
|
||||
private static DecimalFormat df;
|
||||
|
||||
//Constructor
|
||||
public CovidEntry(String st, int m, int d, int di, int dd,
|
||||
int ti, int td){
|
||||
this.state = st;
|
||||
this.month = m;
|
||||
this.day = d;
|
||||
this.dailyInfections = di;
|
||||
this.dailyDeaths = dd;
|
||||
this.totalDeaths = td;
|
||||
this.totalInfections = ti;
|
||||
// Constructor
|
||||
public CovidEntry(String st, int m, int d, int di, int dd, int ti, int td) {
|
||||
this.state = st;
|
||||
this.month = m;
|
||||
this.day = d;
|
||||
this.dailyInfections = di;
|
||||
this.dailyDeaths = dd;
|
||||
this.totalDeaths = td;
|
||||
this.totalInfections = ti;
|
||||
|
||||
df = new DecimalFormat("#,###,###");
|
||||
}
|
||||
df = new DecimalFormat("#,###,###");
|
||||
}
|
||||
|
||||
//accessors
|
||||
public int getMonth(){return month;}
|
||||
// accessors
|
||||
public int getMonth() {
|
||||
return month;
|
||||
}
|
||||
|
||||
public int getDay(){return day;}
|
||||
public int getDay() {
|
||||
return day;
|
||||
}
|
||||
|
||||
public String getState(){return state;}
|
||||
public String getState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
public int getDailyInfections(){return dailyInfections;}
|
||||
public int getDailyInfections() {
|
||||
return dailyInfections;
|
||||
}
|
||||
|
||||
public int getDailyDeaths(){return dailyDeaths;}
|
||||
public int getDailyDeaths() {
|
||||
return dailyDeaths;
|
||||
}
|
||||
|
||||
public int getTotalDeaths(){return totalDeaths;}
|
||||
public int getTotalDeaths() {
|
||||
return totalDeaths;
|
||||
}
|
||||
|
||||
public int getTotalInfections(){return totalInfections;}
|
||||
public String toString(){
|
||||
return state + " " + month + "/" + day + " " +
|
||||
df.format(dailyInfections) + " infections, " +
|
||||
df.format(dailyDeaths) + " deaths";
|
||||
}
|
||||
public int getTotalInfections() {
|
||||
return totalInfections;
|
||||
}
|
||||
|
||||
public int compareTo(Object other){
|
||||
CovidEntry c = (CovidEntry) other;
|
||||
return c.dailyDeaths - dailyDeaths;
|
||||
}
|
||||
public String toString() {
|
||||
return state + " " + month + "/" + day + " " + df.format(dailyInfections) + " infections, "
|
||||
+ df.format(dailyDeaths) + " deaths";
|
||||
}
|
||||
|
||||
public int compareTo(Object other) {
|
||||
CovidEntry c = (CovidEntry) other;
|
||||
return c.dailyDeaths - dailyDeaths;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -3,58 +3,51 @@ import java.util.ArrayList;
|
||||
//time 11:10 - 11:22
|
||||
//time 12:00 - 16:10
|
||||
//time1 - 10:10 10:30
|
||||
|
||||
//~11:30 - 15:30 -- didn't realize how to class path properly to include both
|
||||
//what I've done, and the jar file until seeing how intellij did it.
|
||||
//Web searches were not very helpful in this depot
|
||||
public class CovidManager {
|
||||
public static void main( String[] args){
|
||||
CovidEntry covidObject =
|
||||
new CovidEntry("TX",
|
||||
4, 12,
|
||||
233343,
|
||||
5,
|
||||
10,
|
||||
15);
|
||||
System.out.println(covidObject);
|
||||
public static void main(String[] args) {
|
||||
CovidEntry covidObject = new CovidEntry("TX", 4, 12, 233343, 5, 10, 15);
|
||||
System.out.println(covidObject);
|
||||
|
||||
CovidDatabase db = new CovidDatabase();
|
||||
db.readCovidData("data/covid_data.csv");
|
||||
System.out.println("highest daily d for texas");
|
||||
CovidEntry highestTX = db.peakDailyDeaths("TX");
|
||||
System.out.println(highestTX);
|
||||
CovidDatabase db = new CovidDatabase();
|
||||
db.readCovidData();
|
||||
System.out.println("highest daily d for texas");
|
||||
CovidEntry highestTX = db.peakDailyDeaths("TX");
|
||||
System.out.println(highestTX);
|
||||
|
||||
ArrayList<CovidEntry> may5th = db.getDailyDeaths(5, 5);
|
||||
System.out.println("May 5th Data");
|
||||
for (CovidEntry c: may5th){
|
||||
System.out.println(c);
|
||||
ArrayList<CovidEntry> may5th = db.getDailyDeaths(5, 5);
|
||||
System.out.println("May 5th Data");
|
||||
for (CovidEntry c : may5th) {
|
||||
System.out.println(c);
|
||||
}
|
||||
|
||||
int totalInfections = db.getTotalInfections();
|
||||
System.out.println("Total Infections " + totalInfections);
|
||||
|
||||
System.out.println("Total Records: " + db.countRecords());
|
||||
System.out.println("Total Deaths: " + db.getTotalDeaths());
|
||||
System.out.println("Total Deaths for May 5th: " + db.countTotalDeaths(5, 5));
|
||||
System.out.println("Peak deaths for May 5th: " + db.peakDailyDeaths(5, 5));
|
||||
System.out.println(
|
||||
"Most total deaths: " + db.mostTotalDeaths() + " Total: " + db.mostTotalDeaths().getTotalDeaths());
|
||||
System.out.println("States with less than 300 infections on may 5th: ");
|
||||
may5th = db.listMinimumDailyInfections(5, 5, 300);
|
||||
for (CovidEntry c : may5th) {
|
||||
System.out.println(c);
|
||||
}
|
||||
|
||||
System.out.println("WA safe to open: ");
|
||||
ArrayList<CovidEntry> WASafe = db.safeToOpen("WA");
|
||||
for (CovidEntry c : WASafe) {
|
||||
System.out.println(c);
|
||||
}
|
||||
|
||||
System.out.println("Top 10 deaths for May 1st");
|
||||
ArrayList<CovidEntry> topTenDeaths = db.topTenDeaths(5, 1);
|
||||
for (CovidEntry c : topTenDeaths) {
|
||||
System.out.println(c);
|
||||
}
|
||||
}
|
||||
|
||||
int totalInfections = db.getTotalInfections();
|
||||
System.out.println("Total Infections " + totalInfections);
|
||||
|
||||
System.out.println("Total Records: " + db.countRecords());
|
||||
System.out.println("Total Deaths: " + db.getTotalDeaths());
|
||||
System.out.println("Total Deaths for May 5th: " + db.countTotalDeaths(5, 5));
|
||||
System.out.println("Peak deaths for May 5th: " + db.peakDailyDeaths(5, 5));
|
||||
System.out.println("Most total deaths: " + db.mostTotalDeaths() + " Total: " +
|
||||
db.mostTotalDeaths().getTotalDeaths());
|
||||
System.out.println("States with less than 300 infections on may 5th: ");
|
||||
may5th = db.listMinimumDailyInfections(5, 5, 300);
|
||||
for (CovidEntry c: may5th){
|
||||
System.out.println(c);
|
||||
}
|
||||
|
||||
System.out.println("WA safe to open: ");
|
||||
ArrayList<CovidEntry> WASafe = db.safeToOpen("WA");
|
||||
for (CovidEntry c: WASafe){
|
||||
System.out.println(c);
|
||||
}
|
||||
|
||||
System.out.println("Top 10 deaths for May 1st");
|
||||
ArrayList<CovidEntry> topTenDeaths = db.topTenDeaths(5, 1);
|
||||
for (CovidEntry c: topTenDeaths){
|
||||
System.out.println(c);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
2
java/final-project/Lib/linux_start.sh
Executable file
2
java/final-project/Lib/linux_start.sh
Executable file
@ -0,0 +1,2 @@
|
||||
#!/bin/sh
|
||||
java -cp /home/logen/programming/school/java/final-project/lib/sqlite-jdbc-3.34.0.jar test.java
|
BIN
java/final-project/Lib/sample.db
Normal file
BIN
java/final-project/Lib/sample.db
Normal file
Binary file not shown.
BIN
java/final-project/Lib/sqlite-jdbc-3.34.0.jar
Normal file
BIN
java/final-project/Lib/sqlite-jdbc-3.34.0.jar
Normal file
Binary file not shown.
51
java/final-project/Lib/test.java
Normal file
51
java/final-project/Lib/test.java
Normal file
@ -0,0 +1,51 @@
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
|
||||
public class Sample
|
||||
{
|
||||
public static void main(String[] args)
|
||||
{
|
||||
Connection connection = null;
|
||||
try
|
||||
{
|
||||
// create a database connection
|
||||
connection = DriverManager.getConnection("jdbc:sqlite:sample.db");
|
||||
Statement statement = connection.createStatement();
|
||||
statement.setQueryTimeout(30); // set timeout to 30 sec.
|
||||
|
||||
statement.executeUpdate("drop table if exists person");
|
||||
statement.executeUpdate("create table person (id integer, name string)");
|
||||
statement.executeUpdate("insert into person values(1, 'leo')");
|
||||
statement.executeUpdate("insert into person values(2, 'yui')");
|
||||
ResultSet rs = statement.executeQuery("select * from person");
|
||||
while(rs.next())
|
||||
{
|
||||
// read the result set
|
||||
System.out.println("name = " + rs.getString("name"));
|
||||
System.out.println("id = " + rs.getInt("id"));
|
||||
}
|
||||
}
|
||||
catch(SQLException e)
|
||||
{
|
||||
// if the error message is "out of memory",
|
||||
// it probably means no database file is found
|
||||
System.err.println(e.getMessage());
|
||||
}
|
||||
finally
|
||||
{
|
||||
try
|
||||
{
|
||||
if(connection != null)
|
||||
connection.close();
|
||||
}
|
||||
catch(SQLException e)
|
||||
{
|
||||
// connection close failed.
|
||||
System.err.println(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
BIN
java/final-project/ScreenShots/coverpage.odt
Normal file
BIN
java/final-project/ScreenShots/coverpage.odt
Normal file
Binary file not shown.
BIN
java/final-project/ScreenShots/coverpage.pdf
Normal file
BIN
java/final-project/ScreenShots/coverpage.pdf
Normal file
Binary file not shown.
BIN
java/final-project/covid.db
Normal file
BIN
java/final-project/covid.db
Normal file
Binary file not shown.
3
java/final-project/linux_start.sh
Executable file
3
java/final-project/linux_start.sh
Executable file
@ -0,0 +1,3 @@
|
||||
#!/bin/sh
|
||||
javac *.java
|
||||
java -cp .:sqlite-jdbc-3.34.0.jar CovidManager
|
102
java/final-project/old/CvsTranslate.java
Normal file
102
java/final-project/old/CvsTranslate.java
Normal file
@ -0,0 +1,102 @@
|
||||
// copyright by https://www.codejava.net
|
||||
import java.io.*;
|
||||
import java.sql.*;
|
||||
|
||||
public class CvsTranslate {
|
||||
|
||||
public static void main(String[] args) {
|
||||
String jdbcURL = "jdbc:sqlite:covid.db";
|
||||
|
||||
String csvFilePath = "covid_data.csv";
|
||||
|
||||
int batchSize = 20;
|
||||
|
||||
Connection connection = null;
|
||||
|
||||
try {
|
||||
|
||||
connection = DriverManager.getConnection(jdbcURL);
|
||||
connection.setAutoCommit(false);
|
||||
Statement makeTable = connection.createStatement();
|
||||
makeTable.executeUpdate("drop table if exists entry");
|
||||
makeTable.executeUpdate("create table entry (id integer, state string, month integer, day integer, daily_infections integer, daily_deaths integer, total_infections integer, total_deaths integer)");
|
||||
|
||||
String sql = "INSERT INTO entry (id, state, month, day, daily_infections, daily_deaths, total_infections, total_deaths) VALUES (?, ?, ?, ?, ?, ?, ?, ?)";
|
||||
PreparedStatement statement = connection.prepareStatement(sql);
|
||||
|
||||
BufferedReader lineReader = new BufferedReader(new FileReader(csvFilePath));
|
||||
String lineText = null;
|
||||
|
||||
int count = 0;
|
||||
|
||||
lineReader.readLine(); // skip header line
|
||||
int id = 0;
|
||||
|
||||
while ((lineText = lineReader.readLine()) != null) {
|
||||
String[] data = lineText.split(",");
|
||||
String state = data[0];
|
||||
int month = Integer.parseInt(data[1]);
|
||||
int day = Integer.parseInt(data[2]);
|
||||
int daily_infections = Integer.parseInt(data[3]);
|
||||
int daily_deaths = Integer.parseInt(data[4]);
|
||||
int total_infections = Integer.parseInt(data[5]);
|
||||
int total_deaths = Integer.parseInt(data[6]);
|
||||
|
||||
statement.setInt(1, id);
|
||||
statement.setString(2, state);
|
||||
statement.setInt(3, month);
|
||||
statement.setInt(4, day);
|
||||
statement.setInt(5, daily_infections);
|
||||
statement.setInt(6, daily_deaths);
|
||||
statement.setInt(7, total_infections);
|
||||
statement.setInt(8, total_deaths);
|
||||
|
||||
statement.addBatch();
|
||||
id += 1;
|
||||
|
||||
if (count % batchSize == 0) {
|
||||
statement.executeBatch();
|
||||
}
|
||||
|
||||
}
|
||||
lineReader.close();
|
||||
|
||||
// execute the remaining queries
|
||||
statement.executeBatch();
|
||||
|
||||
// Print out the database for great justice
|
||||
sql = "select * from entry";
|
||||
|
||||
statement = connection.prepareStatement(sql);
|
||||
ResultSet rs = statement.executeQuery();
|
||||
|
||||
while(rs.next())
|
||||
{
|
||||
System.out.print("ID = " + rs.getString("id") + " ");
|
||||
System.out.print("State = " + rs.getString("state") + " ");
|
||||
System.out.print("Month = " + rs.getString("month") + " ");
|
||||
System.out.print("Day = " + rs.getString("day") + " ");
|
||||
System.out.print("Daily infected = " + rs.getString("daily_infections") + " ");
|
||||
System.out.print("Daily Death = " + rs.getString("daily_deaths") + " ");
|
||||
System.out.print("Total infected = " + rs.getString("total_infections") + " ");
|
||||
System.out.println("Total death = " + rs.getString("total_deaths"));
|
||||
}
|
||||
|
||||
|
||||
connection.commit();
|
||||
connection.close();
|
||||
|
||||
} catch (IOException ex) {
|
||||
System.err.println(ex);
|
||||
} catch (SQLException ex) {
|
||||
ex.printStackTrace();
|
||||
|
||||
try {
|
||||
connection.rollback();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
2
java/final-project/old/run_translate.sh
Executable file
2
java/final-project/old/run_translate.sh
Executable file
@ -0,0 +1,2 @@
|
||||
#!/bin/sh
|
||||
java -cp /home/logen/programming/school/java/final-project/lib/sqlite-jdbc-3.34.0.jar CvsTranslate.java
|
BIN
java/final-project/sqlite-jdbc-3.34.0.jar
Normal file
BIN
java/final-project/sqlite-jdbc-3.34.0.jar
Normal file
Binary file not shown.
267
java/final-project/tests/CovidDatabaseJUnit.java
Normal file
267
java/final-project/tests/CovidDatabaseJUnit.java
Normal file
@ -0,0 +1,267 @@
|
||||
import static org.junit.Assert.*;
|
||||
import java.util.ArrayList;
|
||||
import org.junit.*;
|
||||
/*******************************************
|
||||
* Class to test the CovidDatabase project
|
||||
*
|
||||
* @author -
|
||||
* @version -
|
||||
******************************************/
|
||||
public class CovidDatabaseJUnit{
|
||||
/** object of the CovidDatabase class */
|
||||
private CovidDatabase database;
|
||||
|
||||
/******************************************************
|
||||
* Test constructor
|
||||
*****************************************************/
|
||||
@Test
|
||||
public void testConstructor()
|
||||
{
|
||||
database= new CovidDatabase();
|
||||
assertEquals("ArrayList should not contain any records at this time",
|
||||
0, database.countRecords ());
|
||||
}
|
||||
|
||||
/******************************************************
|
||||
* Test read file and counts
|
||||
*****************************************************/
|
||||
@Test
|
||||
public void testReadFileAndCounts()
|
||||
{
|
||||
database= new CovidDatabase();
|
||||
database.readCovidData("covid_data.csv");
|
||||
assertEquals("ArrayList should not contain 10346 records",
|
||||
10346, database.countRecords ());
|
||||
}
|
||||
|
||||
/******************************************************
|
||||
* Test statics for all the covid entries
|
||||
*****************************************************/
|
||||
@Test
|
||||
public void testStatistics()
|
||||
{
|
||||
database= new CovidDatabase();
|
||||
database.readCovidData("covid_data.csv");
|
||||
|
||||
// testing total deaths
|
||||
assertEquals("Total deaths up to 9/27 should be 196,696",
|
||||
196696, database.getTotalDeaths());
|
||||
|
||||
// testing total infections
|
||||
assertEquals("Total infections up to 9/27 should be 7,032,090",
|
||||
7032090, database.getTotalInfections());
|
||||
|
||||
// testing most total infections
|
||||
CovidEntry c = database.mostTotalDeaths();
|
||||
assertEquals("State with most total deaths up to 9/27 is NY",
|
||||
"NY", c.getState());
|
||||
assertEquals("Number of deaths in NY up to 9/27: 25,456" ,
|
||||
25456, c.getTotalDeaths());
|
||||
}
|
||||
|
||||
/******************************************************
|
||||
* Test peak daily deaths
|
||||
*****************************************************/
|
||||
@Test
|
||||
public void testPeakDailyDeaths()
|
||||
{
|
||||
database= new CovidDatabase();
|
||||
database.readCovidData("covid_data.csv");
|
||||
CovidEntry c;
|
||||
|
||||
// testing peak daily deaths for a date 8/12
|
||||
c = database.peakDailyDeaths(8, 12);
|
||||
assertEquals("State with peak deaths on 8/12 is TX",
|
||||
"TX", c.getState());
|
||||
assertEquals("Number deaths in TX on 8/12: 324" ,
|
||||
324, c.getDailyDeaths());
|
||||
|
||||
// testing peak daily deaths for a state
|
||||
c = database.peakDailyDeaths("MI");
|
||||
assertEquals("Peak deaths up to 9/27 in MI",
|
||||
"MI", c.getState());
|
||||
assertEquals("Peak number of deaths for MI: 169" ,
|
||||
169, c.getDailyDeaths());
|
||||
|
||||
// testing peak daily deaths for a date 4/30
|
||||
c = database.peakDailyDeaths(4, 30);
|
||||
assertEquals("State with peak deaths on 4/30 is NJ",
|
||||
"NJ", c.getState());
|
||||
assertEquals("Number deaths in NJ on 4/30: 481" ,
|
||||
481, c.getDailyDeaths());
|
||||
|
||||
// testing peak daily deaths for a state
|
||||
c = database.peakDailyDeaths("NY");
|
||||
assertEquals("Peak deaths up to 9/27 in NY",
|
||||
"NY", c.getState());
|
||||
assertEquals("Peak number of deaths for NY: 951" ,
|
||||
951, c.getDailyDeaths());
|
||||
|
||||
}
|
||||
|
||||
/******************************************************
|
||||
* Test peak daily deaths - invalid state & invalid date
|
||||
*****************************************************/
|
||||
@Test
|
||||
public void testPeakDailyDeathsInvalidParameters()
|
||||
{
|
||||
database= new CovidDatabase();
|
||||
database.readCovidData("covid_data.csv");
|
||||
CovidEntry c;
|
||||
|
||||
// testing peak daily deaths for an invalid date
|
||||
c = database.peakDailyDeaths(13, 12);
|
||||
assertEquals("Wrong date 13/12 should return null",
|
||||
null, c);
|
||||
|
||||
// testing peak daily deaths for an invalid state
|
||||
c = database.peakDailyDeaths("XX");
|
||||
assertEquals("Wrong state XX should return null" ,
|
||||
null, c);
|
||||
|
||||
// testing peak daily deaths for date not found in the file
|
||||
c = database.peakDailyDeaths(1, 1);
|
||||
assertEquals("No records for 1/1 should return null",
|
||||
null, c);
|
||||
}
|
||||
|
||||
/******************************************************
|
||||
* Test safe to open
|
||||
*****************************************************/
|
||||
@Test
|
||||
public void testSafeToOpen() {
|
||||
ArrayList<CovidEntry> list;
|
||||
database= new CovidDatabase();
|
||||
database.readCovidData("covid_data.csv");
|
||||
|
||||
// testing safe to open WA
|
||||
list = database.safeToOpen("WA");
|
||||
assertEquals("Safe to open should have 5 records" ,
|
||||
5, list.size());
|
||||
|
||||
//testing first record on the list
|
||||
assertEquals("The states should be WA",
|
||||
"WA", list.get(0).getState());
|
||||
assertEquals("Month in the first record in the sequence should be 5",
|
||||
5, list.get(0).getMonth());
|
||||
assertEquals("Day in the first record in the sequence should be 6",
|
||||
6, list.get(0).getDay());
|
||||
assertEquals("Infections in the first record in the sequence whould be 289",
|
||||
289, list.get(0).getDailyInfections());
|
||||
|
||||
//testing last record on the list
|
||||
assertEquals("The states should be WA",
|
||||
"WA", list.get(4).getState());
|
||||
assertEquals("Month in the lasst record in the sequence should be 5",
|
||||
5, list.get(4).getMonth());
|
||||
assertEquals("Day in the last record in the sequence should be 10",
|
||||
10, list.get(4).getDay());
|
||||
assertEquals("Infections in the last record in the sequence whould be 62",
|
||||
62, list.get(4).getDailyInfections());
|
||||
|
||||
// test safe to open - California
|
||||
list = database.safeToOpen("CA");
|
||||
assertEquals("Safe to open should have 5 records" ,
|
||||
5, list.size());
|
||||
|
||||
//testing first record on the list
|
||||
assertEquals("The states should be CA",
|
||||
"CA", list.get(0).getState());
|
||||
assertEquals("Month in the first record in the sequence should be 5\4",
|
||||
4, list.get(0).getMonth());
|
||||
assertEquals("Day in the first record in the sequence should be 21",
|
||||
21, list.get(0).getDay());
|
||||
assertEquals("Infections in the first record in the sequence whould be 2283",
|
||||
2283, list.get(0).getDailyInfections());
|
||||
|
||||
//testing last record on the list
|
||||
assertEquals("The states should be CA",
|
||||
"CA", list.get(4).getState());
|
||||
assertEquals("Month in the lasst record in the sequence should be 4",
|
||||
4, list.get(4).getMonth());
|
||||
assertEquals("Day in the last record in the sequence should be 25",
|
||||
25, list.get(4).getDay());
|
||||
assertEquals("Infections in the last record in the sequence whould be 1883",
|
||||
1883, list.get(4).getDailyInfections());
|
||||
|
||||
// testing a state not found in the database
|
||||
list = database.safeToOpen("ZZ");
|
||||
assertEquals("State not valid - safeToOpen should return null" ,
|
||||
null, list);
|
||||
}
|
||||
|
||||
/******************************************************
|
||||
* Test minimum infections on a date
|
||||
*****************************************************/
|
||||
@Test
|
||||
public void testMinInfections() {
|
||||
ArrayList<CovidEntry> list;
|
||||
database= new CovidDatabase();
|
||||
database.readCovidData("covid_data.csv");
|
||||
|
||||
// testing a Minimum of 2,500 infections on 9/11
|
||||
list = database.listMinimumDailyInfections(9, 11, 2500);
|
||||
assertEquals("three records with 2,500 infections or more on 9/11" ,
|
||||
3, list.size());
|
||||
|
||||
//testing highest - index 0
|
||||
assertEquals("TX should have the highest number of deaths on 8/1",
|
||||
"TX", list.get(0).getState());
|
||||
assertEquals("Infections in TX on 9/11 should be 3547",
|
||||
3547, list.get(0).getDailyInfections());
|
||||
|
||||
//testing last entry
|
||||
assertEquals("CA should be the last entry on the list",
|
||||
"CA", list.get(2).getState());
|
||||
assertEquals("Infections in CA on 9/11 should be 3326",
|
||||
3326, list.get(2).getDailyInfections());
|
||||
|
||||
// testing parameter values not found in database
|
||||
list = database.listMinimumDailyInfections(9, 11, 6000);
|
||||
assertEquals("Infections of 6,000 or more on 9/11 hould be zero" ,
|
||||
0, list.size());
|
||||
|
||||
// testing wrong parameter values
|
||||
list = database.listMinimumDailyInfections(13, 11, 10);
|
||||
assertEquals("Invalid date 13/11 Infections of 10 or more on 9/11 hould be zero" ,
|
||||
0, list.size());
|
||||
}
|
||||
|
||||
/******************************************************
|
||||
* Test top ten
|
||||
*****************************************************/
|
||||
@Test
|
||||
public void testTopTen() {
|
||||
ArrayList<CovidEntry> list;
|
||||
database= new CovidDatabase();
|
||||
database.readCovidData("covid_data.csv");
|
||||
|
||||
// testing top ten for 8/1
|
||||
list = database.topTenDeaths(8, 1);
|
||||
assertEquals("top ten number of records should be 10" ,
|
||||
10, list.size());
|
||||
|
||||
//testing highest - index 0
|
||||
assertEquals("TX should have the highest number of deaths on 8/1",
|
||||
"TX", list.get(0).getState());
|
||||
assertEquals("Deaths in TX on 8/1 should be 268",
|
||||
268, list.get(0).getDailyDeaths());
|
||||
|
||||
//testing CovidEntry at index 6
|
||||
assertEquals("NC should be at index 6 of the list of deaths on 8/1",
|
||||
"NC", list.get(6).getState());
|
||||
assertEquals("Deaths in NC on 8/1 should be 40",
|
||||
40, list.get(6).getDailyDeaths());
|
||||
|
||||
// testing a date not found in the database
|
||||
list = database.topTenDeaths(10, 31);
|
||||
assertEquals("top ten number of records should be zero" ,
|
||||
0, list.size());
|
||||
|
||||
// testing an invalid date
|
||||
list = database.topTenDeaths(-10, 31);
|
||||
assertEquals("top ten number of records should be zero" ,
|
||||
0, list.size());
|
||||
}
|
||||
}
|
||||
|
43
java/final-project/tests/CovidEntryJUnit.java
Normal file
43
java/final-project/tests/CovidEntryJUnit.java
Normal file
@ -0,0 +1,43 @@
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.*;
|
||||
/*******************************************
|
||||
* Class to test the CovidEntry class
|
||||
*
|
||||
* @author -
|
||||
* @version -
|
||||
******************************************/
|
||||
public class CovidEntryJUnit{
|
||||
/** object of the CovidEntry class*/
|
||||
private CovidEntry covid;
|
||||
|
||||
/******************************************************
|
||||
* Test constructor
|
||||
*****************************************************/
|
||||
@Test
|
||||
public void testConstructor() {
|
||||
//Testing a female baby name
|
||||
covid = new CovidEntry("MI",8,1,758,7,91332,6457);
|
||||
|
||||
assertEquals("Constructor: State should be equal to value of input parameter",
|
||||
"MI", covid.getState());
|
||||
|
||||
assertEquals("Constructor: month should be equal to value of input parameter",
|
||||
8, covid.getMonth());
|
||||
|
||||
assertEquals("Constructor: day should be equal to value of input parameter",
|
||||
1, covid.getDay());
|
||||
|
||||
assertEquals("Constructor: daily infections should be equal to value of input parameter",
|
||||
758, covid.getDailyInfections());
|
||||
|
||||
assertEquals("Constructor: daily deaths should be equal to value of input parameter",
|
||||
7, covid.getDailyDeaths());
|
||||
|
||||
assertEquals("Constructor: total infections should be equal to value of input parameter",
|
||||
91332, covid.getTotalInfections());
|
||||
|
||||
assertEquals("Constructor: total deaths should be equal to value of input parameter",
|
||||
6457, covid.getTotalDeaths());
|
||||
|
||||
}
|
||||
}
|
BIN
temp/a.out
Executable file
BIN
temp/a.out
Executable file
Binary file not shown.
23
temp/main.cpp
Normal file
23
temp/main.cpp
Normal file
@ -0,0 +1,23 @@
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
using namespace std;
|
||||
|
||||
int main() {
|
||||
string object1Info = "Pencil 5 4";
|
||||
string object2Info = "Notepad 13 12";
|
||||
string object3Info = "Headphones 23 26";
|
||||
|
||||
istringstream objectISS(object1Info);
|
||||
|
||||
string object;
|
||||
int quantity;
|
||||
int price;
|
||||
|
||||
objectISS >> object >> quantity >> price;
|
||||
|
||||
cout << object << " x" << quantity << endl;
|
||||
cout << "Price: " << price;
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user