Adding in CS-115 coursework
This commit is contained in:
29
cs-115-test/.gitignore
vendored
Normal file
29
cs-115-test/.gitignore
vendored
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
### IntelliJ IDEA ###
|
||||||
|
out/
|
||||||
|
!**/src/main/**/out/
|
||||||
|
!**/src/test/**/out/
|
||||||
|
|
||||||
|
### Eclipse ###
|
||||||
|
.apt_generated
|
||||||
|
.classpath
|
||||||
|
.factorypath
|
||||||
|
.project
|
||||||
|
.settings
|
||||||
|
.springBeans
|
||||||
|
.sts4-cache
|
||||||
|
bin/
|
||||||
|
!**/src/main/**/bin/
|
||||||
|
!**/src/test/**/bin/
|
||||||
|
|
||||||
|
### NetBeans ###
|
||||||
|
/nbproject/private/
|
||||||
|
/nbbuild/
|
||||||
|
/dist/
|
||||||
|
/nbdist/
|
||||||
|
/.nb-gradle/
|
||||||
|
|
||||||
|
### VS Code ###
|
||||||
|
.vscode/
|
||||||
|
|
||||||
|
### Mac OS ###
|
||||||
|
.DS_Store
|
||||||
5
cs-115-test/.idea/.gitignore
generated
vendored
Normal file
5
cs-115-test/.idea/.gitignore
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
# Default ignored files
|
||||||
|
/shelf/
|
||||||
|
/workspace.xml
|
||||||
|
# Environment-dependent path to Maven home directory
|
||||||
|
/mavenHomeManager.xml
|
||||||
6
cs-115-test/.idea/misc.xml
generated
Normal file
6
cs-115-test/.idea/misc.xml
generated
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_24" default="true" project-jdk-name="openjdk-24" project-jdk-type="JavaSDK">
|
||||||
|
<output url="file://$PROJECT_DIR$/out" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
8
cs-115-test/.idea/modules.xml
generated
Normal file
8
cs-115-test/.idea/modules.xml
generated
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectModuleManager">
|
||||||
|
<modules>
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/cs-115-test.iml" filepath="$PROJECT_DIR$/cs-115-test.iml" />
|
||||||
|
</modules>
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
11
cs-115-test/cs-115-test.iml
Normal file
11
cs-115-test/cs-115-test.iml
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module type="JAVA_MODULE" version="4">
|
||||||
|
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||||
|
<exclude-output />
|
||||||
|
<content url="file://$MODULE_DIR$">
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||||
|
</content>
|
||||||
|
<orderEntry type="inheritedJdk" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
</component>
|
||||||
|
</module>
|
||||||
3
cs-115-test/src/Advance.java
Normal file
3
cs-115-test/src/Advance.java
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
public interface Advance {
|
||||||
|
void advance(int increment);
|
||||||
|
}
|
||||||
85
cs-115-test/src/AppletOne.java
Normal file
85
cs-115-test/src/AppletOne.java
Normal file
@@ -0,0 +1,85 @@
|
|||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.*;
|
||||||
|
import java.awt.event.ItemEvent;
|
||||||
|
import java.awt.event.ItemListener;
|
||||||
|
|
||||||
|
public class AppletOne extends JFrame implements ItemListener {
|
||||||
|
|
||||||
|
final int WEEKEND_PREMIUM = 100;
|
||||||
|
final int BREAKFAST_PREMIUM = 20;
|
||||||
|
final int GOLF_PREMIUM = 75;
|
||||||
|
final int BASE_PRICE = 200;
|
||||||
|
int totalPrice = BASE_PRICE;
|
||||||
|
|
||||||
|
JCheckBox weekendBox = new JCheckBox("Weekend Premium $" + WEEKEND_PREMIUM, false);
|
||||||
|
JCheckBox breakfastBox = new JCheckBox("Breakfast Premium $" + BREAKFAST_PREMIUM, false);
|
||||||
|
JCheckBox golfBox = new JCheckBox("Golf Premium $" + GOLF_PREMIUM, false);
|
||||||
|
|
||||||
|
JLabel resortLabel = new JLabel("Resort Price Calculator");
|
||||||
|
JLabel priceLabel = new JLabel("The price for your stay is");
|
||||||
|
|
||||||
|
Font newFont = new Font("SansSerif", Font.BOLD, 20);
|
||||||
|
JTextField totPrice = new JTextField(4);
|
||||||
|
|
||||||
|
JLabel optionExplainLabel = new JLabel("Base price for a room is $" + BASE_PRICE + ".");
|
||||||
|
JLabel optionExplainLabel2 = new JLabel("Check the options you want.");
|
||||||
|
|
||||||
|
public AppletOne() {
|
||||||
|
super("Resort Price Estimator");
|
||||||
|
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
|
setLayout(new GridLayout(8, 2));
|
||||||
|
resortLabel.setForeground(Color.ORANGE);
|
||||||
|
optionExplainLabel.setForeground(Color.ORANGE);
|
||||||
|
optionExplainLabel2.setForeground(Color.ORANGE);
|
||||||
|
priceLabel.setForeground(Color.ORANGE);
|
||||||
|
totPrice.setFont(newFont);
|
||||||
|
add(resortLabel);
|
||||||
|
add(optionExplainLabel);
|
||||||
|
add(optionExplainLabel2);
|
||||||
|
add(weekendBox);
|
||||||
|
add(breakfastBox);
|
||||||
|
add(golfBox);
|
||||||
|
add(priceLabel);
|
||||||
|
add(totPrice);
|
||||||
|
|
||||||
|
totPrice.setText("$" + totalPrice);
|
||||||
|
weekendBox.addItemListener(this);
|
||||||
|
breakfastBox.addItemListener(this);
|
||||||
|
golfBox.addItemListener(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
AppletOne j = new AppletOne();
|
||||||
|
j.getContentPane().setBackground(Color.DARK_GRAY);
|
||||||
|
j.setBackground(Color.BLACK);
|
||||||
|
j.setVisible(true);
|
||||||
|
j.setSize(750, 650);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void itemStateChanged(ItemEvent event) {
|
||||||
|
Object source = event.getSource();
|
||||||
|
int select = event.getStateChange();
|
||||||
|
|
||||||
|
if(source == weekendBox) {
|
||||||
|
if(select == ItemEvent.SELECTED) {
|
||||||
|
totalPrice += WEEKEND_PREMIUM;
|
||||||
|
} else {
|
||||||
|
totalPrice -= WEEKEND_PREMIUM;
|
||||||
|
}
|
||||||
|
} else if (source == breakfastBox) {
|
||||||
|
if (select == ItemEvent.SELECTED) {
|
||||||
|
totalPrice += BREAKFAST_PREMIUM;
|
||||||
|
} else {
|
||||||
|
totalPrice -= BREAKFAST_PREMIUM;
|
||||||
|
}
|
||||||
|
} else if (source == golfBox) {
|
||||||
|
if(select == ItemEvent.SELECTED) {
|
||||||
|
totalPrice += GOLF_PREMIUM;
|
||||||
|
} else {
|
||||||
|
totalPrice -= GOLF_PREMIUM;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
totPrice.setText("$" + totalPrice);
|
||||||
|
}
|
||||||
|
}
|
||||||
8
cs-115-test/src/Calendar.java
Normal file
8
cs-115-test/src/Calendar.java
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
public class Calendar implements Advance {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
|
||||||
|
}
|
||||||
|
public void advance(int increment) {
|
||||||
|
System.out.println("Advancing " + increment + " Day(s)");
|
||||||
|
}
|
||||||
|
}
|
||||||
9
cs-115-test/src/Clock.java
Normal file
9
cs-115-test/src/Clock.java
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
public class Clock implements Advance {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void advance(int increment) {
|
||||||
|
System.out.println("Advancing " + increment + " Second(s)");
|
||||||
|
}
|
||||||
|
}
|
||||||
2
cs-115-test/src/ClockCalendar.java
Normal file
2
cs-115-test/src/ClockCalendar.java
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
public class ClockCalendar {
|
||||||
|
}
|
||||||
34
cs-115-test/src/DialogExample.java
Normal file
34
cs-115-test/src/DialogExample.java
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.*;
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
|
|
||||||
|
public class DialogExample {
|
||||||
|
private static JDialog dialog;
|
||||||
|
|
||||||
|
public DialogExample() {
|
||||||
|
JFrame frame = new JFrame();
|
||||||
|
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
|
||||||
|
|
||||||
|
dialog = new JDialog(frame, "New Dialog Box", true);
|
||||||
|
dialog.setLayout(new FlowLayout());
|
||||||
|
dialog.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
|
||||||
|
|
||||||
|
JButton button = new JButton("OK");
|
||||||
|
button.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
DialogExample.dialog.setVisible(false);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
dialog.add(new JLabel("Click OK to Agree"));
|
||||||
|
dialog.add(button);
|
||||||
|
dialog.setSize(250, 250);
|
||||||
|
dialog.setVisible(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
new DialogExample();
|
||||||
|
}
|
||||||
|
}
|
||||||
24
cs-115-test/src/Editor.java
Normal file
24
cs-115-test/src/Editor.java
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
import javax.swing.*;
|
||||||
|
|
||||||
|
public class Editor {
|
||||||
|
JFrame myFrame = null;
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
(new Editor()).showPane();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void showPane() {
|
||||||
|
myFrame = new JFrame("JEditorPane Test");
|
||||||
|
myFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
|
myFrame.setSize(500, 225);
|
||||||
|
|
||||||
|
JEditorPane latinPane = new JEditorPane();
|
||||||
|
latinPane.setContentType("text/html");
|
||||||
|
latinPane.setText("<h2>Latin Text!"
|
||||||
|
+ "<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit."
|
||||||
|
+ " Duis rutrum arcu mauris, et vulputate arcu laoreet vitae. </p>");
|
||||||
|
|
||||||
|
myFrame.setContentPane(latinPane);
|
||||||
|
myFrame.setVisible(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
28
cs-115-test/src/ExceptionsDemo.java
Normal file
28
cs-115-test/src/ExceptionsDemo.java
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
import javax.swing.*;
|
||||||
|
import java.util.InputMismatchException;
|
||||||
|
|
||||||
|
public class ExceptionsDemo {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
int numerator = 0;
|
||||||
|
int denominator = 0;
|
||||||
|
int result;
|
||||||
|
|
||||||
|
String inputString;
|
||||||
|
|
||||||
|
try {
|
||||||
|
inputString = JOptionPane.showInputDialog(null, "Enter a number to be divided");
|
||||||
|
numerator = Integer.parseInt(inputString);
|
||||||
|
inputString = JOptionPane.showInputDialog(null, "Enter a number to divide into the first number");
|
||||||
|
denominator = Integer.parseInt(inputString);
|
||||||
|
result = numerator / denominator;
|
||||||
|
|
||||||
|
JOptionPane.showMessageDialog(null, numerator + " / " + denominator + "\nResult is " + result);
|
||||||
|
} catch (ArithmeticException exception) {
|
||||||
|
JOptionPane.showMessageDialog(null, exception.getMessage());
|
||||||
|
result = 0;
|
||||||
|
} catch (NumberFormatException exception) {
|
||||||
|
JOptionPane.showMessageDialog(null, "Please enter only Integers!");
|
||||||
|
result = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
73
cs-115-test/src/Files.java
Normal file
73
cs-115-test/src/Files.java
Normal file
@@ -0,0 +1,73 @@
|
|||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
|
import java.io.*;
|
||||||
|
import javax.swing.JEditorPane;
|
||||||
|
|
||||||
|
public class Files extends JFrame implements ActionListener {
|
||||||
|
|
||||||
|
JTextArea textArea;
|
||||||
|
JMenuItem open;
|
||||||
|
JEditorPane latinPane;
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
Files filePicker = new Files();
|
||||||
|
filePicker.setSize(600, 600);
|
||||||
|
filePicker.setLayout(null);
|
||||||
|
filePicker.setVisible(true);
|
||||||
|
filePicker.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Files() {
|
||||||
|
JMenuBar menuBar = new JMenuBar();
|
||||||
|
JMenu file = new JMenu("File");
|
||||||
|
latinPane = new JEditorPane();
|
||||||
|
open = new JMenuItem("Open File");
|
||||||
|
open.addActionListener(this);
|
||||||
|
textArea = new JTextArea(600, 600);
|
||||||
|
JEditorPane latinPane = new JEditorPane();
|
||||||
|
|
||||||
|
latinPane.setContentType("text/plain");
|
||||||
|
file.add(open);
|
||||||
|
menuBar.setBounds(0, 0, 600, 20);
|
||||||
|
menuBar.add(file);
|
||||||
|
textArea.setBounds(0, 20, 600, 600);
|
||||||
|
add(menuBar);
|
||||||
|
add(latinPane);
|
||||||
|
|
||||||
|
latinPane.setContentType("text/plain");
|
||||||
|
add(latinPane);
|
||||||
|
add(textArea);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void actionPerformed(ActionEvent event) {
|
||||||
|
if (event.getSource() == open) {
|
||||||
|
JFileChooser fileChooser = new JFileChooser();
|
||||||
|
int i = fileChooser.showOpenDialog(this);
|
||||||
|
|
||||||
|
if (i == JFileChooser.APPROVE_OPTION) {
|
||||||
|
File file = fileChooser.getSelectedFile();
|
||||||
|
String filePath = file.getPath();
|
||||||
|
|
||||||
|
try {
|
||||||
|
BufferedReader bufferedReader = new BufferedReader(new FileReader(filePath));
|
||||||
|
String s1 = "";
|
||||||
|
String s2 = "";
|
||||||
|
while ( (s1 = bufferedReader.readLine()) != null ) {
|
||||||
|
s2 += s1 + "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
latinPane.setText(s2);
|
||||||
|
//textArea.setText(s2);
|
||||||
|
bufferedReader.close();
|
||||||
|
} catch (FileNotFoundException exception) {
|
||||||
|
System.out.println("FUCK");
|
||||||
|
} catch (IOException exception) {
|
||||||
|
System.out.println("SHIT");
|
||||||
|
} catch (Exception exception) {
|
||||||
|
exception.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
46
cs-115-test/src/GUIOutput.java
Normal file
46
cs-115-test/src/GUIOutput.java
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.*;
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
|
|
||||||
|
public class GUIOutput {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
new GUIOutput();
|
||||||
|
}
|
||||||
|
|
||||||
|
public GUIOutput() {
|
||||||
|
JFrame guiFrame = new JFrame();
|
||||||
|
guiFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
|
guiFrame.setTitle("My Gui App");
|
||||||
|
guiFrame.setSize(1920, 1080);
|
||||||
|
guiFrame.setLocationRelativeTo(null);
|
||||||
|
|
||||||
|
String[] northAmerican = {"USA", "Canada"};
|
||||||
|
String[] westernEurope = {"United Kingdom", "France", "Germany"};
|
||||||
|
|
||||||
|
final JPanel comboPanel = new JPanel();
|
||||||
|
JLabel comboLbl = new JLabel("North American Countries:");
|
||||||
|
JComboBox namerica = new JComboBox(northAmerican);
|
||||||
|
comboPanel.add(comboLbl);
|
||||||
|
comboPanel.add(namerica);
|
||||||
|
|
||||||
|
final JPanel listPanel = new JPanel();
|
||||||
|
listPanel.setVisible(false);
|
||||||
|
|
||||||
|
JLabel listLbl = new JLabel("Western Europe Countries:");
|
||||||
|
JList westerneu = new JList(westernEurope);
|
||||||
|
westerneu.setLayoutOrientation(JList.HORIZONTAL_WRAP);
|
||||||
|
listPanel.add(listLbl);
|
||||||
|
listPanel.add(westerneu);
|
||||||
|
JButton ameEuBut = new JButton(((ActionListener) event -> {
|
||||||
|
listPanel.setVisible(!listPanel.isVisible());
|
||||||
|
comboPanel.setVisible(!comboPanel.isVisible());
|
||||||
|
}).toString());
|
||||||
|
|
||||||
|
guiFrame.add(comboPanel, BorderLayout.NORTH);
|
||||||
|
guiFrame.add(listPanel, BorderLayout.CENTER);
|
||||||
|
guiFrame.add(ameEuBut, BorderLayout.SOUTH);
|
||||||
|
|
||||||
|
guiFrame.setVisible(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
36
cs-115-test/src/List.java
Normal file
36
cs-115-test/src/List.java
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
|
|
||||||
|
public class List {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
JFrame frame = new JFrame();
|
||||||
|
String[] trees = { "Maple", "Larch", "Spruce", "Balsam" };
|
||||||
|
JList treeList = new JList(trees);
|
||||||
|
JPanel panel = new JPanel();
|
||||||
|
|
||||||
|
JLabel label = new JLabel("Select a Tree");
|
||||||
|
|
||||||
|
treeList.add(panel);
|
||||||
|
|
||||||
|
JButton button = new JButton("Show Me");
|
||||||
|
button.setBounds(10, 150, 230, 30);
|
||||||
|
|
||||||
|
button.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
String data = "";
|
||||||
|
if (treeList.getSelectedIndex() != -1) {
|
||||||
|
data = "Trees: " + treeList.getSelectedValue();
|
||||||
|
button.setText(data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
frame.add(button);
|
||||||
|
frame.add(treeList);
|
||||||
|
frame.setSize(250, 250);
|
||||||
|
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
|
||||||
|
frame.setVisible(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
135
cs-115-test/src/Main.java
Normal file
135
cs-115-test/src/Main.java
Normal file
@@ -0,0 +1,135 @@
|
|||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
class Rectangle {
|
||||||
|
private double height;
|
||||||
|
private double width;
|
||||||
|
|
||||||
|
public Rectangle(double h, double w) {
|
||||||
|
height = h;
|
||||||
|
width = w;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double Perimeter() {
|
||||||
|
return 2.0 * (height + width);
|
||||||
|
}
|
||||||
|
|
||||||
|
public double Area() {
|
||||||
|
return height * width;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
enum DayOfWeek {
|
||||||
|
SUNDAY(0),
|
||||||
|
MONDAY(1),
|
||||||
|
TUESDAY(2),
|
||||||
|
WEDNESDAY(3),
|
||||||
|
THURSDAY(4),
|
||||||
|
FRIDAY(5),
|
||||||
|
SATURDAY(6);
|
||||||
|
|
||||||
|
private int value;
|
||||||
|
|
||||||
|
private DayOfWeek(int value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getDayOfWeekValue() {
|
||||||
|
return this.value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class Main {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void showMsg(String... vars) {
|
||||||
|
for (String s: vars) {
|
||||||
|
System.out.println("Arg = " + s);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void multiplyMatrix() {
|
||||||
|
int[][] myMatrixA = {
|
||||||
|
{3, 5, 7},
|
||||||
|
{9, 17, 12},
|
||||||
|
{32, 21, 5}
|
||||||
|
};
|
||||||
|
|
||||||
|
int[][] myMatrixB = {
|
||||||
|
{1, 3, 5},
|
||||||
|
{7, 9, 11},
|
||||||
|
{13, 15, 17}
|
||||||
|
};
|
||||||
|
|
||||||
|
int rowsA = myMatrixA.length;
|
||||||
|
int colsA = myMatrixA[0].length;
|
||||||
|
int rowsB = myMatrixB.length;
|
||||||
|
int colsB = myMatrixB[0].length;
|
||||||
|
|
||||||
|
int[][] myMatrixC = new int [rowsA][colsB];
|
||||||
|
|
||||||
|
System.out.println(Arrays.deepToString(myMatrixC));
|
||||||
|
|
||||||
|
for (int i = 0; i < rowsA; i++) {
|
||||||
|
for (int j = 0; j < colsB; j++) {
|
||||||
|
for (int k = 0; k < colsA; k++) {
|
||||||
|
myMatrixC[i][j] += myMatrixA[i][k] * myMatrixB[k][j];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println("Multiplying A and B equals: ");
|
||||||
|
for (int m = 0; m < myMatrixC.length; m++) {
|
||||||
|
for (int n = 0; n < myMatrixC[0].length; n++) {
|
||||||
|
System.out.print(myMatrixC[m][n] + " ");
|
||||||
|
}
|
||||||
|
System.out.println();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void randomChapter() {
|
||||||
|
double r = 0.0;
|
||||||
|
int priceCategory = 0;
|
||||||
|
int revenue = 0;
|
||||||
|
int firstClassPassengerCount = 0;
|
||||||
|
int businessClassPassengerCount = 0;
|
||||||
|
|
||||||
|
r = Math.random();
|
||||||
|
priceCategory = (int)(3.0 * r) + 1;
|
||||||
|
|
||||||
|
if (priceCategory == 1) {
|
||||||
|
firstClassPassengerCount++;
|
||||||
|
|
||||||
|
if (firstClassPassengerCount <= 25) {
|
||||||
|
revenue += 250;
|
||||||
|
}
|
||||||
|
} else if (priceCategory == 2) {
|
||||||
|
businessClassPassengerCount++;
|
||||||
|
|
||||||
|
if (businessClassPassengerCount <= 25) {
|
||||||
|
revenue += 170;
|
||||||
|
}
|
||||||
|
} else if (priceCategory == 3) {
|
||||||
|
revenue += 100;
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println(revenue);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void usingScanner() {
|
||||||
|
int firstNum, secondNum, sum, diff, avg;
|
||||||
|
Scanner input = new Scanner(System.in);
|
||||||
|
System.out.println("Please enter an integer: ");
|
||||||
|
firstNum = input.nextInt();
|
||||||
|
System.out.println("Please enter another integer: ");
|
||||||
|
secondNum = input.nextInt();
|
||||||
|
sum = firstNum + secondNum;
|
||||||
|
diff = firstNum - secondNum;
|
||||||
|
avg = sum / 2;
|
||||||
|
System.out.println("The Sum " + firstNum + " + " + secondNum + " = " + sum);
|
||||||
|
System.out.println("The Difference " + firstNum + " - " + secondNum + " = " + diff);
|
||||||
|
System.out.println("The Average " + sum + " / " + "2" + " = " + avg);
|
||||||
|
input.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
36
cs-115-test/src/MenuBar.java
Normal file
36
cs-115-test/src/MenuBar.java
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
import javax.swing.*;
|
||||||
|
|
||||||
|
public class MenuBar {
|
||||||
|
JMenu menu, subMenu;
|
||||||
|
JMenuItem i1, i2, i3, i4, i5, i6;
|
||||||
|
|
||||||
|
public MenuBar() {
|
||||||
|
JFrame frame = new JFrame();
|
||||||
|
|
||||||
|
JMenuBar menuBar = new JMenuBar();
|
||||||
|
|
||||||
|
menu = new JMenu("Options");
|
||||||
|
subMenu = new JMenu("Pan Types");
|
||||||
|
|
||||||
|
i1 = new JMenuItem("Spatula");
|
||||||
|
i2 = new JMenuItem("Stove");
|
||||||
|
i3 = new JMenuItem("Broiler");
|
||||||
|
i4 = new JMenuItem("Frying Pan");
|
||||||
|
i5 = new JMenuItem("Skillet");
|
||||||
|
i6 = new JCheckBoxMenuItem("Hey Check Me!");
|
||||||
|
menu.add(i1); menu.add(i2); menu.add(i3);
|
||||||
|
subMenu.add(i4); subMenu.add(i5); subMenu.add(i6);
|
||||||
|
menu.add(subMenu);
|
||||||
|
menu.add(subMenu);
|
||||||
|
menuBar.add(menu);
|
||||||
|
frame.setJMenuBar(menuBar);
|
||||||
|
frame.setSize(1920, 1080);
|
||||||
|
frame.setLayout(null);
|
||||||
|
frame.setVisible(true);
|
||||||
|
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
new MenuBar();
|
||||||
|
}
|
||||||
|
}
|
||||||
20
cs-115-test/src/Reflection.java
Normal file
20
cs-115-test/src/Reflection.java
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
import java.lang.Class;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
|
public class Reflection {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
Reflection b = new Reflection();
|
||||||
|
Class<? extends Reflection> showMe = b.getClass();
|
||||||
|
System.out.println(showMe);
|
||||||
|
Class<? extends Reflection> dClass = Reflection.class;
|
||||||
|
Method[] methods = dClass.getDeclaredMethods();
|
||||||
|
|
||||||
|
for(Method method: methods) {
|
||||||
|
System.out.println("Method name = " + method.getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void display() {
|
||||||
|
System.out.println("This is a Message!");
|
||||||
|
}
|
||||||
|
}
|
||||||
44
cs-115-test/src/Slider.java
Normal file
44
cs-115-test/src/Slider.java
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.*;
|
||||||
|
import java.util.Hashtable;
|
||||||
|
|
||||||
|
public class Slider extends JPanel {
|
||||||
|
public Slider() {
|
||||||
|
initializeUI();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
Slider.showFrame();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initializeUI() {
|
||||||
|
setLayout(new BorderLayout());
|
||||||
|
setPreferredSize(new Dimension(500, 200));
|
||||||
|
JSlider slider = new JSlider(JSlider.HORIZONTAL, 0, 35, 0);
|
||||||
|
slider.setMinorTickSpacing(1);
|
||||||
|
slider.setMajorTickSpacing(5);
|
||||||
|
slider.setPaintTicks(true);
|
||||||
|
|
||||||
|
Hashtable<Integer, JLabel> labels = new Hashtable<Integer, JLabel>();
|
||||||
|
labels.put(0, new JLabel("$10,000"));
|
||||||
|
labels.put(10, new JLabel("$20,000"));
|
||||||
|
labels.put(20, new JLabel("$30,000"));
|
||||||
|
labels.put(30, new JLabel("$40,000"));
|
||||||
|
|
||||||
|
slider.setLabelTable(labels);
|
||||||
|
slider.setPaintLabels(true);
|
||||||
|
add(slider, BorderLayout.NORTH);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void showFrame() {
|
||||||
|
JPanel panel = new Slider();
|
||||||
|
JFrame frame = new JFrame("JSlider Car Price Picker");
|
||||||
|
SpinnerModel value = new SpinnerNumberModel(25, 25, 100, 10);
|
||||||
|
JSpinner spinner = new JSpinner(value);
|
||||||
|
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
|
||||||
|
frame.setContentPane(panel);
|
||||||
|
frame.pack();
|
||||||
|
frame.add(spinner);
|
||||||
|
frame.setVisible(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
41
cs-115-test/src/SwingTree.java
Normal file
41
cs-115-test/src/SwingTree.java
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
import javax.swing.*;
|
||||||
|
import javax.swing.tree.DefaultMutableTreeNode;
|
||||||
|
|
||||||
|
public class SwingTree {
|
||||||
|
public SwingTree() {
|
||||||
|
JFrame frame = new JFrame();
|
||||||
|
|
||||||
|
DefaultMutableTreeNode style = new DefaultMutableTreeNode("Trees");
|
||||||
|
DefaultMutableTreeNode deciduous = new DefaultMutableTreeNode("Deciduous");
|
||||||
|
DefaultMutableTreeNode evergreen = new DefaultMutableTreeNode("Evergreen");
|
||||||
|
|
||||||
|
style.add(deciduous);
|
||||||
|
style.add(evergreen);
|
||||||
|
|
||||||
|
DefaultMutableTreeNode maple = new DefaultMutableTreeNode("Maple");
|
||||||
|
DefaultMutableTreeNode oak = new DefaultMutableTreeNode("Oak");
|
||||||
|
DefaultMutableTreeNode linden = new DefaultMutableTreeNode("Linden");
|
||||||
|
|
||||||
|
deciduous.add(maple);
|
||||||
|
deciduous.add(oak);
|
||||||
|
deciduous.add(linden);
|
||||||
|
|
||||||
|
DefaultMutableTreeNode pine = new DefaultMutableTreeNode("Pine");
|
||||||
|
DefaultMutableTreeNode balsam = new DefaultMutableTreeNode("Balsam");
|
||||||
|
DefaultMutableTreeNode spruce = new DefaultMutableTreeNode("Spruce");
|
||||||
|
|
||||||
|
evergreen.add(pine);
|
||||||
|
evergreen.add(balsam);
|
||||||
|
evergreen.add(spruce);
|
||||||
|
|
||||||
|
JTree tree = new JTree(style);
|
||||||
|
frame.add(tree);
|
||||||
|
frame.setSize(1920, 1080);
|
||||||
|
frame.setVisible(true);
|
||||||
|
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
new SwingTree();
|
||||||
|
}
|
||||||
|
}
|
||||||
25
cs-115-test/src/Table.java
Normal file
25
cs-115-test/src/Table.java
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
import javax.swing.*;
|
||||||
|
|
||||||
|
public class Table {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
JFrame frame = new JFrame("JTable Example");
|
||||||
|
JPanel panel = new JPanel();
|
||||||
|
String[][] data = {
|
||||||
|
{"1101", "Los Angeles", "6700"},
|
||||||
|
{"1102", "Chicago", "830000"},
|
||||||
|
{"1104", "New York", "92500"},
|
||||||
|
};
|
||||||
|
|
||||||
|
String[] column = { "Person ID", "Location", "Balance" };
|
||||||
|
JTable table = new JTable(data, column);
|
||||||
|
|
||||||
|
JScrollPane pane = new JScrollPane(table);
|
||||||
|
|
||||||
|
panel.add(pane);
|
||||||
|
frame.add(panel);
|
||||||
|
frame.add(table);
|
||||||
|
frame.setSize(300, 200);
|
||||||
|
frame.setVisible(true);
|
||||||
|
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user