page flow done for now

This commit is contained in:
Medium Fries 2019-03-18 20:06:09 -07:00
parent 15f2385e27
commit fd380c6fe7
3 changed files with 226 additions and 9 deletions

View File

@ -17,25 +17,81 @@ import javafx.scene.layout.GridPane;
public class App extends Application { public class App extends Application {
static public School school_; static public School school_;
// next 3 methods are just here to populate the scene with items insede them
public Scene setStudentScene(Stage stage, Scene _prevScene) {
GridPane _layout = new GridPane();
// make the buttons
Button addButton = new Button("Add student");
Button returnButton = new Button("Return");
// adding buttons to the scene's layout
_layout.add(addButton, 1,0,1,1);
_layout.add(returnButton, 1,1,1,1);
// add event listeners for the buttons
returnButton.setOnAction(e-> stage.setScene(_prevScene));
// finally return a new scene with the finished layout
Scene ret = new Scene(_layout, 1280, 720);
return ret;
}
public Scene setInstructorScene(Stage stage, Scene _prevScene) {
GridPane _layout = new GridPane();
// buttons for this page
Button addButton = new Button("Add instructor");
Button setButton = new Button("Assign to course");
Button returnButton = new Button("Return");
// setup buttons
_layout.add(addButton, 1,0,1,1);
_layout.add(setButton, 1,1,1,1);
_layout.add(returnButton, 1,2,1,1);
returnButton.setOnAction(e -> stage.setScene(_prevScene));
Scene ret = new Scene(_layout, 1280, 720);
return ret;
}
public Scene setCourseScene(Stage stage, Scene _prevScene) {
GridPane _layout = new GridPane();
Button addButton = new Button("Add course");
Button deleteButton = new Button("Delete course");
Button returnButton = new Button("Return");
_layout.add(addButton, 1,0,1,1);
_layout.add(deleteButton, 1,1,1,1);
_layout.add(returnButton, 1,2,1,1);
returnButton.setOnAction(e -> stage.setScene(_prevScene));
Scene ret = new Scene(_layout, 1280, 720);
return ret;
}
@Override @Override
public void start(Stage stage) { public void start(Stage stage) {
// make the initial menu with three buttons // make the initial menu with three buttons
stage.setTitle("School App"); stage.setTitle("School App");
// main menu buttons
// Main menu comes first
GridPane grid = new GridPane();
Button instButton = new Button("Instructors"); Button instButton = new Button("Instructors");
Button studButton = new Button("Students"); Button studButton = new Button("Students");
Button courButton = new Button("Courses"); Button courseButton = new Button("Courses");
// add those buttons to the main_menu scene
// creating the initial scene to draw thigns onto
GridPane grid = new GridPane();
grid.add(instButton, 1, 0, 1, 1); grid.add(instButton, 1, 0, 1, 1);
grid.add(studButton, 1, 1, 1, 1); grid.add(studButton, 1, 1, 1, 1);
grid.add(courButton, 1, 2, 1, 1); grid.add(courseButton, 1, 2, 1, 1);
Scene scene = new Scene(grid, 1280, 720); Scene main_menu = new Scene(grid, 1280, 720);
stage.setScene(scene);
// render the scene // next we can create the other menu's
Scene studMenu = setStudentScene(stage, main_menu);
Scene instMenu = setInstructorScene(stage, main_menu);
Scene courMenu = setCourseScene(stage, main_menu);
// now we can add the event listeners for our main menu as the other scenes now exist
instButton.setOnAction(e-> stage.setScene(instMenu));
studButton.setOnAction(e-> stage.setScene(studMenu));
courseButton.setOnAction(e-> stage.setScene(courMenu));
stage.setScene(main_menu);
stage.show(); stage.show();
} }
public static void main(String[] args) { public static void main(String[] args) {

74
370/samples/avl.py Normal file
View File

@ -0,0 +1,74 @@
class Node:
def __init__(self, key, value, left=None, right=None, height=0):
self.key = key
self.value = value
self.left = left
self.right = right
self.height = height
class AVLTreeMap:
def __init__(self, node):
self.root = root
# Data related operations
def put(self, key, value):
# go until we find a good place to put our dank value
curr = self.root
while True:
# going left maybe
if key < curr.key:
# see if we can stop now
if curr.left is None:
curr.left = Node(key, value)
break
if curr.right is None:
curr.right = Node(key, value)
break
def get(self, key):
curr = self.root
if curr is None:
return None
# check if we found the thing
if key == curr.key:
return curr
if key < curr.key:
get(curr.left)
else:
get(curr.right)
def remove(self,key):
pass
def levelOrder(self):
# Return case
if node == None:
return
# Go left
self.levelOrder(node.left)
# Visit
print(f'{node.value} ', end='')
# Go right
self.levelOrder(node.right)
# tree related operations
def rotateLeft(self, node):
pass
def rotateRight(self,node):
pass
# returns the height of a _node_ not the whole tree
def getHeight(self, node):
pass
# returns node balance
def getBalance(self, node):
_left = 0 if node.left is None else node.left.height
_right = 0 if node.right is None else node.right.height
return _left - right

87
370/samples/cycle.py Normal file
View File

@ -0,0 +1,87 @@
# Detecting cycles in a given adjacency list
# First we're given N for how many nodes we'll have
n = int(input())
# Next we're given the N nodes
class Node:
def __init__(self, name, in_degree=0):
self.name = name
self.in_degree = in_degree
def __str__(self):
return self.name
def __repr__(self):
return f'{self.name} {self.in_degree}'
nodes = []
for i in range(0, n):
nodes.append(Node(input().strip()))
# Next we're given how many nodes and edges we have total ex:n e
_node_count, _edge_count = input().split()
_node_count = int(_node_count)
_edge_count = int(_edge_count)
edges = []
for i in range(0, _edge_count):
_from, _to = input().split()
edges.append([int(_from), int(_to)])
# Now we calculate the in-degrees
for edge in edges:
# take the target index in nodes and increment its in_degree
nodes[edge[1]].in_degree += 1
# Quick check if we exceed the max count of edges
max_edges = ((_node_count//2) * (_node_count -1))+1
#print(f'{_edge_count}/{max_edges}')
if _edge_count >= max_edges:
print('Cycle!')
exit(0)
# building the queue of items based on in-degrees
def add_nodes(_deg):
ret = []
for i in nodes:
if i.in_degree == _deg:
ret.append(i)
return ret
def find_neighbors(node):
ret = []
for i in edges:
if i[1] == nodes.index(node):
ret.append(nodes[i[0]])
nodes_mirror = [i for i in nodes]
# add the lowest in-degree nodes to our queue, up to the higher ones
budget_q = []
for i in range(0, max_edges):
budget_q += add_nodes(i)
visited = []
i = 0
while len(budget_q) > 0:
# add the first thing to the visited list
#visited.append(budget_q[0])
# Decrememt the neighbors' in_degree
for i in edges:
_from = i[0]
_to = i[1]
if nodes[_from] == budget_q[0]:
_neighbor = nodes_mirror[_to]
_neighbor.in_degree -= 1
if _neighbor.in_degree == 0:
visited.append(nodes_mirror[_to])
budget_q.append(_neighbor)
# remove whats at the front
del budget_q[0]
# then compare the lenthts
if len(visited) != (len(nodes) + len(edges)):
print('Cycle!')
else:
print('No cycle!')