Reset author name to chosen name ✨
This commit is contained in:
Binary file not shown.
@@ -0,0 +1,73 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!-- You may freely edit this file. See commented blocks below for -->
|
||||
<!-- some examples of how to customize the build. -->
|
||||
<!-- (If you delete it and reopen the project it will be recreated.) -->
|
||||
<!-- By default, only the Clean and Build commands use this build script. -->
|
||||
<!-- Commands such as Run, Debug, and Test only use this build script if -->
|
||||
<!-- the Compile on Save feature is turned off for the project. -->
|
||||
<!-- You can turn off the Compile on Save (or Deploy on Save) setting -->
|
||||
<!-- in the project's Project Properties dialog box.-->
|
||||
<project name="MP5-Binary-Files_ChloeFontenot" default="default" basedir=".">
|
||||
<description>Builds, tests, and runs the project MP5-Binary-Files_ChloeFontenot.</description>
|
||||
<import file="nbproject/build-impl.xml"/>
|
||||
<!--
|
||||
|
||||
There exist several targets which are by default empty and which can be
|
||||
used for execution of your tasks. These targets are usually executed
|
||||
before and after some main targets. They are:
|
||||
|
||||
-pre-init: called before initialization of project properties
|
||||
-post-init: called after initialization of project properties
|
||||
-pre-compile: called before javac compilation
|
||||
-post-compile: called after javac compilation
|
||||
-pre-compile-single: called before javac compilation of single file
|
||||
-post-compile-single: called after javac compilation of single file
|
||||
-pre-compile-test: called before javac compilation of JUnit tests
|
||||
-post-compile-test: called after javac compilation of JUnit tests
|
||||
-pre-compile-test-single: called before javac compilation of single JUnit test
|
||||
-post-compile-test-single: called after javac compilation of single JUunit test
|
||||
-pre-jar: called before JAR building
|
||||
-post-jar: called after JAR building
|
||||
-post-clean: called after cleaning build products
|
||||
|
||||
(Targets beginning with '-' are not intended to be called on their own.)
|
||||
|
||||
Example of inserting an obfuscator after compilation could look like this:
|
||||
|
||||
<target name="-post-compile">
|
||||
<obfuscate>
|
||||
<fileset dir="${build.classes.dir}"/>
|
||||
</obfuscate>
|
||||
</target>
|
||||
|
||||
For list of available properties check the imported
|
||||
nbproject/build-impl.xml file.
|
||||
|
||||
|
||||
Another way to customize the build is by overriding existing main targets.
|
||||
The targets of interest are:
|
||||
|
||||
-init-macrodef-javac: defines macro for javac compilation
|
||||
-init-macrodef-junit: defines macro for junit execution
|
||||
-init-macrodef-debug: defines macro for class debugging
|
||||
-init-macrodef-java: defines macro for class execution
|
||||
-do-jar: JAR building
|
||||
run: execution of project
|
||||
-javadoc-build: Javadoc generation
|
||||
test-report: JUnit report generation
|
||||
|
||||
An example of overriding the target for project execution could look like this:
|
||||
|
||||
<target name="run" depends="MP5-Binary-Files_ChloeFontenot-impl.jar">
|
||||
<exec dir="bin" executable="launcher.exe">
|
||||
<arg file="${dist.jar}"/>
|
||||
</exec>
|
||||
</target>
|
||||
|
||||
Notice that the overridden target depends on the jar target and not only on
|
||||
the compile target as the regular run target does. Again, for a list of available
|
||||
properties which you can use, check the target you are overriding in the
|
||||
nbproject/build-impl.xml file.
|
||||
|
||||
-->
|
||||
</project>
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,2 @@
|
||||
com.chloefontenot.mp5.files_chloefontenot.Exercise17_05
|
||||
com.chloefontenot.mp5.files_chloefontenot.DataContainer
|
||||
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,3 @@
|
||||
Manifest-Version: 1.0
|
||||
X-COMMENT: Main-Class will be added automatically by build
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,8 @@
|
||||
build.xml.data.CRC32=a0844a83
|
||||
build.xml.script.CRC32=dee8d968
|
||||
build.xml.stylesheet.CRC32=f85dc8f2@1.108.0.48
|
||||
# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
|
||||
# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
|
||||
nbproject/build-impl.xml.data.CRC32=a0844a83
|
||||
nbproject/build-impl.xml.script.CRC32=025ed557
|
||||
nbproject/build-impl.xml.stylesheet.CRC32=12e0a6c2@1.108.0.48
|
||||
@@ -0,0 +1,8 @@
|
||||
compile.on.save=true
|
||||
do.depend=false
|
||||
do.jar=true
|
||||
do.jlink=false
|
||||
javac.debug=true
|
||||
javadoc.preview=true
|
||||
jlink.strip=false
|
||||
user.properties.file=/home/chloe/.netbeans/19/build.properties
|
||||
@@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project-private xmlns="http://www.netbeans.org/ns/project-private/1">
|
||||
<editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/2" lastBookmarkId="0"/>
|
||||
<open-files xmlns="http://www.netbeans.org/ns/projectui-open-files/2">
|
||||
<group>
|
||||
<file>file:/home/chloe/ASDV-WebDev/Semester%202/Assignments/MP5-Binary-Files_ChloeFontenot/src/module-info.java</file>
|
||||
<file>file:/home/chloe/ASDV-WebDev/Semester%202/Assignments/MP5-Binary-Files_ChloeFontenot/src/com/chloefontenot/mp5/files_chloefontenot/AddressBookFX.java</file>
|
||||
<file>file:/home/chloe/ASDV-WebDev/Semester%202/Assignments/MP5-Binary-Files_ChloeFontenot/src/com/chloefontenot/mp5/files_chloefontenot/Exercise17_05.java</file>
|
||||
<file>file:/home/chloe/ASDV-WebDev/Semester%202/Assignments/MP5-Binary-Files_ChloeFontenot/src/com/chloefontenot/mp5/files_chloefontenot/App.java</file>
|
||||
</group>
|
||||
</open-files>
|
||||
</project-private>
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,15 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://www.netbeans.org/ns/project/1">
|
||||
<type>org.netbeans.modules.java.j2seproject</type>
|
||||
<configuration>
|
||||
<data xmlns="http://www.netbeans.org/ns/j2se-project/3">
|
||||
<name>MP5-Binary-Files_ChloeFontenot</name>
|
||||
<source-roots>
|
||||
<root id="src.dir"/>
|
||||
</source-roots>
|
||||
<test-roots>
|
||||
<root id="test.src.dir"/>
|
||||
</test-roots>
|
||||
</data>
|
||||
</configuration>
|
||||
</project>
|
||||
@@ -0,0 +1,204 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
package com.chloefontenot.mp5.files_chloefontenot;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import javafx.application.Application;
|
||||
import javafx.geometry.HPos;
|
||||
import javafx.geometry.Pos;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.control.TextField;
|
||||
import javafx.scene.layout.ColumnConstraints;
|
||||
import javafx.scene.layout.GridPane;
|
||||
import javafx.scene.layout.RowConstraints;
|
||||
import javafx.stage.Stage;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author chloe
|
||||
*/
|
||||
public class AddressBookFX extends Application {
|
||||
|
||||
ArrayList<AddressBookEntry> addressArray = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
public void start(Stage stage) throws Exception
|
||||
{
|
||||
GridPane primaryGridPane = new GridPane();
|
||||
GridPane textFieldGridPane = new GridPane();
|
||||
GridPane addressFieldPane = new GridPane();
|
||||
GridPane buttonFieldPane = new GridPane();
|
||||
|
||||
// Text fields / labels
|
||||
textFieldGridPane.add(new Label("Name"), 0, 0);
|
||||
textFieldGridPane.add(new Label("Street"), 0, 1);
|
||||
textFieldGridPane.add(new Label("City"), 0, 2);
|
||||
addressFieldPane.add(new Label("State"), 2, 0);
|
||||
addressFieldPane.add(new Label("ZIP"), 4, 0);
|
||||
TextField nameTextField = new TextField();
|
||||
TextField streetTextField = new TextField();
|
||||
TextField cityTextField = new TextField();
|
||||
TextField stateTextField = new TextField();
|
||||
TextField zipTextField = new TextField();
|
||||
textFieldGridPane.add(nameTextField, 1, 0);
|
||||
textFieldGridPane.add(streetTextField, 1, 1);
|
||||
textFieldGridPane.add(addressFieldPane, 1, 2);
|
||||
addressFieldPane.add(cityTextField, 1, 0);
|
||||
addressFieldPane.add(stateTextField, 3, 0);
|
||||
addressFieldPane.add(zipTextField, 5, 0);
|
||||
textFieldGridPane.getColumnConstraints().add(new ColumnConstraints(50));
|
||||
primaryGridPane.add(textFieldGridPane, 0, 0);
|
||||
|
||||
// Buttons
|
||||
Button addButton = new Button("Add");
|
||||
Button firstButton = new Button("First");
|
||||
Button nextButton = new Button("Next");
|
||||
Button previousButton = new Button("Previous");
|
||||
Button lastButton = new Button("Last");
|
||||
Button updateButton = new Button("Update");
|
||||
buttonFieldPane.add(addButton, 0, 0);
|
||||
buttonFieldPane.add(firstButton, 1, 0);
|
||||
buttonFieldPane.add(nextButton, 2, 0);
|
||||
buttonFieldPane.add(previousButton, 3, 0);
|
||||
buttonFieldPane.add(lastButton, 4, 0);
|
||||
buttonFieldPane.add(updateButton, 5, 0);
|
||||
primaryGridPane.add(buttonFieldPane, 0, 1);
|
||||
primaryGridPane.setAlignment(Pos.CENTER);
|
||||
buttonFieldPane.setHgap(10);
|
||||
|
||||
addButton.setOnAction(e -> {
|
||||
|
||||
});
|
||||
firstButton.setOnAction(e -> {
|
||||
|
||||
});
|
||||
nextButton.setOnAction(e -> {
|
||||
|
||||
});
|
||||
previousButton.setOnAction(e -> {
|
||||
|
||||
});
|
||||
lastButton.setOnAction(e -> {
|
||||
|
||||
});
|
||||
updateButton.setOnAction(e -> {
|
||||
|
||||
});
|
||||
|
||||
Scene scene = new Scene(primaryGridPane);
|
||||
stage.setScene(scene);
|
||||
stage.show();
|
||||
}
|
||||
|
||||
public static void main(String[] args)
|
||||
{
|
||||
File addressBook = new File("AddressBookFX.dat");
|
||||
if (!addressBook.exists()) {
|
||||
try (ObjectOutputStream fileStream = new ObjectOutputStream(new FileOutputStream(addressBook))) {
|
||||
fileStream.writeObject(new DataContainer());
|
||||
} catch (IOException ex) {
|
||||
System.out.println(ex);
|
||||
}
|
||||
} else {
|
||||
|
||||
try (ObjectInputStream fileStream = new ObjectInputStream(new FileInputStream(addressBook))) {
|
||||
addressBook = (ArrayList<AddressBookEntry>) fileStream.readObject();
|
||||
} catch (IOException ex) {
|
||||
System.out.println(ex);
|
||||
} catch (ClassNotFoundException ex) {
|
||||
System.out.println(ex);
|
||||
}
|
||||
}
|
||||
|
||||
launch();
|
||||
}
|
||||
}
|
||||
|
||||
class AddressBookEntry implements Serializable {
|
||||
|
||||
private String name;
|
||||
private String street;
|
||||
private String city;
|
||||
private String state;
|
||||
private String zip;
|
||||
|
||||
public AddressBookEntry()
|
||||
{
|
||||
this.name = "Enter a name here.";
|
||||
this.street = "Enter a street here.";
|
||||
this.city = "Enter a city here.";
|
||||
this.state = "Enter a state here.";
|
||||
this.zip = "Enter a zip here.";
|
||||
}
|
||||
|
||||
public AddressBookEntry(String name, String street, String city, String state, String zip)
|
||||
{
|
||||
this.name = name;
|
||||
this.street = street;
|
||||
this.city = city;
|
||||
this.state = state;
|
||||
this.zip = zip;
|
||||
}
|
||||
|
||||
public String getZip()
|
||||
{
|
||||
return zip;
|
||||
}
|
||||
|
||||
public void setZip(String zip)
|
||||
{
|
||||
this.zip = zip;
|
||||
}
|
||||
|
||||
public String getState()
|
||||
{
|
||||
return state;
|
||||
}
|
||||
|
||||
public void setState(String state)
|
||||
{
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
public String getCity()
|
||||
{
|
||||
return city;
|
||||
}
|
||||
|
||||
public void setCity(String city)
|
||||
{
|
||||
this.city = city;
|
||||
}
|
||||
|
||||
public String getStreet()
|
||||
{
|
||||
return street;
|
||||
}
|
||||
|
||||
public void setStreet(String street)
|
||||
{
|
||||
this.street = street;
|
||||
}
|
||||
|
||||
public String getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name)
|
||||
{
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package com.chloefontenot.mp5.files_chloefontenot;
|
||||
|
||||
import javafx.application.Application;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.layout.StackPane;
|
||||
import javafx.stage.Stage;
|
||||
|
||||
|
||||
/**
|
||||
* JavaFX App
|
||||
*/
|
||||
public class App extends Application {
|
||||
|
||||
@Override
|
||||
public void start(Stage stage) {
|
||||
var javaVersion = SystemInfo.javaVersion();
|
||||
var javafxVersion = SystemInfo.javafxVersion();
|
||||
|
||||
var label = new Label("Hello, JavaFX " + javafxVersion + ", running on Java " + javaVersion + ".");
|
||||
var scene = new Scene(new StackPane(label), 640, 480);
|
||||
stage.setScene(scene);
|
||||
stage.show();
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
launch();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
package com.chloefontenot.mp5.files_chloefontenot;
|
||||
|
||||
import java.io.EOFException;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.RandomAccessFile;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author chloe
|
||||
*/
|
||||
public class Exercise17_01 {
|
||||
|
||||
public static void main(String[] args)
|
||||
{
|
||||
try (RandomAccessFile fileIO = new RandomAccessFile("Exercise17_01.txt", "rw")) {
|
||||
int random = 0;
|
||||
System.out.println("Writing data to file...");
|
||||
for (int i = 1; i < 100 + 1; ++i) {
|
||||
random = (int) (Math.random() * 9) + 1;
|
||||
System.out.print(random + " ");
|
||||
if (i != 0 && i % 10 == 0) {
|
||||
System.out.println();
|
||||
}
|
||||
fileIO.writeInt(random);
|
||||
}
|
||||
System.out.println("Wrote to the file successfully!");
|
||||
System.out.println("File contents:");
|
||||
fileIO.seek(0);
|
||||
int readIterator = 1;
|
||||
while (true) {
|
||||
try {
|
||||
System.out.print(fileIO.readInt() + " ");
|
||||
if (readIterator != 0 && readIterator % 10 == 0) {
|
||||
System.out.println();
|
||||
}
|
||||
++readIterator;
|
||||
} catch (EOFException e) {
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} catch (Exception ex) {
|
||||
System.out.println(ex);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
package com.chloefontenot.mp5.files_chloefontenot;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author chloe
|
||||
*/
|
||||
public class Exercise17_03 {
|
||||
|
||||
static int fileSize = Math.abs((int) (Math.random() * 1024));
|
||||
|
||||
public static void writeData()
|
||||
{
|
||||
try (FileOutputStream fileWrite = new FileOutputStream("Exercise17_03.dat")) {
|
||||
// Write a unspecified number of integers into the file.
|
||||
// Must be positive!
|
||||
int randInt = 0;
|
||||
for (int i = 0; i < fileSize; ++i) {
|
||||
randInt = (int) (Math.random() * 10);
|
||||
fileWrite.write(randInt);
|
||||
}
|
||||
} catch (IOException ex) {
|
||||
System.out.println(ex);
|
||||
}
|
||||
System.out.println("Wrote data to the file!");
|
||||
}
|
||||
|
||||
public static int[] readData()
|
||||
{
|
||||
int[] fileData = new int[fileSize];
|
||||
try (FileInputStream fileRead = new FileInputStream("Exercise17_03.dat")) {
|
||||
// Read the data back
|
||||
int dataIterator = 0;
|
||||
int dataStream = 0;
|
||||
while (fileRead.available() > 0) {
|
||||
dataStream = fileRead.read();
|
||||
fileData[dataIterator++] = dataStream;
|
||||
System.out.print(dataStream + " ");
|
||||
if ((dataIterator + 1) % 10 == 0) {
|
||||
System.out.println();
|
||||
}
|
||||
}
|
||||
} catch (IOException ex) {
|
||||
System.out.println(ex);
|
||||
}
|
||||
return fileData;
|
||||
}
|
||||
|
||||
public static void main(String[] args)
|
||||
{
|
||||
System.out.println("Ints to write: " + fileSize);
|
||||
writeData();
|
||||
int[] fileData = readData();
|
||||
// Sum the digits
|
||||
int sum = 0;
|
||||
for (int i: fileData) {
|
||||
sum += i;
|
||||
}
|
||||
System.out.println("\nThe sum of the integers in the file is: " + sum);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
package com.chloefontenot.mp5.files_chloefontenot;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.Serializable;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author chloe
|
||||
*/
|
||||
public class Exercise17_05 {
|
||||
public static void main(String[] args) {
|
||||
File dataFile = new File("Exercise17_05.dat");
|
||||
if(!dataFile.exists()) {
|
||||
try (ObjectOutputStream fileStream = new ObjectOutputStream(new FileOutputStream(dataFile))) {
|
||||
fileStream.writeObject(new DataContainer());
|
||||
} catch (IOException ex) {
|
||||
System.out.println(ex);
|
||||
}
|
||||
}
|
||||
DataContainer data = null;
|
||||
try (ObjectInputStream fileStream = new ObjectInputStream(new FileInputStream(dataFile))) {
|
||||
data = (DataContainer) fileStream.readObject();
|
||||
} catch (IOException ex) {
|
||||
System.out.println(ex);
|
||||
} catch (ClassNotFoundException ex) {
|
||||
System.out.println(ex);
|
||||
}
|
||||
// Now print out the data!
|
||||
System.out.println("We got the data from the file!");
|
||||
System.out.println(data.toString());
|
||||
}
|
||||
}
|
||||
|
||||
class DataContainer implements Serializable {
|
||||
int[] intArray = {1, 2, 3, 4};
|
||||
Date currentDate = new Date();
|
||||
double doubleMoment = 5.5;
|
||||
|
||||
public int[] getIntArray()
|
||||
{
|
||||
return intArray;
|
||||
}
|
||||
|
||||
public Date getCurrentDate()
|
||||
{
|
||||
return currentDate;
|
||||
}
|
||||
|
||||
public double getDoubleMoment()
|
||||
{
|
||||
return doubleMoment;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
String intString = "[";
|
||||
for (int i = 0; i < intArray.length - 1; ++i) {
|
||||
intString += intArray[i];
|
||||
if (i == (intArray.length - 2)) {
|
||||
intString += "]";
|
||||
} else {
|
||||
intString += ", ";
|
||||
}
|
||||
}
|
||||
return "DataContainer{" + "intArray=" + intString + ", currentDate=" + currentDate + ", doubleMoment=" + doubleMoment + '}';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.chloefontenot.mp5.files_chloefontenot;
|
||||
|
||||
public class SystemInfo {
|
||||
|
||||
public static String javaVersion() {
|
||||
return System.getProperty("java.version");
|
||||
}
|
||||
|
||||
public static String javafxVersion() {
|
||||
return System.getProperty("javafx.version");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
module com.chloefontenot.mp5.files_chloefontenot{
|
||||
requires javafx.controls;
|
||||
exports com.chloefontenot.mp5.files_chloefontenot;
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
|
||||
<html>
|
||||
<head>
|
||||
<title>BinaryToDecimal.java</title>
|
||||
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
|
||||
<style type="text/css">
|
||||
<!--
|
||||
body {color: #a9b7c6; background-color: #2b2b2b; font-family: monospace; font-weight: bold}
|
||||
pre {color: #a9b7c6; background-color: #2b2b2b; font-family: monospace; font-weight: bold}
|
||||
table {color: #888888; background-color: #313335; font-family: monospace; font-weight: bold}
|
||||
.literal {color: #cc7832}
|
||||
.string {color: #6a8759}
|
||||
.number {color: #6897bb}
|
||||
.whitespace {color: #505050}
|
||||
.comment {color: #808080}
|
||||
-->
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<table width="100%"><tr><td align="center">/home/chloe/ASDV-Java/Semester 3/Assignments/MP3_Recursion_ChloeFontenot/src/mp3_recursion_chloefontenot/BinaryToDecimal.java</td></tr></table>
|
||||
<pre>
|
||||
<span class="literal">package</span> mp3_recursion_chloefontenot;
|
||||
|
||||
|
||||
<span class="literal">import</span> java.util.Scanner;
|
||||
|
||||
<span class="comment">/*</span>
|
||||
<span class="comment"> * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license</span>
|
||||
<span class="comment"> * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template</span>
|
||||
<span class="comment"> */</span>
|
||||
<span class="comment">/**</span>
|
||||
<span class="comment"> *</span>
|
||||
<span class="comment"> * </span><span class="comment">@author</span> <span class="comment">chloe</span>
|
||||
<span class="comment">*/</span>
|
||||
<span class="literal">public</span> <span class="literal">class</span> BinaryToDecimal {
|
||||
|
||||
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> main(String[] args) {
|
||||
Scanner input = <span class="literal">new</span> Scanner(System.in);
|
||||
<span class="literal">while</span> (<span class="literal">true</span>) {
|
||||
System.out.print(<span class="string">"</span><span class="string">Enter a binary number: </span><span class="string">"</span>);
|
||||
String binary = input.nextLine();
|
||||
System.out.println(binary + <span class="string">"</span><span class="string"> in decimal is </span><span class="string">"</span> + binaryToDecimal(binary));
|
||||
}
|
||||
}
|
||||
|
||||
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">int</span> binaryToDecimal(String binaryString) {
|
||||
<span class="literal">return</span> binaryToDecimal(binaryString, <span class="number">0</span>, binaryString.length(), <span class="number">0</span>);
|
||||
}
|
||||
|
||||
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">int</span> binaryToDecimal(String binaryString, <span class="literal">int</span> low, <span class="literal">int</span> high, <span class="literal">int</span> value) {
|
||||
<span class="literal">if</span> (low == binaryString.length() - <span class="number">1</span>) {
|
||||
<span class="literal">return</span> value;
|
||||
}
|
||||
<span class="literal">if</span> (binaryString.charAt(low) == <span class="string">'</span><span class="string">1</span><span class="string">'</span>) {
|
||||
<span class="literal">return</span> binaryToDecimal(binaryString, ++low, --high, value += Math.pow(<span class="number">2</span>, high));
|
||||
} <span class="literal">else</span> {
|
||||
<span class="literal">return</span> binaryToDecimal(binaryString, ++low, --high, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
</pre></body>
|
||||
</html>
|
||||
@@ -0,0 +1,86 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
|
||||
<html>
|
||||
<head>
|
||||
<title>DecimalToBinary.java</title>
|
||||
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
|
||||
<style type="text/css">
|
||||
<!--
|
||||
body {color: #a9b7c6; background-color: #2b2b2b; font-family: monospace; font-weight: bold}
|
||||
pre {color: #a9b7c6; background-color: #2b2b2b; font-family: monospace; font-weight: bold}
|
||||
table {color: #888888; background-color: #313335; font-family: monospace; font-weight: bold}
|
||||
.literal {color: #cc7832}
|
||||
.string {color: #6a8759}
|
||||
.number {color: #6897bb}
|
||||
.comment {color: #808080}
|
||||
.whitespace {color: #505050}
|
||||
-->
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<table width="100%"><tr><td align="center">/home/chloe/ASDV-Java/Semester 3/Assignments/MP3_Recursion_ChloeFontenot/src/mp3_recursion_chloefontenot/DecimalToBinary.java</td></tr></table>
|
||||
<pre>
|
||||
<span class="comment">/*</span>
|
||||
<span class="comment"> * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license</span>
|
||||
<span class="comment"> * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template</span>
|
||||
<span class="comment"> */</span>
|
||||
<span class="literal">package</span> mp3_recursion_chloefontenot;
|
||||
|
||||
<span class="literal">import</span> java.util.Scanner;
|
||||
|
||||
<span class="comment">/**</span>
|
||||
<span class="comment"> *</span>
|
||||
<span class="comment"> * </span><span class="comment">@author</span> <span class="comment">chloe</span>
|
||||
<span class="comment">*/</span>
|
||||
<span class="literal">public</span> <span class="literal">class</span> DecimalToBinary {
|
||||
|
||||
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> main(String[] args) {
|
||||
Scanner input = <span class="literal">new</span> Scanner(System.in);
|
||||
<span class="literal">while</span> (<span class="literal">true</span>) {
|
||||
System.out.print(<span class="string">"</span><span class="string">Enter a decimal integer: </span><span class="string">"</span>);
|
||||
<span class="literal">int</span> decimal = input.nextInt();
|
||||
System.out.println(decimal + <span class="string">"</span><span class="string"> is </span><span class="string">"</span> + decimalToBinary(decimal) + <span class="string">"</span><span class="string"> in binary.</span><span class="string">"</span>);
|
||||
}
|
||||
}
|
||||
|
||||
<span class="literal">public</span> <span class="literal">static</span> String decimalToBinary(<span class="literal">int</span> value) {
|
||||
<span class="literal">return</span> reverse(decimalToBinary(value, <span class="string">""</span>));
|
||||
}
|
||||
|
||||
<span class="literal">public</span> <span class="literal">static</span> String decimalToBinary(<span class="literal">int</span> value, String bin) {
|
||||
<span class="literal">if</span> (value == <span class="number">0</span>) {
|
||||
<span class="literal">return</span> bin += <span class="string">""</span>;
|
||||
} <span class="literal">else</span> <span class="literal">if</span> (value > <span class="number">0</span>) {
|
||||
<span class="literal">if</span> (value % <span class="number">2</span> == <span class="number">1</span>) {
|
||||
<span class="literal">return</span> decimalToBinary((<span class="literal">int</span>) Math.floor(value / <span class="number">2</span>), bin + <span class="string">"</span><span class="string">1</span><span class="string">"</span>);
|
||||
} <span class="literal">else</span> {
|
||||
<span class="literal">return</span> decimalToBinary((<span class="literal">int</span>) Math.floor(value / <span class="number">2</span>), bin + <span class="string">"</span><span class="string">0</span><span class="string">"</span>);
|
||||
}
|
||||
}
|
||||
|
||||
<span class="literal">return</span> <span class="string">"</span><span class="string">0 naht ssel si eulav</span><span class="string">"</span>;
|
||||
|
||||
}
|
||||
<span class="literal">public</span> <span class="literal">static</span> String reverse(String input) {
|
||||
String returnString = <span class="string">""</span>;
|
||||
<span class="literal">for</span> (<span class="literal">int</span> i = input.length() - <span class="number">1</span>; <span class="number">0</span> <= i; --i) {
|
||||
returnString += input.charAt(i);
|
||||
}
|
||||
<span class="literal">return</span> returnString;
|
||||
}
|
||||
|
||||
<span class="literal">public</span> <span class="literal">static</span> String decimalToBinaryIterative(<span class="literal">int</span> value) {
|
||||
String bin = <span class="string">""</span>;
|
||||
<span class="literal">while</span> (value > <span class="number">0</span>) {
|
||||
<span class="literal">if</span> (value % <span class="number">2</span> == <span class="number">1</span>)
|
||||
bin += <span class="string">"</span><span class="string">1</span><span class="string">"</span>;
|
||||
<span class="literal">else</span>
|
||||
bin += <span class="string">"</span><span class="string">0</span><span class="string">"</span>;
|
||||
|
||||
value /= <span class="number">2</span>;
|
||||
}
|
||||
<span class="literal">return</span> reverse(bin);
|
||||
}
|
||||
}
|
||||
|
||||
</pre></body>
|
||||
</html>
|
||||
@@ -0,0 +1,397 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
|
||||
<html>
|
||||
<head>
|
||||
<title>Maze.java</title>
|
||||
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
|
||||
<style type="text/css">
|
||||
<!--
|
||||
body {color: #a9b7c6; background-color: #2b2b2b; font-family: monospace; font-weight: bold}
|
||||
pre {color: #a9b7c6; background-color: #2b2b2b; font-family: monospace; font-weight: bold}
|
||||
table {color: #888888; background-color: #313335; font-family: monospace; font-weight: bold}
|
||||
.literal {color: #cc7832}
|
||||
.ST4 {font-family: monospace; font-weight: bold; font-style: italic}
|
||||
.ST0 {color: #287bde}
|
||||
.number {color: #6897bb}
|
||||
.string {color: #6a8759}
|
||||
.ST1 {color: #9876aa}
|
||||
.ST2 {color: #ffc66d}
|
||||
.comment {color: #808080}
|
||||
.whitespace {color: #505050}
|
||||
.ST3 {color: #9876aa; font-family: monospace; font-weight: bold; font-style: italic}
|
||||
.ST5 {color: #ffc66d; font-family: monospace; font-weight: bold; font-style: italic}
|
||||
-->
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<table width="100%"><tr><td align="center">/home/chloe/ASDV-Java/Semester 3/Assignments/MP3_Recursion_ChloeFontenot/src/mp3_recursion_chloefontenot/Maze.java</td></tr></table>
|
||||
<pre>
|
||||
<span class="comment">/*</span>
|
||||
<span class="comment"> * Click </span><span class="ST0">nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt</span><span class="comment"> to change this license</span>
|
||||
<span class="comment"> * Click </span><span class="ST0">nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java</span><span class="comment"> to edit this template</span>
|
||||
<span class="comment"> */</span>
|
||||
<span class="literal">package</span> mp3_recursion_chloefontenot;
|
||||
|
||||
<span class="literal">import</span> java.util.Optional;
|
||||
<span class="literal">import</span> javafx.application.Application;
|
||||
<span class="literal">import</span> javafx.geometry.Pos;
|
||||
<span class="literal">import</span> javafx.scene.Scene;
|
||||
<span class="literal">import</span> javafx.scene.control.Alert;
|
||||
<span class="literal">import</span> javafx.scene.control.Button;
|
||||
<span class="literal">import</span> javafx.scene.control.ButtonType;
|
||||
<span class="literal">import</span> javafx.scene.control.Label;
|
||||
<span class="literal">import</span> javafx.scene.layout.BorderPane;
|
||||
<span class="literal">import</span> javafx.scene.layout.GridPane;
|
||||
<span class="literal">import</span> javafx.scene.layout.HBox;
|
||||
<span class="literal">import</span> javafx.scene.layout.StackPane;
|
||||
<span class="literal">import</span> javafx.scene.paint.Color;
|
||||
<span class="literal">import</span> javafx.scene.shape.Line;
|
||||
<span class="literal">import</span> javafx.scene.shape.Rectangle;
|
||||
<span class="literal">import</span> javafx.stage.Stage;
|
||||
|
||||
<span class="comment">/**</span>
|
||||
<span class="comment"> *</span>
|
||||
<span class="comment"> * </span><span class="comment">@author</span> <span class="comment">chloe</span>
|
||||
<span class="comment">*/</span>
|
||||
<span class="literal">public</span> <span class="literal">class</span> Maze <span class="literal">extends</span> Application {
|
||||
|
||||
<span class="literal">double</span> <span class="ST1">paneWidth</span> = <span class="number">600</span>;
|
||||
<span class="literal">double</span> <span class="ST1">paneHeight</span> = <span class="number">600</span>;
|
||||
|
||||
<span class="literal">private</span> Cell[][] <span class="ST1">board</span> = <span class="literal">new</span> Cell[<span class="number">8</span>][<span class="number">8</span>];
|
||||
<span class="literal">private</span> Button <span class="ST1">btFindPath</span> = <span class="literal">new</span> Button(<span class="string">"</span><span class="string">Find Path Top Left to Bottom Right</span><span class="string">"</span>);
|
||||
<span class="literal">private</span> Button <span class="ST1">btFindPath2</span> = <span class="literal">new</span> Button(<span class="string">"</span><span class="string">Find Path Top Right to Bottom Left</span><span class="string">"</span>);
|
||||
<span class="literal">private</span> Button <span class="ST1">btClearPath</span> = <span class="literal">new</span> Button(<span class="string">"</span><span class="string">Clear Path</span><span class="string">"</span>);
|
||||
<span class="literal">private</span> Label <span class="ST1">lblStatus</span> = <span class="literal">new</span> Label();
|
||||
|
||||
@Override <span class="comment">// Override the start method in the Application class</span>
|
||||
<span class="literal">public</span> <span class="literal">void</span> <span class="ST2">start</span>(Stage primaryStage) {
|
||||
GridPane gridPane = <span class="literal">new</span> GridPane();
|
||||
<span class="literal">for</span> (<span class="literal">int</span> i = <span class="number">0</span>; i < <span class="number">8</span>; i++) {
|
||||
<span class="literal">for</span> (<span class="literal">int</span> j = <span class="number">0</span>; j < <span class="number">8</span>; j++) {
|
||||
gridPane.add(<span class="ST1">board</span>[i][j] = <span class="literal">new</span> Cell(), j, i);
|
||||
}
|
||||
}
|
||||
|
||||
HBox hBox = <span class="literal">new</span> HBox(<span class="number">5</span>);
|
||||
hBox.setAlignment(Pos.<span class="ST3">CENTER</span>);
|
||||
hBox.getChildren().addAll(<span class="ST1">b</span><span class="ST1">tFindPath</span>, <span class="ST1">b</span><span class="ST1">tFindPath2</span>, <span class="ST1">b</span><span class="ST1">tClearPath</span>);
|
||||
|
||||
BorderPane pane = <span class="literal">new</span> BorderPane();
|
||||
pane.setTop(<span class="ST1">l</span><span class="ST1">blStatus</span>);
|
||||
BorderPane.<span class="ST4">setAlignment</span>(<span class="ST1">l</span><span class="ST1">blStatus</span>, Pos.<span class="ST3">CENTER</span>);
|
||||
pane.setCenter(gridPane);
|
||||
pane.setBottom(hBox);
|
||||
|
||||
<span class="comment">// Create a scene and place it in the stage</span>
|
||||
Scene scene = <span class="literal">new</span> Scene(pane, <span class="ST1">p</span><span class="ST1">aneWidth</span>, <span class="ST1">paneHeight</span> + <span class="number">60</span>);
|
||||
primaryStage.setTitle(<span class="string">"</span><span class="string">Maze</span><span class="string">"</span>); <span class="comment">// Set the stage title</span>
|
||||
primaryStage.setScene(scene); <span class="comment">// Place the scene in the stage</span>
|
||||
primaryStage.show(); <span class="comment">// Display the stage</span>
|
||||
|
||||
<span class="ST1">btFindPath</span>.setOnAction(e -> findPath());
|
||||
<span class="ST1">btFindPath2</span>.setOnAction(e -> findPath2());
|
||||
<span class="ST1">btClearPath</span>.setOnAction(e -> clearPath());
|
||||
showSampleMessage();
|
||||
|
||||
}
|
||||
|
||||
<span class="literal">public</span> <span class="literal">void</span> <span class="ST2">showSampleMessage</span>() {
|
||||
Alert a = <span class="literal">new</span> Alert(Alert.<span class="ST4">AlertType</span>.<span class="ST3">CONFIRMATION</span>);
|
||||
|
||||
a.setTitle(<span class="string">"</span><span class="string">Maze Information</span><span class="string">"</span>);
|
||||
a.setHeaderText(<span class="string">"</span><span class="string"> Put this message in its proper place. </span><span class="string">"</span>);
|
||||
a.setContentText(<span class="string">"</span><span class="string">This square cannot have an X</span><span class="string">"</span>);
|
||||
Optional<ButtonType> result = a.showAndWait();
|
||||
<span class="literal">if</span> (result.get() == ButtonType.<span class="ST3">OK</span>) {
|
||||
System.<span class="ST3">out</span>.println(<span class="string">"</span><span class="string">OK </span><span class="string">"</span>);
|
||||
} <span class="literal">else</span> <span class="literal">if</span> (result.get() == ButtonType.<span class="ST3">CANCEL</span>) {
|
||||
System.<span class="ST3">out</span>.println(<span class="string">"</span><span class="string">CANCEL</span><span class="string">"</span>);
|
||||
}
|
||||
}
|
||||
<span class="literal">public</span> <span class="literal">void</span> <span class="ST2">clearCells</span>() {
|
||||
<span class="literal">for</span> (<span class="literal">int</span> i = <span class="number">0</span>; i < <span class="number">8</span>; ++i) {
|
||||
<span class="literal">for</span> (<span class="literal">int</span> j = <span class="number">0</span>; j < <span class="number">8</span>; j++) {
|
||||
<span class="ST1">board</span>[i][j].resetCell();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
<span class="literal">public</span> <span class="literal">void</span> <span class="ST2">findPath</span>() {
|
||||
clearCells();
|
||||
<span class="literal">if</span> (findPath(<span class="number">0</span>, <span class="number">0</span>)) {
|
||||
<span class="ST1">lblStatus</span>.setText(<span class="string">"</span><span class="string">path found</span><span class="string">"</span>);
|
||||
} <span class="literal">else</span> {
|
||||
<span class="ST1">lblStatus</span>.setText(<span class="string">"</span><span class="string">No path exists</span><span class="string">"</span>);
|
||||
}
|
||||
}
|
||||
|
||||
<span class="literal">public</span> <span class="literal">void</span> <span class="ST2">findPath2</span>() {
|
||||
clearCells();
|
||||
<span class="literal">if</span> (findPath2(<span class="number">0</span>, <span class="number">7</span>)) {
|
||||
<span class="ST1">lblStatus</span>.setText(<span class="string">"</span><span class="string">path found</span><span class="string">"</span>);
|
||||
} <span class="literal">else</span> {
|
||||
<span class="ST1">lblStatus</span>.setText(<span class="string">"</span><span class="string">No path exists</span><span class="string">"</span>);
|
||||
}
|
||||
}
|
||||
|
||||
<span class="literal">public</span> <span class="literal">boolean</span> <span class="ST2">findPath</span>(<span class="literal">int</span> row, <span class="literal">int</span> col) {
|
||||
<span class="ST1">board</span>[row][col].visit();
|
||||
|
||||
<span class="literal">if</span> ((col == <span class="number">7</span>) && (row == <span class="number">7</span>)) {
|
||||
<span class="ST1">board</span>[row][col].selectCell();
|
||||
<span class="literal">return</span> <span class="literal">true</span>;
|
||||
}
|
||||
|
||||
<span class="literal">if</span> ((row > <span class="number">0</span>) && !<span class="ST1">board</span>[row - <span class="number">1</span>][col].marked()
|
||||
&& !<span class="ST1">board</span>[row - <span class="number">1</span>][col].blocked() && !<span class="ST1">board</span>[row - <span class="number">1</span>][col].visited()) {
|
||||
block(row, col);
|
||||
|
||||
<span class="literal">if</span> (findPath(row - <span class="number">1</span>, col)) {
|
||||
<span class="ST1">board</span>[row][col].selectCell();
|
||||
<span class="literal">return</span> <span class="literal">true</span>;
|
||||
}
|
||||
|
||||
unblock(row, col);
|
||||
}
|
||||
|
||||
<span class="literal">if</span> ((row < <span class="number">7</span>) && !<span class="ST1">board</span>[row + <span class="number">1</span>][col].marked()
|
||||
&& !<span class="ST1">board</span>[row + <span class="number">1</span>][col].blocked() && !<span class="ST1">board</span>[row + <span class="number">1</span>][col].visited()) {
|
||||
block(row, col);
|
||||
|
||||
<span class="literal">if</span> (findPath(row + <span class="number">1</span>, col)) {
|
||||
<span class="ST1">board</span>[row][col].selectCell();
|
||||
<span class="literal">return</span> <span class="literal">true</span>;
|
||||
}
|
||||
|
||||
unblock(row, col);
|
||||
}
|
||||
|
||||
<span class="literal">if</span> ((col > <span class="number">0</span>) && !<span class="ST1">board</span>[row][col - <span class="number">1</span>].marked()
|
||||
&& !<span class="ST1">board</span>[row][col - <span class="number">1</span>].blocked() && !<span class="ST1">board</span>[row][col - <span class="number">1</span>].visited()) {
|
||||
block(row, col);
|
||||
<span class="literal">if</span> (findPath(row, col - <span class="number">1</span>)) {
|
||||
<span class="ST1">board</span>[row][col].selectCell();
|
||||
<span class="literal">return</span> <span class="literal">true</span>;
|
||||
}
|
||||
|
||||
unblock(row, col);
|
||||
}
|
||||
|
||||
<span class="literal">if</span> ((col < <span class="number">7</span>) && !<span class="ST1">board</span>[row][col + <span class="number">1</span>].marked()
|
||||
&& !<span class="ST1">board</span>[row][col + <span class="number">1</span>].blocked() && !<span class="ST1">board</span>[row][col + <span class="number">1</span>].visited()) {
|
||||
block(row, col);
|
||||
<span class="literal">if</span> (findPath(row, col + <span class="number">1</span>)) {
|
||||
<span class="ST1">board</span>[row][col].selectCell();
|
||||
<span class="literal">return</span> <span class="literal">true</span>;
|
||||
}
|
||||
|
||||
unblock(row, col);
|
||||
}
|
||||
|
||||
<span class="literal">return</span> <span class="literal">false</span>;
|
||||
}
|
||||
|
||||
<span class="literal">public</span> <span class="literal">boolean</span> <span class="ST2">findPath2</span>(<span class="literal">int</span> row, <span class="literal">int</span> col) {
|
||||
<span class="ST1">board</span>[row][col].visit();
|
||||
|
||||
<span class="literal">if</span> ((col == <span class="number">0</span>) && (row == <span class="number">7</span>)) {
|
||||
<span class="ST1">board</span>[row][col].selectCellGreen();
|
||||
<span class="literal">return</span> <span class="literal">true</span>;
|
||||
}
|
||||
|
||||
<span class="literal">if</span> ((row > <span class="number">0</span>) && !<span class="ST1">board</span>[row - <span class="number">1</span>][col].marked()
|
||||
&& !<span class="ST1">board</span>[row - <span class="number">1</span>][col].blocked() && !<span class="ST1">board</span>[row - <span class="number">1</span>][col].visited()) {
|
||||
block(row, col);
|
||||
|
||||
<span class="literal">if</span> (findPath2(row - <span class="number">1</span>, col)) {
|
||||
<span class="ST1">board</span>[row][col].selectCellGreen();
|
||||
<span class="literal">return</span> <span class="literal">true</span>;
|
||||
}
|
||||
|
||||
unblock(row, col);
|
||||
}
|
||||
|
||||
<span class="literal">if</span> ((row < <span class="number">7</span>) && !<span class="ST1">board</span>[row + <span class="number">1</span>][col].marked()
|
||||
&& !<span class="ST1">board</span>[row + <span class="number">1</span>][col].blocked() && !<span class="ST1">board</span>[row + <span class="number">1</span>][col].visited()) {
|
||||
block(row, col);
|
||||
|
||||
<span class="literal">if</span> (findPath2(row + <span class="number">1</span>, col)) {
|
||||
<span class="ST1">board</span>[row][col].selectCellGreen();
|
||||
<span class="literal">return</span> <span class="literal">true</span>;
|
||||
}
|
||||
|
||||
unblock(row, col);
|
||||
}
|
||||
|
||||
<span class="literal">if</span> ((col > <span class="number">0</span>) && !<span class="ST1">board</span>[row][col - <span class="number">1</span>].marked()
|
||||
&& !<span class="ST1">board</span>[row][col - <span class="number">1</span>].blocked() && !<span class="ST1">board</span>[row][col - <span class="number">1</span>].visited()) {
|
||||
block(row, col);
|
||||
<span class="literal">if</span> (findPath2(row, col - <span class="number">1</span>)) {
|
||||
<span class="ST1">board</span>[row][col].selectCellGreen();
|
||||
<span class="literal">return</span> <span class="literal">true</span>;
|
||||
}
|
||||
|
||||
unblock(row, col);
|
||||
}
|
||||
|
||||
<span class="literal">if</span> ((col < <span class="number">7</span>) && !<span class="ST1">board</span>[row][col + <span class="number">1</span>].marked()
|
||||
&& !<span class="ST1">board</span>[row][col + <span class="number">1</span>].blocked() && !<span class="ST1">board</span>[row][col + <span class="number">1</span>].visited()) {
|
||||
block(row, col);
|
||||
<span class="literal">if</span> (findPath2(row, col + <span class="number">1</span>)) {
|
||||
<span class="ST1">board</span>[row][col].selectCellGreen();
|
||||
<span class="literal">return</span> <span class="literal">true</span>;
|
||||
}
|
||||
|
||||
unblock(row, col);
|
||||
}
|
||||
|
||||
<span class="literal">return</span> <span class="literal">false</span>;
|
||||
}
|
||||
|
||||
<span class="comment">// Temporary block the neighbor to prevent neighboring path</span>
|
||||
<span class="literal">public</span> <span class="literal">void</span> <span class="ST2">block</span>(<span class="literal">int</span> row, <span class="literal">int</span> col) {
|
||||
<span class="literal">if</span> (row > <span class="number">0</span>) {
|
||||
<span class="ST1">board</span>[row - <span class="number">1</span>][col].block();
|
||||
}
|
||||
|
||||
<span class="literal">if</span> (row < <span class="number">7</span>) {
|
||||
<span class="ST1">board</span>[row + <span class="number">1</span>][col].block();
|
||||
}
|
||||
|
||||
<span class="literal">if</span> (col > <span class="number">0</span>) {
|
||||
<span class="ST1">board</span>[row][col - <span class="number">1</span>].block();
|
||||
}
|
||||
|
||||
<span class="literal">if</span> (col < <span class="number">7</span>) {
|
||||
<span class="ST1">board</span>[row][col + <span class="number">1</span>].block();
|
||||
}
|
||||
}
|
||||
|
||||
<span class="comment">// Remove the temporary block</span>
|
||||
<span class="literal">public</span> <span class="literal">void</span> <span class="ST2">unblock</span>(<span class="literal">int</span> row, <span class="literal">int</span> col) {
|
||||
<span class="literal">if</span> (row > <span class="number">0</span>) {
|
||||
<span class="ST1">board</span>[row - <span class="number">1</span>][col].unblock();
|
||||
}
|
||||
|
||||
<span class="literal">if</span> (row < <span class="number">7</span>) {
|
||||
<span class="ST1">board</span>[row + <span class="number">1</span>][col].unblock();
|
||||
}
|
||||
|
||||
<span class="literal">if</span> (col > <span class="number">0</span>) {
|
||||
<span class="ST1">board</span>[row][col - <span class="number">1</span>].unblock();
|
||||
}
|
||||
|
||||
<span class="literal">if</span> (col < <span class="number">7</span>) {
|
||||
<span class="ST1">board</span>[row][col + <span class="number">1</span>].unblock();
|
||||
}
|
||||
}
|
||||
|
||||
<span class="literal">public</span> <span class="literal">void</span> <span class="ST2">clearPath</span>() {
|
||||
<span class="literal">for</span> (<span class="literal">int</span> row = <span class="number">0</span>; row < <span class="ST1">board</span>.<span class="ST1">length</span>; row++) {
|
||||
<span class="literal">for</span> (<span class="literal">int</span> col = <span class="number">0</span>; col < <span class="ST1">board</span>[row].<span class="ST1">length</span>; col++) {
|
||||
<span class="ST1">board</span>[row][col].deselectCell();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> <span class="ST5">main</span>(String[] args) {
|
||||
<span class="ST4">launch</span>(args);
|
||||
}
|
||||
|
||||
<span class="comment">// Inner class</span>
|
||||
<span class="literal">class</span> Cell <span class="literal">extends</span> StackPane {
|
||||
|
||||
<span class="literal">private</span> <span class="literal">boolean</span> <span class="ST1">marked</span> = <span class="literal">false</span>;
|
||||
<span class="literal">private</span> <span class="literal">boolean</span> <span class="ST1">visited</span> = <span class="literal">false</span>;
|
||||
<span class="literal">private</span> <span class="literal">boolean</span> <span class="ST1">blocked</span> = <span class="literal">false</span>;
|
||||
|
||||
<span class="literal">double</span> <span class="ST1">width</span> = <span class="ST1">paneWidth</span> / <span class="number">8</span>;
|
||||
<span class="literal">double</span> <span class="ST1">height</span> = <span class="ST1">paneHeight</span> / <span class="number">8</span>;
|
||||
<span class="literal">private</span> Rectangle <span class="ST1">rectangle</span> = <span class="literal">new</span> Rectangle(<span class="number">0</span>, <span class="number">0</span>, <span class="ST1">w</span><span class="ST1">idth</span>, <span class="ST1">h</span><span class="ST1">eight</span>);
|
||||
|
||||
Line <span class="ST1">line1</span> = <span class="literal">new</span> Line(<span class="number">0</span>, <span class="number">0</span>, <span class="ST1">w</span><span class="ST1">idth</span>, <span class="ST1">h</span><span class="ST1">eight</span>);
|
||||
Line <span class="ST1">line2</span> = <span class="literal">new</span> Line(<span class="ST1">w</span><span class="ST1">idth</span>, <span class="number">0</span>, <span class="number">0</span>, <span class="ST1">h</span><span class="ST1">eight</span>);
|
||||
|
||||
<span class="literal">public</span> Cell() {
|
||||
<span class="literal">this</span>.getChildren().add(<span class="ST1">r</span><span class="ST1">ectangle</span>);
|
||||
<span class="ST1">rectangle</span>.setFill(Color.<span class="ST3">WHITE</span>);
|
||||
<span class="ST1">rectangle</span>.setStroke(Color.<span class="ST3">BLACK</span>);
|
||||
|
||||
<span class="literal">this</span>.setOnMousePressed(e
|
||||
-> {
|
||||
<span class="ST1">marked</span> = !<span class="ST1">marked</span>;
|
||||
<span class="literal">if</span> (<span class="ST1">marked</span>) {
|
||||
mark();
|
||||
} <span class="literal">else</span> {
|
||||
unmark();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
<span class="literal">public</span> <span class="literal">void</span> <span class="ST2">mark</span>() {
|
||||
<span class="literal">this</span>.getChildren().addAll(<span class="ST1">l</span><span class="ST1">ine1</span>, <span class="ST1">l</span><span class="ST1">ine2</span>);
|
||||
}
|
||||
|
||||
<span class="literal">public</span> <span class="literal">void</span> <span class="ST2">unmark</span>() {
|
||||
<span class="literal">this</span>.getChildren().remove(<span class="ST1">l</span><span class="ST1">ine1</span>);
|
||||
<span class="literal">this</span>.getChildren().remove(<span class="ST1">l</span><span class="ST1">ine2</span>);
|
||||
}
|
||||
|
||||
<span class="literal">public</span> <span class="literal">boolean</span> <span class="ST2">marked</span>() {
|
||||
<span class="literal">return</span> <span class="ST1">marked</span>;
|
||||
}
|
||||
|
||||
<span class="literal">public</span> <span class="literal">void</span> <span class="ST2">visit</span>() {
|
||||
<span class="ST1">visited</span> = <span class="literal">true</span>;
|
||||
}
|
||||
|
||||
<span class="literal">public</span> <span class="literal">boolean</span> <span class="ST2">visited</span>() {
|
||||
<span class="literal">return</span> <span class="ST1">visited</span>;
|
||||
}
|
||||
|
||||
<span class="literal">public</span> <span class="literal">boolean</span> <span class="ST2">blocked</span>() {
|
||||
<span class="literal">return</span> <span class="ST1">blocked</span>;
|
||||
}
|
||||
|
||||
<span class="literal">public</span> <span class="literal">void</span> <span class="ST2">block</span>() {
|
||||
<span class="ST1">blocked</span> = <span class="literal">true</span>;
|
||||
}
|
||||
|
||||
<span class="literal">public</span> <span class="literal">void</span> <span class="ST2">unblock</span>() {
|
||||
<span class="ST1">blocked</span> = <span class="literal">false</span>;
|
||||
}
|
||||
|
||||
<span class="literal">public</span> <span class="literal">void</span> <span class="ST2">selectCell</span>() {
|
||||
<span class="literal">if</span> (<span class="ST1">rectangle</span>.getFill().equals(Color.<span class="ST3">GREEN</span>)) {
|
||||
<span class="ST1">rectangle</span>.setFill(Color.<span class="ST3">YELLOW</span>);
|
||||
} <span class="literal">else</span> {
|
||||
<span class="ST1">rectangle</span>.setFill(Color.<span class="ST3">RED</span>);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
<span class="literal">public</span> <span class="literal">void</span> <span class="ST2">selectCellGreen</span>() {
|
||||
<span class="literal">if</span> (<span class="ST1">rectangle</span>.getFill().equals(Color.<span class="ST3">RED</span>)) {
|
||||
<span class="ST1">rectangle</span>.setFill(Color.<span class="ST3">YELLOW</span>);
|
||||
} <span class="literal">else</span> {
|
||||
<span class="ST1">rectangle</span>.setFill(Color.<span class="ST3">GREEN</span>);
|
||||
}
|
||||
}
|
||||
|
||||
<span class="literal">public</span> <span class="literal">void</span> <span class="ST2">deselectCell</span>() {
|
||||
<span class="ST1">rectangle</span>.setFill(Color.<span class="ST3">WHITE</span>);
|
||||
<span class="ST1">blocked</span> = <span class="literal">false</span>;
|
||||
<span class="ST1">visited</span> = <span class="literal">false</span>;
|
||||
}
|
||||
|
||||
<span class="literal">public</span> <span class="literal">void</span> <span class="ST2">resetCell</span>() {
|
||||
<span class="comment">//rectangle.setFill(Color.WHITE);</span>
|
||||
<span class="ST1">blocked</span> = <span class="literal">false</span>;
|
||||
<span class="ST1">visited</span> = <span class="literal">false</span>;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
</pre></body>
|
||||
</html>
|
||||
@@ -0,0 +1,82 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
|
||||
<html>
|
||||
<head>
|
||||
<title>SelectionSortR.java</title>
|
||||
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
|
||||
<style type="text/css">
|
||||
<!--
|
||||
body {color: #a9b7c6; background-color: #2b2b2b; font-family: monospace; font-weight: bold}
|
||||
pre {color: #a9b7c6; background-color: #2b2b2b; font-family: monospace; font-weight: bold}
|
||||
table {color: #888888; background-color: #313335; font-family: monospace; font-weight: bold}
|
||||
.literal {color: #cc7832}
|
||||
.ST2 {font-family: monospace; font-weight: bold; font-style: italic}
|
||||
.ST0 {color: #287bde}
|
||||
.number {color: #6897bb}
|
||||
.string {color: #6a8759}
|
||||
.ST3 {color: #9876aa}
|
||||
.comment {color: #808080}
|
||||
.whitespace {color: #505050}
|
||||
.ST1 {color: #ffc66d; font-family: monospace; font-weight: bold; font-style: italic}
|
||||
.ST4 {color: #9876aa; font-family: monospace; font-weight: bold; font-style: italic}
|
||||
-->
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<table width="100%"><tr><td align="center">/home/chloe/ASDV-Java/Semester 3/Assignments/MP3_Recursion_ChloeFontenot/src/mp3_recursion_chloefontenot/SelectionSortR.java</td></tr></table>
|
||||
<pre>
|
||||
<span class="comment">/*</span>
|
||||
<span class="comment"> * Click </span><span class="ST0">nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt</span><span class="comment"> to change this license</span>
|
||||
<span class="comment"> * Click </span><span class="ST0">nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java</span><span class="comment"> to edit this template</span>
|
||||
<span class="comment"> */</span>
|
||||
<span class="literal">package</span> edu.slcc.asdv.chloe.lab5.recursion2_chloefontenot;
|
||||
|
||||
<span class="comment">/**</span>
|
||||
<span class="comment"> *</span>
|
||||
<span class="comment"> * </span><span class="comment">@author</span> <span class="comment">chloe</span>
|
||||
<span class="comment">*/</span>
|
||||
<span class="literal">public</span> <span class="literal">class</span> SelectionSortR {
|
||||
|
||||
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> <span class="ST1">selectionSortR</span>(<span class="literal">int</span>[] arr) {
|
||||
<span class="ST2">selectionSortR</span>(arr, <span class="number">0</span>, arr.<span class="ST3">length</span>);
|
||||
}
|
||||
|
||||
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> <span class="ST1">swap</span>(<span class="literal">int</span>[] arr, <span class="literal">int</span> i, <span class="literal">int</span> j) {
|
||||
<span class="literal">int</span> temp = arr[i];
|
||||
arr[i] = arr[j];
|
||||
arr[j] = temp;
|
||||
<span class="ST2">printArray</span>(arr);
|
||||
}
|
||||
|
||||
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> <span class="ST1">selectionSortR</span>(<span class="literal">int</span>[] arr, <span class="literal">int</span> i, <span class="literal">int</span> n) {
|
||||
<span class="comment">// Selection sort</span>
|
||||
<span class="literal">int</span> min = i;
|
||||
<span class="literal">for</span> (<span class="literal">int</span> j = i + <span class="number">1</span>; j < n; ++j) {
|
||||
<span class="literal">if</span> (arr[j] < arr[min]) {
|
||||
min = j;
|
||||
}
|
||||
}
|
||||
<span class="ST2">swap</span>(arr, min, i);
|
||||
<span class="literal">if</span> (i + <span class="number">1</span> < n) {
|
||||
<span class="ST2">selectionSortR</span>(arr, i + <span class="number">1</span>, n);
|
||||
}
|
||||
}
|
||||
|
||||
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> <span class="ST1">main</span>(String[] args) {
|
||||
<span class="literal">int</span>[] arr = {
|
||||
<span class="number">10</span>, <span class="number">1</span>, <span class="number">20</span>, <span class="number">3</span>
|
||||
};
|
||||
<span class="ST2">printArray</span>(arr);
|
||||
<span class="ST2">selectionSortR</span>(arr);
|
||||
|
||||
}
|
||||
|
||||
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> <span class="ST1">printArray</span>(<span class="literal">int</span>[] arr) {
|
||||
<span class="literal">for</span> (<span class="literal">int</span> i = <span class="number">0</span>; i < arr.<span class="ST3">length</span>; ++i) {
|
||||
System.<span class="ST4">out</span>.print(arr[i] + <span class="string">"</span> <span class="string">"</span>);
|
||||
}
|
||||
System.<span class="ST4">out</span>.println();
|
||||
}
|
||||
}
|
||||
|
||||
</pre></body>
|
||||
</html>
|
||||
@@ -0,0 +1,61 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
|
||||
<html>
|
||||
<head>
|
||||
<title>StringPermuatation.java</title>
|
||||
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
|
||||
<style type="text/css">
|
||||
<!--
|
||||
body {color: #a9b7c6; background-color: #2b2b2b; font-family: monospace; font-weight: bold}
|
||||
pre {color: #a9b7c6; background-color: #2b2b2b; font-family: monospace; font-weight: bold}
|
||||
table {color: #888888; background-color: #313335; font-family: monospace; font-weight: bold}
|
||||
.literal {color: #cc7832}
|
||||
.ST3 {font-family: monospace; font-weight: bold; font-style: italic}
|
||||
.ST0 {color: #287bde}
|
||||
.string {color: #6a8759}
|
||||
.number {color: #6897bb}
|
||||
.comment {color: #808080}
|
||||
.whitespace {color: #505050}
|
||||
.ST1 {color: #ffc66d; font-family: monospace; font-weight: bold; font-style: italic}
|
||||
.ST2 {color: #9876aa; font-family: monospace; font-weight: bold; font-style: italic}
|
||||
-->
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<table width="100%"><tr><td align="center">/home/chloe/ASDV-Java/Semester 3/Assignments/MP3_Recursion_ChloeFontenot/src/mp3_recursion_chloefontenot/StringPermuatation.java</td></tr></table>
|
||||
<pre>
|
||||
<span class="comment">/*</span>
|
||||
<span class="comment"> * Click </span><span class="ST0">nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt</span><span class="comment"> to change this license</span>
|
||||
<span class="comment"> * Click </span><span class="ST0">nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java</span><span class="comment"> to edit this template</span>
|
||||
<span class="comment"> */</span>
|
||||
<span class="literal">package</span> mp3_recursion_chloefontenot;
|
||||
|
||||
<span class="literal">import</span> java.util.Scanner;
|
||||
|
||||
<span class="comment">/**</span>
|
||||
<span class="comment"> *</span>
|
||||
<span class="comment"> * </span><span class="comment">@author</span> <span class="comment">chloe</span>
|
||||
<span class="comment">*/</span>
|
||||
<span class="literal">public</span> <span class="literal">class</span> StringPermuatation {
|
||||
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> <span class="ST1">main</span>(String[] args) {
|
||||
Scanner input = <span class="literal">new</span> Scanner(System.<span class="ST2">in</span>);
|
||||
System.<span class="ST2">out</span>.print(<span class="string">"</span><span class="string">Enter a string: </span><span class="string">"</span>);
|
||||
String s = input.nextLine();
|
||||
System.<span class="ST2">out</span>.println(<span class="string">"</span><span class="string">The permuatation for </span><span class="string">"</span> + s + <span class="string">"</span><span class="string"> is:</span><span class="string">"</span>);
|
||||
<span class="ST3">displayPermutation</span>(s);
|
||||
}
|
||||
|
||||
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> <span class="ST1">displayPermutation</span>(String s) {
|
||||
<span class="ST3">displayPermutation</span>(<span class="string">"</span><span class="string">"</span>, s);
|
||||
}
|
||||
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> <span class="ST1">displayPermutation</span>(String s1, String s2) {
|
||||
<span class="literal">if</span> (s2.equals(<span class="string">"</span><span class="string">"</span>)) {
|
||||
System.<span class="ST2">out</span>.println(s1);
|
||||
}
|
||||
<span class="literal">for</span> (<span class="literal">int</span> i = <span class="number">0</span>; i < s2.length(); ++i) {
|
||||
<span class="ST3">displayPermutation</span>(s1.concat(<span class="string">""</span> + s2.charAt(i)), s2.substring(<span class="number">0</span>, i).concat(s2.substring(i + <span class="number">1</span>)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
</pre></body>
|
||||
</html>
|
||||
73
Semester 3/Assignments/MP3_Recursion_ChloeFontenot/build.xml
Normal file
73
Semester 3/Assignments/MP3_Recursion_ChloeFontenot/build.xml
Normal file
@@ -0,0 +1,73 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!-- You may freely edit this file. See commented blocks below for -->
|
||||
<!-- some examples of how to customize the build. -->
|
||||
<!-- (If you delete it and reopen the project it will be recreated.) -->
|
||||
<!-- By default, only the Clean and Build commands use this build script. -->
|
||||
<!-- Commands such as Run, Debug, and Test only use this build script if -->
|
||||
<!-- the Compile on Save feature is turned off for the project. -->
|
||||
<!-- You can turn off the Compile on Save (or Deploy on Save) setting -->
|
||||
<!-- in the project's Project Properties dialog box.-->
|
||||
<project name="MP3_Recursion_ChloeFontenot" default="default" basedir=".">
|
||||
<description>Builds, tests, and runs the project MP3_Recursion_ChloeFontenot.</description>
|
||||
<import file="nbproject/build-impl.xml"/>
|
||||
<!--
|
||||
|
||||
There exist several targets which are by default empty and which can be
|
||||
used for execution of your tasks. These targets are usually executed
|
||||
before and after some main targets. They are:
|
||||
|
||||
-pre-init: called before initialization of project properties
|
||||
-post-init: called after initialization of project properties
|
||||
-pre-compile: called before javac compilation
|
||||
-post-compile: called after javac compilation
|
||||
-pre-compile-single: called before javac compilation of single file
|
||||
-post-compile-single: called after javac compilation of single file
|
||||
-pre-compile-test: called before javac compilation of JUnit tests
|
||||
-post-compile-test: called after javac compilation of JUnit tests
|
||||
-pre-compile-test-single: called before javac compilation of single JUnit test
|
||||
-post-compile-test-single: called after javac compilation of single JUunit test
|
||||
-pre-jar: called before JAR building
|
||||
-post-jar: called after JAR building
|
||||
-post-clean: called after cleaning build products
|
||||
|
||||
(Targets beginning with '-' are not intended to be called on their own.)
|
||||
|
||||
Example of inserting an obfuscator after compilation could look like this:
|
||||
|
||||
<target name="-post-compile">
|
||||
<obfuscate>
|
||||
<fileset dir="${build.classes.dir}"/>
|
||||
</obfuscate>
|
||||
</target>
|
||||
|
||||
For list of available properties check the imported
|
||||
nbproject/build-impl.xml file.
|
||||
|
||||
|
||||
Another way to customize the build is by overriding existing main targets.
|
||||
The targets of interest are:
|
||||
|
||||
-init-macrodef-javac: defines macro for javac compilation
|
||||
-init-macrodef-junit: defines macro for junit execution
|
||||
-init-macrodef-debug: defines macro for class debugging
|
||||
-init-macrodef-java: defines macro for class execution
|
||||
-do-jar: JAR building
|
||||
run: execution of project
|
||||
-javadoc-build: Javadoc generation
|
||||
test-report: JUnit report generation
|
||||
|
||||
An example of overriding the target for project execution could look like this:
|
||||
|
||||
<target name="run" depends="MP3_Recursion_ChloeFontenot-impl.jar">
|
||||
<exec dir="bin" executable="launcher.exe">
|
||||
<arg file="${dist.jar}"/>
|
||||
</exec>
|
||||
</target>
|
||||
|
||||
Notice that the overridden target depends on the jar target and not only on
|
||||
the compile target as the regular run target does. Again, for a list of available
|
||||
properties which you can use, check the target you are overriding in the
|
||||
nbproject/build-impl.xml file.
|
||||
|
||||
-->
|
||||
</project>
|
||||
@@ -0,0 +1,3 @@
|
||||
Manifest-Version: 1.0
|
||||
X-COMMENT: Main-Class will be added automatically by build
|
||||
|
||||
Binary file not shown.
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,8 @@
|
||||
build.xml.data.CRC32=44c2f96f
|
||||
build.xml.script.CRC32=0c59a678
|
||||
build.xml.stylesheet.CRC32=f85dc8f2@1.107.0.48
|
||||
# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
|
||||
# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
|
||||
nbproject/build-impl.xml.data.CRC32=44c2f96f
|
||||
nbproject/build-impl.xml.script.CRC32=47a26e92
|
||||
nbproject/build-impl.xml.stylesheet.CRC32=12e0a6c2@1.107.0.48
|
||||
@@ -0,0 +1,95 @@
|
||||
annotation.processing.enabled=true
|
||||
annotation.processing.enabled.in.editor=false
|
||||
annotation.processing.processor.options=
|
||||
annotation.processing.processors.list=
|
||||
annotation.processing.run.all.processors=true
|
||||
annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output
|
||||
build.classes.dir=${build.dir}/classes
|
||||
build.classes.excludes=**/*.java,**/*.form
|
||||
# This directory is removed when the project is cleaned:
|
||||
build.dir=build
|
||||
build.generated.dir=${build.dir}/generated
|
||||
build.generated.sources.dir=${build.dir}/generated-sources
|
||||
# Only compile against the classpath explicitly listed here:
|
||||
build.sysclasspath=ignore
|
||||
build.test.classes.dir=${build.dir}/test/classes
|
||||
build.test.results.dir=${build.dir}/test/results
|
||||
# Uncomment to specify the preferred debugger connection transport:
|
||||
#debug.transport=dt_socket
|
||||
debug.classpath=\
|
||||
${run.classpath}
|
||||
debug.modulepath=\
|
||||
${run.modulepath}
|
||||
debug.test.classpath=\
|
||||
${run.test.classpath}
|
||||
debug.test.modulepath=\
|
||||
${run.test.modulepath}
|
||||
# Files in build.classes.dir which should be excluded from distribution jar
|
||||
dist.archive.excludes=
|
||||
# This directory is removed when the project is cleaned:
|
||||
dist.dir=dist
|
||||
dist.jar=${dist.dir}/MP3_Recursion_ChloeFontenot.jar
|
||||
dist.javadoc.dir=${dist.dir}/javadoc
|
||||
dist.jlink.dir=${dist.dir}/jlink
|
||||
dist.jlink.output=${dist.jlink.dir}/MP3_Recursion_ChloeFontenot
|
||||
excludes=
|
||||
includes=**
|
||||
jar.compress=false
|
||||
javac.classpath=
|
||||
# Space-separated list of extra javac options
|
||||
javac.compilerargs=
|
||||
javac.deprecation=false
|
||||
javac.external.vm=true
|
||||
javac.modulepath=
|
||||
javac.processormodulepath=
|
||||
javac.processorpath=\
|
||||
${javac.classpath}
|
||||
javac.source=17
|
||||
javac.target=17
|
||||
javac.test.classpath=\
|
||||
${javac.classpath}:\
|
||||
${build.classes.dir}
|
||||
javac.test.modulepath=\
|
||||
${javac.modulepath}
|
||||
javac.test.processorpath=\
|
||||
${javac.test.classpath}
|
||||
javadoc.additionalparam=
|
||||
javadoc.author=false
|
||||
javadoc.encoding=${source.encoding}
|
||||
javadoc.html5=false
|
||||
javadoc.noindex=false
|
||||
javadoc.nonavbar=false
|
||||
javadoc.notree=false
|
||||
javadoc.private=false
|
||||
javadoc.splitindex=true
|
||||
javadoc.use=true
|
||||
javadoc.version=false
|
||||
javadoc.windowtitle=
|
||||
# The jlink additional root modules to resolve
|
||||
jlink.additionalmodules=
|
||||
# The jlink additional command line parameters
|
||||
jlink.additionalparam=
|
||||
jlink.launcher=true
|
||||
jlink.launcher.name=MP3_Recursion_ChloeFontenot
|
||||
main.class=mp3_recursion_chloefontenot.MP3_Recursion_ChloeFontenot
|
||||
manifest.file=manifest.mf
|
||||
meta.inf.dir=${src.dir}/META-INF
|
||||
mkdist.disabled=false
|
||||
platform.active=JDK_17
|
||||
run.classpath=\
|
||||
${javac.classpath}:\
|
||||
${build.classes.dir}
|
||||
# Space-separated list of JVM arguments used when running the project.
|
||||
# You may also define separate properties like run-sys-prop.name=value instead of -Dname=value.
|
||||
# To set system properties for unit tests define test-sys-prop.name=value:
|
||||
run.jvmargs=
|
||||
run.modulepath=\
|
||||
${javac.modulepath}
|
||||
run.test.classpath=\
|
||||
${javac.test.classpath}:\
|
||||
${build.test.classes.dir}
|
||||
run.test.modulepath=\
|
||||
${javac.test.modulepath}
|
||||
source.encoding=UTF-8
|
||||
src.dir=src
|
||||
test.src.dir=test
|
||||
@@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://www.netbeans.org/ns/project/1">
|
||||
<type>org.netbeans.modules.java.j2seproject</type>
|
||||
<configuration>
|
||||
<data xmlns="http://www.netbeans.org/ns/j2se-project/3">
|
||||
<name>MP3_Recursion_ChloeFontenot</name>
|
||||
<explicit-platform explicit-source-supported="true"/>
|
||||
<source-roots>
|
||||
<root id="src.dir"/>
|
||||
</source-roots>
|
||||
<test-roots>
|
||||
<root id="test.src.dir"/>
|
||||
</test-roots>
|
||||
</data>
|
||||
</configuration>
|
||||
</project>
|
||||
@@ -0,0 +1,39 @@
|
||||
package mp3_recursion_chloefontenot;
|
||||
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
/**
|
||||
*
|
||||
* @author chloe
|
||||
*/
|
||||
public class BinaryToDecimal {
|
||||
|
||||
public static void main(String[] args) {
|
||||
Scanner input = new Scanner(System.in);
|
||||
while (true) {
|
||||
System.out.print("Enter a binary number: ");
|
||||
String binary = input.nextLine();
|
||||
System.out.println(binary + " in decimal is " + binaryToDecimal(binary));
|
||||
}
|
||||
}
|
||||
|
||||
public static int binaryToDecimal(String binaryString) {
|
||||
return binaryToDecimal(binaryString, 0, binaryString.length(), 0);
|
||||
}
|
||||
|
||||
public static int binaryToDecimal(String binaryString, int low, int high, int value) {
|
||||
if (low == binaryString.length() - 1) {
|
||||
return value;
|
||||
}
|
||||
if (binaryString.charAt(low) == '1') {
|
||||
return binaryToDecimal(binaryString, ++low, --high, value += Math.pow(2, high));
|
||||
} else {
|
||||
return binaryToDecimal(binaryString, ++low, --high, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
package mp3_recursion_chloefontenot;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author chloe
|
||||
*/
|
||||
public class DecimalToBinary {
|
||||
|
||||
public static void main(String[] args) {
|
||||
Scanner input = new Scanner(System.in);
|
||||
while (true) {
|
||||
System.out.print("Enter a decimal integer: ");
|
||||
int decimal = input.nextInt();
|
||||
System.out.println(decimal + " is " + decimalToBinary(decimal) + " in binary.");
|
||||
}
|
||||
}
|
||||
|
||||
public static String decimalToBinary(int value) {
|
||||
return reverse(decimalToBinary(value, ""));
|
||||
}
|
||||
|
||||
public static String decimalToBinary(int value, String bin) {
|
||||
if (value == 0) {
|
||||
return bin += "";
|
||||
} else if (value > 0) {
|
||||
if (value % 2 == 1) {
|
||||
return decimalToBinary((int) Math.floor(value / 2), bin + "1");
|
||||
} else {
|
||||
return decimalToBinary((int) Math.floor(value / 2), bin + "0");
|
||||
}
|
||||
}
|
||||
|
||||
return "0 naht ssel si eulav";
|
||||
|
||||
}
|
||||
public static String reverse(String input) {
|
||||
String returnString = "";
|
||||
for (int i = input.length() - 1; 0 <= i; --i) {
|
||||
returnString += input.charAt(i);
|
||||
}
|
||||
return returnString;
|
||||
}
|
||||
|
||||
public static String decimalToBinaryIterative(int value) {
|
||||
String bin = "";
|
||||
while (value > 0) {
|
||||
if (value % 2 == 1)
|
||||
bin += "1";
|
||||
else
|
||||
bin += "0";
|
||||
|
||||
value /= 2;
|
||||
}
|
||||
return reverse(bin);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
*/
|
||||
|
||||
package mp3_recursion_chloefontenot;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author chloe
|
||||
*/
|
||||
public class MP3_Recursion_ChloeFontenot {
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println("Hello World!");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,367 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
package mp3_recursion_chloefontenot;
|
||||
|
||||
import java.util.Optional;
|
||||
import javafx.application.Application;
|
||||
import javafx.geometry.Pos;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.control.Alert;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.ButtonType;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.layout.BorderPane;
|
||||
import javafx.scene.layout.GridPane;
|
||||
import javafx.scene.layout.HBox;
|
||||
import javafx.scene.layout.StackPane;
|
||||
import javafx.scene.paint.Color;
|
||||
import javafx.scene.shape.Line;
|
||||
import javafx.scene.shape.Rectangle;
|
||||
import javafx.stage.Stage;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author chloe
|
||||
*/
|
||||
public class Maze extends Application {
|
||||
|
||||
double paneWidth = 600;
|
||||
double paneHeight = 600;
|
||||
|
||||
private Cell[][] board = new Cell[8][8];
|
||||
private Button btFindPath = new Button("Find Path Top Left to Bottom Right");
|
||||
private Button btFindPath2 = new Button("Find Path Top Right to Bottom Left");
|
||||
private Button btClearPath = new Button("Clear Path");
|
||||
private Label lblStatus = new Label();
|
||||
|
||||
@Override // Override the start method in the Application class
|
||||
public void start(Stage primaryStage) {
|
||||
GridPane gridPane = new GridPane();
|
||||
for (int i = 0; i < 8; i++) {
|
||||
for (int j = 0; j < 8; j++) {
|
||||
gridPane.add(board[i][j] = new Cell(), j, i);
|
||||
}
|
||||
}
|
||||
|
||||
HBox hBox = new HBox(5);
|
||||
hBox.setAlignment(Pos.CENTER);
|
||||
hBox.getChildren().addAll(btFindPath, btFindPath2, btClearPath);
|
||||
|
||||
BorderPane pane = new BorderPane();
|
||||
pane.setTop(lblStatus);
|
||||
BorderPane.setAlignment(lblStatus, Pos.CENTER);
|
||||
pane.setCenter(gridPane);
|
||||
pane.setBottom(hBox);
|
||||
|
||||
// Create a scene and place it in the stage
|
||||
Scene scene = new Scene(pane, paneWidth, paneHeight + 60);
|
||||
primaryStage.setTitle("Maze"); // Set the stage title
|
||||
primaryStage.setScene(scene); // Place the scene in the stage
|
||||
primaryStage.show(); // Display the stage
|
||||
|
||||
btFindPath.setOnAction(e -> findPath());
|
||||
btFindPath2.setOnAction(e -> findPath2());
|
||||
btClearPath.setOnAction(e -> clearPath());
|
||||
showSampleMessage();
|
||||
|
||||
}
|
||||
|
||||
public void showSampleMessage() {
|
||||
Alert a = new Alert(Alert.AlertType.CONFIRMATION);
|
||||
|
||||
a.setTitle("Maze Information");
|
||||
a.setHeaderText(" Put this message in its proper place. ");
|
||||
a.setContentText("This square cannot have an X");
|
||||
Optional<ButtonType> result = a.showAndWait();
|
||||
if (result.get() == ButtonType.OK) {
|
||||
System.out.println("OK ");
|
||||
} else if (result.get() == ButtonType.CANCEL) {
|
||||
System.out.println("CANCEL");
|
||||
}
|
||||
}
|
||||
public void clearCells() {
|
||||
for (int i = 0; i < 8; ++i) {
|
||||
for (int j = 0; j < 8; j++) {
|
||||
board[i][j].resetCell();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void findPath() {
|
||||
clearCells();
|
||||
if (findPath(0, 0)) {
|
||||
lblStatus.setText("path found");
|
||||
} else {
|
||||
lblStatus.setText("No path exists");
|
||||
}
|
||||
}
|
||||
|
||||
public void findPath2() {
|
||||
clearCells();
|
||||
if (findPath2(0, 7)) {
|
||||
lblStatus.setText("path found");
|
||||
} else {
|
||||
lblStatus.setText("No path exists");
|
||||
}
|
||||
}
|
||||
|
||||
public boolean findPath(int row, int col) {
|
||||
board[row][col].visit();
|
||||
|
||||
if ((col == 7) && (row == 7)) {
|
||||
board[row][col].selectCell();
|
||||
return true;
|
||||
}
|
||||
|
||||
if ((row > 0) && !board[row - 1][col].marked()
|
||||
&& !board[row - 1][col].blocked() && !board[row - 1][col].visited()) {
|
||||
block(row, col);
|
||||
|
||||
if (findPath(row - 1, col)) {
|
||||
board[row][col].selectCell();
|
||||
return true;
|
||||
}
|
||||
|
||||
unblock(row, col);
|
||||
}
|
||||
|
||||
if ((row < 7) && !board[row + 1][col].marked()
|
||||
&& !board[row + 1][col].blocked() && !board[row + 1][col].visited()) {
|
||||
block(row, col);
|
||||
|
||||
if (findPath(row + 1, col)) {
|
||||
board[row][col].selectCell();
|
||||
return true;
|
||||
}
|
||||
|
||||
unblock(row, col);
|
||||
}
|
||||
|
||||
if ((col > 0) && !board[row][col - 1].marked()
|
||||
&& !board[row][col - 1].blocked() && !board[row][col - 1].visited()) {
|
||||
block(row, col);
|
||||
if (findPath(row, col - 1)) {
|
||||
board[row][col].selectCell();
|
||||
return true;
|
||||
}
|
||||
|
||||
unblock(row, col);
|
||||
}
|
||||
|
||||
if ((col < 7) && !board[row][col + 1].marked()
|
||||
&& !board[row][col + 1].blocked() && !board[row][col + 1].visited()) {
|
||||
block(row, col);
|
||||
if (findPath(row, col + 1)) {
|
||||
board[row][col].selectCell();
|
||||
return true;
|
||||
}
|
||||
|
||||
unblock(row, col);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean findPath2(int row, int col) {
|
||||
board[row][col].visit();
|
||||
|
||||
if ((col == 0) && (row == 7)) {
|
||||
board[row][col].selectCellGreen();
|
||||
return true;
|
||||
}
|
||||
|
||||
if ((row > 0) && !board[row - 1][col].marked()
|
||||
&& !board[row - 1][col].blocked() && !board[row - 1][col].visited()) {
|
||||
block(row, col);
|
||||
|
||||
if (findPath2(row - 1, col)) {
|
||||
board[row][col].selectCellGreen();
|
||||
return true;
|
||||
}
|
||||
|
||||
unblock(row, col);
|
||||
}
|
||||
|
||||
if ((row < 7) && !board[row + 1][col].marked()
|
||||
&& !board[row + 1][col].blocked() && !board[row + 1][col].visited()) {
|
||||
block(row, col);
|
||||
|
||||
if (findPath2(row + 1, col)) {
|
||||
board[row][col].selectCellGreen();
|
||||
return true;
|
||||
}
|
||||
|
||||
unblock(row, col);
|
||||
}
|
||||
|
||||
if ((col > 0) && !board[row][col - 1].marked()
|
||||
&& !board[row][col - 1].blocked() && !board[row][col - 1].visited()) {
|
||||
block(row, col);
|
||||
if (findPath2(row, col - 1)) {
|
||||
board[row][col].selectCellGreen();
|
||||
return true;
|
||||
}
|
||||
|
||||
unblock(row, col);
|
||||
}
|
||||
|
||||
if ((col < 7) && !board[row][col + 1].marked()
|
||||
&& !board[row][col + 1].blocked() && !board[row][col + 1].visited()) {
|
||||
block(row, col);
|
||||
if (findPath2(row, col + 1)) {
|
||||
board[row][col].selectCellGreen();
|
||||
return true;
|
||||
}
|
||||
|
||||
unblock(row, col);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// Temporary block the neighbor to prevent neighboring path
|
||||
public void block(int row, int col) {
|
||||
if (row > 0) {
|
||||
board[row - 1][col].block();
|
||||
}
|
||||
|
||||
if (row < 7) {
|
||||
board[row + 1][col].block();
|
||||
}
|
||||
|
||||
if (col > 0) {
|
||||
board[row][col - 1].block();
|
||||
}
|
||||
|
||||
if (col < 7) {
|
||||
board[row][col + 1].block();
|
||||
}
|
||||
}
|
||||
|
||||
// Remove the temporary block
|
||||
public void unblock(int row, int col) {
|
||||
if (row > 0) {
|
||||
board[row - 1][col].unblock();
|
||||
}
|
||||
|
||||
if (row < 7) {
|
||||
board[row + 1][col].unblock();
|
||||
}
|
||||
|
||||
if (col > 0) {
|
||||
board[row][col - 1].unblock();
|
||||
}
|
||||
|
||||
if (col < 7) {
|
||||
board[row][col + 1].unblock();
|
||||
}
|
||||
}
|
||||
|
||||
public void clearPath() {
|
||||
for (int row = 0; row < board.length; row++) {
|
||||
for (int col = 0; col < board[row].length; col++) {
|
||||
board[row][col].deselectCell();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
launch(args);
|
||||
}
|
||||
|
||||
// Inner class
|
||||
class Cell extends StackPane {
|
||||
|
||||
private boolean marked = false;
|
||||
private boolean visited = false;
|
||||
private boolean blocked = false;
|
||||
|
||||
double width = paneWidth / 8;
|
||||
double height = paneHeight / 8;
|
||||
private Rectangle rectangle = new Rectangle(0, 0, width, height);
|
||||
|
||||
Line line1 = new Line(0, 0, width, height);
|
||||
Line line2 = new Line(width, 0, 0, height);
|
||||
|
||||
public Cell() {
|
||||
this.getChildren().add(rectangle);
|
||||
rectangle.setFill(Color.WHITE);
|
||||
rectangle.setStroke(Color.BLACK);
|
||||
|
||||
this.setOnMousePressed(e
|
||||
-> {
|
||||
marked = !marked;
|
||||
if (marked) {
|
||||
mark();
|
||||
} else {
|
||||
unmark();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void mark() {
|
||||
this.getChildren().addAll(line1, line2);
|
||||
}
|
||||
|
||||
public void unmark() {
|
||||
this.getChildren().remove(line1);
|
||||
this.getChildren().remove(line2);
|
||||
}
|
||||
|
||||
public boolean marked() {
|
||||
return marked;
|
||||
}
|
||||
|
||||
public void visit() {
|
||||
visited = true;
|
||||
}
|
||||
|
||||
public boolean visited() {
|
||||
return visited;
|
||||
}
|
||||
|
||||
public boolean blocked() {
|
||||
return blocked;
|
||||
}
|
||||
|
||||
public void block() {
|
||||
blocked = true;
|
||||
}
|
||||
|
||||
public void unblock() {
|
||||
blocked = false;
|
||||
}
|
||||
|
||||
public void selectCell() {
|
||||
if (rectangle.getFill().equals(Color.GREEN)) {
|
||||
rectangle.setFill(Color.YELLOW);
|
||||
} else {
|
||||
rectangle.setFill(Color.RED);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void selectCellGreen() {
|
||||
if (rectangle.getFill().equals(Color.RED)) {
|
||||
rectangle.setFill(Color.YELLOW);
|
||||
} else {
|
||||
rectangle.setFill(Color.GREEN);
|
||||
}
|
||||
}
|
||||
|
||||
public void deselectCell() {
|
||||
rectangle.setFill(Color.WHITE);
|
||||
blocked = false;
|
||||
visited = false;
|
||||
}
|
||||
|
||||
public void resetCell() {
|
||||
//rectangle.setFill(Color.WHITE);
|
||||
blocked = false;
|
||||
visited = false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
package edu.slcc.asdv.chloe.lab5.recursion2_chloefontenot;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author chloe
|
||||
*/
|
||||
public class SelectionSortR {
|
||||
|
||||
public static void selectionSortR(int[] arr) {
|
||||
selectionSortR(arr, 0, arr.length);
|
||||
}
|
||||
|
||||
public static void swap(int[] arr, int i, int j) {
|
||||
int temp = arr[i];
|
||||
arr[i] = arr[j];
|
||||
arr[j] = temp;
|
||||
printArray(arr);
|
||||
}
|
||||
|
||||
public static void selectionSortR(int[] arr, int i, int n) {
|
||||
// Selection sort
|
||||
int min = i;
|
||||
for (int j = i + 1; j < n; ++j) {
|
||||
if (arr[j] < arr[min]) {
|
||||
min = j;
|
||||
}
|
||||
}
|
||||
swap(arr, min, i);
|
||||
if (i + 1 < n) {
|
||||
selectionSortR(arr, i + 1, n);
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
int[] arr = {
|
||||
10, 1, 20, 3
|
||||
};
|
||||
printArray(arr);
|
||||
selectionSortR(arr);
|
||||
|
||||
}
|
||||
|
||||
public static void printArray(int[] arr) {
|
||||
for (int i = 0; i < arr.length; ++i) {
|
||||
System.out.print(arr[i] + " ");
|
||||
}
|
||||
System.out.println();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
package mp3_recursion_chloefontenot;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author chloe
|
||||
*/
|
||||
public class StringPermuatation {
|
||||
public static void main(String[] args) {
|
||||
Scanner input = new Scanner(System.in);
|
||||
System.out.print("Enter a string: ");
|
||||
String s = input.nextLine();
|
||||
System.out.println("The permuatation for " + s + " is:");
|
||||
displayPermutation(s);
|
||||
}
|
||||
|
||||
public static void displayPermutation(String s) {
|
||||
displayPermutation("", s);
|
||||
}
|
||||
public static void displayPermutation(String s1, String s2) {
|
||||
if (s2.equals("")) {
|
||||
System.out.println(s1);
|
||||
}
|
||||
for (int i = 0; i < s2.length(); ++i) {
|
||||
displayPermutation(s1.concat("" + s2.charAt(i)), s2.substring(0, i).concat(s2.substring(i + 1)));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user