
Code Samples
Python Code
#Description: This program that will manage a customer database for a retailer
def main():
#Opens the file and creates a list of Lists
f =open("customers.txt")
r = f.readlines()
listofLists =[]
count =0
for i in r:
listofLists.append(i.split())
listofLists[count][3] = int(listofLists[count][3])
listofLists[count][4] = int(listofLists[count][4])
count +=1
#Converts the numbers into Ints
found = 0
print("Welcome to the Customer Database Program")
user = input("Enter an option: ")
while(user !="q"):
if(user == "a"):
add(listofLists)
elif(user == "i"):
name =input("Which customer should be incremented? ")
print("Customer Incremented!")
for i in range(len(listofLists)):
if(name in listofLists[i]):
listofLists[i][4] = listofLists[i][4] +1
#Add 1 to the purchased items
elif(user =="p"):
for i in range (len(listofLists)):
print(listofLists[i],"\n")
#Print the list
elif(user == "x"):
name =input("Which customer's balance should be changed? ")
balance= int(input("What is their new balance? "))
print("Customer balance edited!")
for i in range(len(listofLists)):
if(name in listofLists[i]):
listofLists[i][3]= balance
#Find customer's name then edit their balance
elif(user =="s"):
print("Customer database sorted!")
check =False
while(check == False):
for i in range(len(listofLists)-1):
for j in range(i+1,len(listofLists)):
if listofLists[i][4] > listofLists[j][4]: #Determine if i is bigger than J
temp=listofLists[i]
listofLists[i]=listofLists[j] #Swap list postions using a temp
listofLists[j]=temp
for x in range(len(listofLists)-1):
if listofLists[x][4] > listofLists[x+1][4]:
check = False
check = True
elif(user =="r"):
name =input("Which customer should be removed? ")
for i in range(len(listofLists)):
if(name in listofLists[i]): #Find name in list
listofLists.remove(listofLists[i]) #Remove customer
found = 1
print("Customer Removed!")
break
if(found == 0):
print("Error, name not found")
else:
print("Please enter a correct command") #Check if command is valid
user = input("Enter an option: ")
print("Goodbye.") #Goodbye statement
def add(listofLists):
found = 0
new_list =[]
name =input("What is the name of the customer you want to add? ")
for i in range(len(listofLists)):
if(name in listofLists[i]):
found = 1
print("Error, the name was already found, try again")
return
phone =(input("What is the phone number? "))
balance=int(input("What is the balance? "))
purchase=int(input("What is the number of recent purchases? "))
print("Customer Added!")
new_name = name.split()
new_list.append(new_name[0])#Split the name into two parts
new_list.append(new_name[1])
new_list.append(phone) #Ask user for information and fill it into a new list
new_list.append(balance)
new_list.append(purchase)
listofLists.append(new_list)
main()
Java Code
//This program will take the data of a txt file and present it in a nice way
import java.io.*;
import java.util.Scanner;
import java.lang.*;
public class Assignment5 {
public static void main(String[] args)
throws IOException
{
Scanner filescan = new Scanner (new File ("students.txt")); //scans file name students.txt
Student [] info = new Student[50]; //maximum size of students is 50
String name; //variable for student name
Scanner linescan;
String line;
int id; //variable for id
int grade; //variable for the grade
int size = 0; //variable for the size of the array
int score = 0; //variable for the score in the array
int A_count = 0; //count for each letter grade
int B_count = 0;
int C_count = 0;
int D_count = 0;
int F_count = 0;
String the_letter ="";
String fmt1 = "%-15s%-25s%-15s%-15s"; //formaters for the different outputs
String fmt2 = "%-15d";
String fmt3 = "%-25s";
String fmt4 = "%.2f";
String fmt5 = "%-15s";
while(filescan.hasNext()) { //scan information on txt file
line = filescan.nextLine();
linescan =new Scanner(line);
linescan.useDelimiter(","); //separate each text by the ,
id = linescan.nextInt(); //take id
name= linescan.next(); //take name
grade = linescan.nextInt(); //take the score
Student x = new Student(name,id,grade); //run this through the Student.java file
info[size] = x; //set the size
size++; //increase size
}
double the_mean = mean(info,size); //call mean function
double the_stddev = stddev(info,the_mean,size); //call standard deviation function
System.out.println("Grade Manager by Donato Apon");
System.out.println(String.format(fmt1,"ID","Name","Score","Grade"));
for(int i =0; i<size; i++) {
the_letter = Letter(the_mean,the_stddev,info[i].getGrade()); //call letter function for each student's grade
if(the_letter == "A") {
A_count++; //increase letter counters
}
else if(the_letter == "B"){
B_count++;
}
else if(the_letter == "C"){
C_count++;
}
else if(the_letter == "D"){
D_count++;
}
else{
F_count++;
}
//print information
System.out.print(String.format(fmt2,info[i].getId()));
System.out.print(String.format(fmt3,info[i].getName()));
System.out.print(String.format(fmt2,info[i].getGrade()));
System.out.println(String.format(fmt5,the_letter));
}
System.out.println("");
System.out.println("Number of students: "+ Student.getCount());
System.out.println("Mean is " + String.format(fmt4,the_mean));
System.out.println("Standard deviation is " + String.format(fmt4,the_stddev));
System.out.println("Score Analysis");
the_letter ="A";
Display(the_letter,A_count); //call display function for the *
the_letter ="B";
Display(the_letter,B_count);
the_letter ="C";
Display(the_letter,C_count);
the_letter ="D";
Display(the_letter,D_count);
the_letter ="F";
Display(the_letter,F_count);
}
public static double mean(Student[] info, int size) {
int grades = 0;
double mean;
for(int i= 0; i<size; i++) { //create a for loop to add all the grades
grades = grades +info[i].getGrade();
}
mean = grades/size; //divide by the size of the array (a.k.a the amount of grades)
return mean; //return the mean
}
public static double stddev (Student[] info, double mean, int size) {
double stddev = 0;
double sum = 0;
for(int i= 0; i<size; i++) {
sum = sum + (info[i].getGrade()- mean)*(info[i].getGrade()- mean); //create a sum of the grade minus the mean squared
}
stddev = Math.sqrt(sum/(size-1)); //divide the sum by one less than the size, then take the square root
return stddev; //return standard deviation
}
public static String Letter (double mean, double stddev, int score) {
String Letter = "";
if(score< mean -(1.5*stddev)) { //use formula given to determine the letter grade using if logic
Letter = "F";
}
else if((mean - (1.5*stddev) <=score) && (score <mean - (0.5*stddev))) {
Letter = "D";
}
else if((mean - (0.5*stddev) <=score) && (score <mean + (0.5*stddev))) {
Letter = "C";
}
else if((mean + (0.5*stddev) <=score) && (score <mean + (1.5*stddev))) {
Letter = "B";
}
else if(mean + (1.5*stddev)<= score) {
Letter = "A";
}
return Letter;
} //return the letter
public static void Display(String Letter, int count) {
String star = "*";
System.out.print(Letter+"\t"); //print what letter catergory this is
for(int i = 0; i< count; i++) {
System.out.print(star); //for the amount in the count, print that many stars
}
System.out.println(" "); //print a blank line for the next letter
}
}
C Code
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
int main(int argc, char argv[]){
while(1){
printf("Enter a line -->");
fflush(stdout);
char buf[80];
char *args[4];
int ret;
int BG = 0;
int pid;
char *ptr2;
char *ptr3;
ret = read(0,buf, 80);
char *ptr;
ptr=buf;
*(ptr+ret)='\0';
printf("\n");
for(int i = 0; i<ret; i++){
if(buf[i] == '&'){
buf[i] = '\0';
BG = 1;
}
if((buf[i] == ' ') || (buf[i] == '\n')){
buf[i] = '\0';
}
}
ptr2 = buf;
while(*ptr2 != '\0'){
ptr2++;
}
ptr2++;
ptr3 = ptr2;
while(*ptr3 != '\0'){
ptr3++;
}
ptr3++;
pid = fork();
args[0] = buf;
args[1] = ptr2;
args[2] = ptr3;
args[3] = NULL;
if(pid == 0){
ret = execv(args[0], args);
printf("Program %s not found!\n", args[0]);
}
else{
if(BG != 1){
wait();
//This line of code is here to prove if the program is waiting for the child or not
printf("Program has run\n");
}
wait();
}
}
}
Unity Game

My game Slime Slayer, made through Unity.
If you would like to know more, or download the game, please contact me.