Skip to content

Commit d433be2

Browse files
Add files via upload
1 parent b160731 commit d433be2

File tree

5 files changed

+119
-0
lines changed

5 files changed

+119
-0
lines changed

Project0.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import javax.swing.*;
2+
3+
public class Project0
4+
{
5+
public static void main(String[] args)
6+
{
7+
String input = JOptionPane.showInputDialog(null, "Please enter a sentence.");
8+
while(!input.equalsIgnoreCase("STOP"))
9+
{
10+
int lowercase = 0;
11+
int uppercase = 0;
12+
for(int i = 0; i < input.length(); i++)
13+
{
14+
if(new Character(input.charAt(i)).equals(new Character('e')))
15+
lowercase++;
16+
if(new Character(input.charAt(i)).equals(new Character('E')))
17+
uppercase++;
18+
}
19+
JOptionPane.showMessageDialog(null, "Number of lower case e's: " + lowercase + "\n" + " Number of upper case e's: " + uppercase);
20+
input = JOptionPane.showInputDialog(null, "Please enter a sentence.");
21+
}
22+
}
23+
}

Project1.java

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
// Much of this class is copied and adjusted from previous PowerPoints
2+
3+
// This imports the StringTokenizer class for use in this class
4+
import java.util.StringTokenizer;
5+
6+
// This creates a new public class called Project1
7+
public class Project1
8+
{
9+
// This creates a new main method
10+
public static void main(String[] args)
11+
{
12+
// This creates a new TextFileInput using the first command-line argument as the file name
13+
TextFileInput tfi = new TextFileInput(args[0]);
14+
// This initializes an arbitrarily large String array to store the dates
15+
String[] dates = new String[1000];
16+
// This uses the readLine method from TextFileInput to store the first String in the file, which is null if the file is empty
17+
String line = tfi.readLine();
18+
// This creates a new unitialized StringTokenizer
19+
StringTokenizer st;
20+
// This sets the initial value for the index of the array to 0
21+
int index = 0;
22+
// This creates an uninitialized String to store each day temporarily before testing and either accepting and storing or rejecting and printing them
23+
String day;
24+
// This performs the actions within as long as the line does not equal null (file has more lines) and index of the array is less than the length of the arbitraily long String array
25+
while(line != null && index < dates.length)
26+
{
27+
// Each time the loop is performed, this creates a initializes the StringTokenizer with the line from the File and "," as parameters
28+
st = new StringTokenizer(line, ",");
29+
// This performs the actions within as long as the StringTokenizer hasMoreTokens in it
30+
while(st.hasMoreTokens())
31+
{
32+
// This temporarily stores the next Token in the StringTokenizer
33+
day = st.nextToken();
34+
// This uses the isValidDate method to make sure the Token has 8 digits
35+
if(isValidDate(day))
36+
{
37+
// If isValidDate is true, the day is stored at the index of the array, and the index increases by 1;
38+
dates[index] = day;
39+
index++;
40+
}
41+
else
42+
{
43+
// If isValidDate is false, the day is printed to the console and not stored in the array
44+
System.out.println(day + " is not a valid date, and was not put in the array.");
45+
}
46+
}
47+
// This gets the next line of the file and stores it
48+
line = tfi.readLine();
49+
}
50+
// If this test is true, it means the exit condition for the while loop was index was not less than the length of the array, which means not all dates were stored in the array
51+
if(line != null)
52+
{
53+
System.out.println("There were more dates than space in the array.");
54+
System.out.println("The array can only store " + dates.length + " dates.");
55+
System.exit(1);
56+
}
57+
String[] sortedDates = new String[index];
58+
for(int i = 0; i < index; i++)
59+
{
60+
sortedDates[i] = dates[i];
61+
}
62+
selectionSort(sortedDates);
63+
createAndDisplayGUI(dates, sortedDates);
64+
}
65+
public static boolean isValidDate(String date)
66+
{
67+
if(date.length() != 8) return false;
68+
for(int i = 0; i < 8; i++)
69+
{
70+
if(!Character.isDigit(date.charAt(i))) return false;
71+
}
72+
return true;
73+
}
74+
private static void selectionSort(String[] array)
75+
{
76+
for(int i = 0; i < array.length - 1; i++)
77+
{
78+
int indexLowest = i;
79+
for(int j = i + 1; j < array.length; j++)
80+
{
81+
if(array[j].compareTo(array[indexLowest]) < 0)
82+
indexLowest = j;
83+
}
84+
if(!array[indexLowest].equals(array[i]))
85+
{
86+
String temp = array[indexLowest];
87+
array[indexLowest] = array[i];
88+
array[i] = temp;
89+
}
90+
}
91+
}
92+
private static void createAndDisplayGUI(String[] array1, String[] array2)
93+
{
94+
DateGUI mainGUI = new DateGUI(array1, array2);
95+
}
96+
}

Project2.jar

66.9 KB
Binary file not shown.

Project3.jar

90.7 KB
Binary file not shown.

Project4 (1).jar

96.1 KB
Binary file not shown.

0 commit comments

Comments
 (0)