added old projects
This commit is contained in:
+4
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"java.project.sourcePaths": ["src"],
|
||||
"java.project.outputPath": "bin"
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
## Getting Started
|
||||
|
||||
Welcome to the VS Code Java world. Here is a guideline to help you get started to write Java code in Visual Studio Code.
|
||||
|
||||
## Folder Structure
|
||||
|
||||
The workspace contains two folders by default, where:
|
||||
|
||||
- `src`: the folder to maintain sources
|
||||
- `lib`: the folder to maintain dependencies
|
||||
|
||||
Meanwhile, the compiled output files will be generated in the `bin` folder by default.
|
||||
|
||||
> If you want to customize the folder structure, open `.vscode/settings.json` and update the related settings there.
|
||||
|
||||
## Dependency Management
|
||||
|
||||
The `JAVA PROJECTS` view allows you to manage your dependencies. More details can be found [here](https://github.com/microsoft/vscode-java-dependency#manage-dependencies).
|
||||
Binary file not shown.
@@ -0,0 +1,16 @@
|
||||
public class App {
|
||||
public static void main(String[] args) throws Exception {
|
||||
int factOf4 = factorial(4);
|
||||
System.out.println(factOf4);
|
||||
|
||||
public static int factorial(int n) {
|
||||
int result;
|
||||
if (n > 1)
|
||||
result = n * factorial(n - 1);
|
||||
else
|
||||
result = 1;
|
||||
return result;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"java.project.sourcePaths": ["src"],
|
||||
"java.project.outputPath": "bin"
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
## Getting Started
|
||||
|
||||
Welcome to the VS Code Java world. Here is a guideline to help you get started to write Java code in Visual Studio Code.
|
||||
|
||||
## Folder Structure
|
||||
|
||||
The workspace contains two folders by default, where:
|
||||
|
||||
- `src`: the folder to maintain sources
|
||||
- `lib`: the folder to maintain dependencies
|
||||
|
||||
Meanwhile, the compiled output files will be generated in the `bin` folder by default.
|
||||
|
||||
> If you want to customize the folder structure, open `.vscode/settings.json` and update the related settings there.
|
||||
|
||||
## Dependency Management
|
||||
|
||||
The `JAVA PROJECTS` view allows you to manage your dependencies. More details can be found [here](https://github.com/microsoft/vscode-java-dependency#manage-dependencies).
|
||||
Binary file not shown.
@@ -0,0 +1,5 @@
|
||||
public class App {
|
||||
public static void main(String[] args) throws Exception {
|
||||
System.out.println("Hello, World!");
|
||||
}
|
||||
}
|
||||
Vendored
+4
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"java.project.sourcePaths": ["src"],
|
||||
"java.project.outputPath": "bin"
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
## Getting Started
|
||||
|
||||
Welcome to the VS Code Java world. Here is a guideline to help you get started to write Java code in Visual Studio Code.
|
||||
|
||||
## Folder Structure
|
||||
|
||||
The workspace contains two folders by default, where:
|
||||
|
||||
- `src`: the folder to maintain sources
|
||||
- `lib`: the folder to maintain dependencies
|
||||
|
||||
Meanwhile, the compiled output files will be generated in the `bin` folder by default.
|
||||
|
||||
> If you want to customize the folder structure, open `.vscode/settings.json` and update the related settings there.
|
||||
|
||||
## Dependency Management
|
||||
|
||||
The `JAVA PROJECTS` view allows you to manage your dependencies. More details can be found [here](https://github.com/microsoft/vscode-java-dependency#manage-dependencies).
|
||||
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,9 @@
|
||||
public class Tester {
|
||||
public static void main(String[] args) throws Exception {
|
||||
//System.out.println("Hello, World!");
|
||||
//System.out.println(Utilities.ceiling(-1.2));
|
||||
//System.out.println(Utilities.ceiling(3));
|
||||
//System.out.println(Utilities.ceiling(1.6));
|
||||
System.out.println(Utilities.stars(5));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
import java.math.BigInteger;
|
||||
|
||||
public class Utilities {
|
||||
|
||||
public static int abs(int num) {
|
||||
if (num < 0)
|
||||
num *= -1;
|
||||
return num;
|
||||
}
|
||||
|
||||
public static int ceiling(double num) {
|
||||
double x = num % 1;
|
||||
if (x < .5)
|
||||
num -= x;
|
||||
else if (x >= .5)
|
||||
num += x;
|
||||
return (int) num;
|
||||
}
|
||||
|
||||
public static BigInteger fact(int x) {
|
||||
BigInteger fact = new BigInteger("1");
|
||||
|
||||
for (int i = 2; i <= x; i++)
|
||||
fact = fact.multiply(BigInteger.valueOf(i));
|
||||
|
||||
return fact;
|
||||
}
|
||||
|
||||
public static String stars(int x) {
|
||||
String s = "";
|
||||
|
||||
for (int i = 1; i <= x; ++i) {
|
||||
for (int j = 1; j <= i; ++j) {
|
||||
s += "*";
|
||||
}
|
||||
s += " ";
|
||||
}
|
||||
return s;
|
||||
}
|
||||
}
|
||||
Vendored
+4
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"java.project.sourcePaths": ["src"],
|
||||
"java.project.outputPath": "bin"
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
## Getting Started
|
||||
|
||||
Welcome to the VS Code Java world. Here is a guideline to help you get started to write Java code in Visual Studio Code.
|
||||
|
||||
## Folder Structure
|
||||
|
||||
The workspace contains two folders by default, where:
|
||||
|
||||
- `src`: the folder to maintain sources
|
||||
- `lib`: the folder to maintain dependencies
|
||||
|
||||
Meanwhile, the compiled output files will be generated in the `bin` folder by default.
|
||||
|
||||
> If you want to customize the folder structure, open `.vscode/settings.json` and update the related settings there.
|
||||
|
||||
## Dependency Management
|
||||
|
||||
The `JAVA PROJECTS` view allows you to manage your dependencies. More details can be found [here](https://github.com/microsoft/vscode-java-dependency#manage-dependencies).
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,37 @@
|
||||
import java.util.Random;
|
||||
|
||||
public class Die {
|
||||
|
||||
private int _sides = 6;
|
||||
private int _roll;
|
||||
|
||||
|
||||
public int roll() {
|
||||
Random rnd = new Random();
|
||||
_roll = rnd.nextInt(_sides) + 1;
|
||||
return _roll;
|
||||
}
|
||||
|
||||
public int getRoll() {
|
||||
return _roll;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
switch (_roll) {
|
||||
case 1:
|
||||
return "One";
|
||||
case 2:
|
||||
return "Two";
|
||||
case 3:
|
||||
return "Three";
|
||||
case 4:
|
||||
return "Four";
|
||||
case 5:
|
||||
return "Five";
|
||||
case 6:
|
||||
return "Six";
|
||||
default:
|
||||
return "roll the dice";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
public class PairOfDice {
|
||||
Die die1 = new Die();
|
||||
Die die2 = new Die(3);
|
||||
int _sides;
|
||||
|
||||
public void PairOfDice() {
|
||||
_sides = 6;
|
||||
}
|
||||
|
||||
public void PairOfDice(int sides) {
|
||||
_sides = sides;
|
||||
}
|
||||
|
||||
public void roll() {
|
||||
die1.roll();
|
||||
die2.roll();
|
||||
}
|
||||
|
||||
public int getRoll() {
|
||||
return die1.getRoll() + die2.getRoll();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
public class Player {
|
||||
public static void main(String[] args) throws Exception {
|
||||
Die die1 = new Die();
|
||||
Die die2 = new Die();
|
||||
PairOfDice pod1 = new PairOfDice();
|
||||
PairOfDice pod2 = new PairOfDice();
|
||||
|
||||
|
||||
die1.roll();
|
||||
System.out.println("1 Die: " + die1.toString());
|
||||
|
||||
die2.roll();
|
||||
System.out.println("1 Die: " + die2.toString());
|
||||
|
||||
pod1.roll();
|
||||
pod2.roll();
|
||||
System.out.println("2 Dice: " + pod1.getRoll());
|
||||
System.out.println("2 Dice: " + pod2.getRoll());
|
||||
}
|
||||
}
|
||||
Vendored
+4
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"java.project.sourcePaths": ["src"],
|
||||
"java.project.outputPath": "bin"
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
## Getting Started
|
||||
|
||||
Welcome to the VS Code Java world. Here is a guideline to help you get started to write Java code in Visual Studio Code.
|
||||
|
||||
## Folder Structure
|
||||
|
||||
The workspace contains two folders by default, where:
|
||||
|
||||
- `src`: the folder to maintain sources
|
||||
- `lib`: the folder to maintain dependencies
|
||||
|
||||
Meanwhile, the compiled output files will be generated in the `bin` folder by default.
|
||||
|
||||
> If you want to customize the folder structure, open `.vscode/settings.json` and update the related settings there.
|
||||
|
||||
## Dependency Management
|
||||
|
||||
The `JAVA PROJECTS` view allows you to manage your dependencies. More details can be found [here](https://github.com/microsoft/vscode-java-dependency#manage-dependencies).
|
||||
Binary file not shown.
@@ -0,0 +1,120 @@
|
||||
import java.util.Scanner;
|
||||
|
||||
public class RomanNumeralCalculator {
|
||||
public static void main(String[] args) {
|
||||
Scanner input = new Scanner(System.in);
|
||||
int num;
|
||||
|
||||
do {
|
||||
System.out.println("Please enter an integer from 1 to 5999. Enter a negative number or 0 to exit."); //can also exit on 0
|
||||
System.out.print("-> ");
|
||||
num = input.nextInt();
|
||||
|
||||
if (num <= 0)
|
||||
System.exit(0);
|
||||
|
||||
if (num < 6000) {
|
||||
String roman = "";
|
||||
|
||||
while (num >= 1000) {
|
||||
roman += "M";
|
||||
num -= 1000;
|
||||
}
|
||||
|
||||
switch (num / 100) { //Needed to switch from modulus division
|
||||
case 0:
|
||||
case 1:
|
||||
case 2:
|
||||
case 3:
|
||||
break;
|
||||
case 4:
|
||||
roman += "CD";
|
||||
num -= 400;
|
||||
break;
|
||||
case 5:
|
||||
case 6:
|
||||
case 7:
|
||||
case 8:
|
||||
roman += "D";
|
||||
num -= 500;
|
||||
break;
|
||||
case 9:
|
||||
roman += "CM";
|
||||
num -= 900;
|
||||
break;
|
||||
default:
|
||||
System.err.println("There is a problem with the hundreds place."); // not tens place
|
||||
}
|
||||
|
||||
while (num >= 100) {
|
||||
roman += "C";
|
||||
num -= 100;
|
||||
}
|
||||
|
||||
int x = num / 10 % 10;
|
||||
switch (num / 10 % 10) {
|
||||
case 0:
|
||||
case 1:
|
||||
case 2:
|
||||
case 3:
|
||||
break;
|
||||
case 4:
|
||||
roman += "XL";
|
||||
num -= 40;
|
||||
break;
|
||||
case 5:
|
||||
case 6:
|
||||
case 7:
|
||||
case 8:
|
||||
roman += "L";
|
||||
num -= 50;
|
||||
break;
|
||||
case 9:
|
||||
roman += "XC"; //X & C were flipped
|
||||
num -= 90;
|
||||
break;
|
||||
default:
|
||||
System.err.println("There is a problem with the tens place.");
|
||||
}
|
||||
|
||||
while (num >= 10) {
|
||||
roman += "X";
|
||||
num -= 10;
|
||||
}
|
||||
|
||||
switch (num) {
|
||||
case 0:
|
||||
case 1:
|
||||
case 2:
|
||||
case 3:
|
||||
break;
|
||||
case 4:
|
||||
roman += "IV";
|
||||
num -= 4;
|
||||
break;
|
||||
case 5:
|
||||
case 6:
|
||||
case 7:
|
||||
case 8:
|
||||
roman += "V"; //Needed capital 'V'
|
||||
num -= 5;
|
||||
break;
|
||||
case 9:
|
||||
roman += "IX";
|
||||
num -= 9;
|
||||
break;
|
||||
|
||||
default:
|
||||
System.err.println("There is a problem with the units place.");
|
||||
}
|
||||
|
||||
while (num > 0) {
|
||||
roman += "I";
|
||||
num--;
|
||||
}
|
||||
|
||||
System.out.println(roman);
|
||||
}
|
||||
} while (true); // Would not loop < was facing the wrong way
|
||||
}
|
||||
}
|
||||
Vendored
+4
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"java.project.sourcePaths": ["src"],
|
||||
"java.project.outputPath": "bin"
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
## Getting Started
|
||||
|
||||
Welcome to the VS Code Java world. Here is a guideline to help you get started to write Java code in Visual Studio Code.
|
||||
|
||||
## Folder Structure
|
||||
|
||||
The workspace contains two folders by default, where:
|
||||
|
||||
- `src`: the folder to maintain sources
|
||||
- `lib`: the folder to maintain dependencies
|
||||
|
||||
Meanwhile, the compiled output files will be generated in the `bin` folder by default.
|
||||
|
||||
> If you want to customize the folder structure, open `.vscode/settings.json` and update the related settings there.
|
||||
|
||||
## Dependency Management
|
||||
|
||||
The `JAVA PROJECTS` view allows you to manage your dependencies. More details can be found [here](https://github.com/microsoft/vscode-java-dependency#manage-dependencies).
|
||||
Binary file not shown.
@@ -0,0 +1,44 @@
|
||||
import java.util.Scanner;
|
||||
import java.util.function.DoubleBinaryOperator;
|
||||
|
||||
/*
|
||||
Write a Java program that repeatedly accepts two integers from the keyboard and prints the quotient to
|
||||
the console. Your code must adhere to the follow specifications:
|
||||
- The user must enter 0 for both the numerator and denominator to exit the program.
|
||||
- You must read the input values using the Scanner’s next() method and then convert to a primitive integer using Integer.parseInt.
|
||||
In case of an exception (when converting the string to an integer), the program must (1) print the corresponding stack trace (printStackTrace)
|
||||
and (2) reset the Scanner object.
|
||||
- The program must catch division by zero exceptions and print a corresponding message in case
|
||||
one occurs. The error should not be printed if the user intends to exit.
|
||||
*/
|
||||
|
||||
public class App {
|
||||
public static void main(String[] args) throws Exception {
|
||||
Scanner scn = new Scanner(System.in);
|
||||
int numerator = 1;
|
||||
int denominator = 1;
|
||||
|
||||
while (numerator != 0 || denominator != 0)
|
||||
{
|
||||
try {
|
||||
System.out.print("Enter two integers. (Enter zero in both spots to exit) \nNumerator: ");
|
||||
numerator = Integer.parseInt(scn.next());
|
||||
System.out.print("Denominator: ");
|
||||
denominator = Integer.parseInt(scn.next());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
if (numerator != 0 || denominator != 0)
|
||||
try {
|
||||
int answer = numerator/denominator;
|
||||
System.out.println("The answer is: " + answer);
|
||||
} catch (ArithmeticException e) {
|
||||
System.out.println("You shouldn't divide a number by zero");
|
||||
}
|
||||
else
|
||||
System.out.println("Exiting");
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Vendored
+4
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"java.project.sourcePaths": ["src"],
|
||||
"java.project.outputPath": "bin"
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
## Getting Started
|
||||
|
||||
Welcome to the VS Code Java world. Here is a guideline to help you get started to write Java code in Visual Studio Code.
|
||||
|
||||
## Folder Structure
|
||||
|
||||
The workspace contains two folders by default, where:
|
||||
|
||||
- `src`: the folder to maintain sources
|
||||
- `lib`: the folder to maintain dependencies
|
||||
|
||||
Meanwhile, the compiled output files will be generated in the `bin` folder by default.
|
||||
|
||||
> If you want to customize the folder structure, open `.vscode/settings.json` and update the related settings there.
|
||||
|
||||
## Dependency Management
|
||||
|
||||
The `JAVA PROJECTS` view allows you to manage your dependencies. More details can be found [here](https://github.com/microsoft/vscode-java-dependency#manage-dependencies).
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,6 @@
|
||||
public class App {
|
||||
public static void main(String[] args) {
|
||||
QuadraticSolver quadSolve = new QuadraticSolver(1, 2, 3);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
|
||||
|
||||
public class NonRealException extends QuadraticException
|
||||
{
|
||||
public NonRealException(String msg)
|
||||
{
|
||||
super(msg);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
|
||||
|
||||
public class QuadraticException extends ArithmeticException
|
||||
{
|
||||
public QuadraticException(String msg)
|
||||
{
|
||||
super(msg);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
public class QuadraticSolver {
|
||||
|
||||
private int _a;
|
||||
private int _b;
|
||||
private int _c;
|
||||
|
||||
public QuadraticSolver() {
|
||||
_a = 1;
|
||||
_b = 1;
|
||||
_c = 1;
|
||||
}
|
||||
|
||||
public QuadraticSolver(int a, int b, int c) throws QuadraticException
|
||||
{
|
||||
if (a == 0)
|
||||
throw new QuadraticException("Not a real quadratic");
|
||||
|
||||
_a = a;
|
||||
_b = b;
|
||||
_c = c;
|
||||
|
||||
}
|
||||
|
||||
public double discriminant() {
|
||||
return _b*_b - 4 * _a * _c;
|
||||
}
|
||||
|
||||
public boolean realSolution() {
|
||||
return discriminant() >= 0 ;
|
||||
}
|
||||
|
||||
public double firstRoot() throws NonRealException {
|
||||
if (!realSolution())
|
||||
throw new NonRealException("no real solution");
|
||||
return (-1 * _b + discriminant()) / (2 * _a);
|
||||
}
|
||||
|
||||
public double secondRoot() throws NonRealException{
|
||||
if (!realSolution())
|
||||
throw new NonRealException("no real solution");
|
||||
else
|
||||
return (-1 * _b - discriminant()) / (2 * _a);
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "f(x) = " + _a + "x^2 + " + _b + "x + " + _c;
|
||||
}
|
||||
}
|
||||
Vendored
+4
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"java.project.sourcePaths": ["src"],
|
||||
"java.project.outputPath": "bin"
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
## Getting Started
|
||||
|
||||
Welcome to the VS Code Java world. Here is a guideline to help you get started to write Java code in Visual Studio Code.
|
||||
|
||||
## Folder Structure
|
||||
|
||||
The workspace contains two folders by default, where:
|
||||
|
||||
- `src`: the folder to maintain sources
|
||||
- `lib`: the folder to maintain dependencies
|
||||
|
||||
Meanwhile, the compiled output files will be generated in the `bin` folder by default.
|
||||
|
||||
> If you want to customize the folder structure, open `.vscode/settings.json` and update the related settings there.
|
||||
|
||||
## Dependency Management
|
||||
|
||||
The `JAVA PROJECTS` view allows you to manage your dependencies. More details can be found [here](https://github.com/microsoft/vscode-java-dependency#manage-dependencies).
|
||||
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,48 @@
|
||||
import java.lang.reflect.Array;
|
||||
import java.util.Random;
|
||||
|
||||
public class Aray {
|
||||
//Returns the indexof the minimum value in the array.
|
||||
public static int findMin(int[] a) {
|
||||
int min = 101;
|
||||
int length = a.length;
|
||||
int index = 0;
|
||||
for (int i = 0; i < length; ++i) {
|
||||
if (a[i] < min)
|
||||
min = a[i];
|
||||
index = i;
|
||||
}
|
||||
return index;
|
||||
}
|
||||
|
||||
//Returns the indexof the maximum value in the array.
|
||||
public static int findMax(int[] a) {
|
||||
int max = 0;
|
||||
int length = a.length;
|
||||
int index = 0;
|
||||
for (int i = 0; i < length; ++i) {
|
||||
if (a[i] > max)
|
||||
max = a[i];
|
||||
index = i;
|
||||
}
|
||||
return index;
|
||||
}
|
||||
|
||||
//Returns the statistical mean of the values in the array.
|
||||
public static double mean (int[] a) {
|
||||
int sum = 0;
|
||||
int length = a.length;
|
||||
for (int i = 0; i < length; ++i) {
|
||||
sum += a[i];
|
||||
}
|
||||
return sum / length;
|
||||
}
|
||||
|
||||
//Populates the array with a series of integer values between 0 and 100 (inclusive) that are randomly generated.
|
||||
public static void populate(int[] a) {
|
||||
Random rnd = new Random();
|
||||
for (int i = 0; i < 100; ++i) {
|
||||
a[i] = rnd.nextInt(0, 101);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
public class Tester {
|
||||
public static void main(String[] args) throws Exception {
|
||||
//data_type name = new data_type ;
|
||||
int[] a = new int[100] ;
|
||||
Aray.populate(a);
|
||||
System.out.println("Max: " + Aray.findMax(a));
|
||||
System.out.println("Min: " + Aray.findMin(a));
|
||||
System.out.println("Mean: " + Aray.mean(a));
|
||||
}
|
||||
}
|
||||
Vendored
+4
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"java.project.sourcePaths": ["src"],
|
||||
"java.project.outputPath": "bin"
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
## Getting Started
|
||||
|
||||
Welcome to the VS Code Java world. Here is a guideline to help you get started to write Java code in Visual Studio Code.
|
||||
|
||||
## Folder Structure
|
||||
|
||||
The workspace contains two folders by default, where:
|
||||
|
||||
- `src`: the folder to maintain sources
|
||||
- `lib`: the folder to maintain dependencies
|
||||
|
||||
Meanwhile, the compiled output files will be generated in the `bin` folder by default.
|
||||
|
||||
> If you want to customize the folder structure, open `.vscode/settings.json` and update the related settings there.
|
||||
|
||||
## Dependency Management
|
||||
|
||||
The `JAVA PROJECTS` view allows you to manage your dependencies. More details can be found [here](https://github.com/microsoft/vscode-java-dependency#manage-dependencies).
|
||||
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,9 @@
|
||||
public class App {
|
||||
public static void main(String[] args) throws Exception {
|
||||
int arr[][] = {{1, 5, 9,},
|
||||
{8, 3, 4 },
|
||||
{6, 7, 2 }};
|
||||
Magic matrix = new Magic(arr);
|
||||
System.out.println(matrix.magic());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
public class Magic {
|
||||
int _matrix[][] = { {1, 5, 9 },
|
||||
{8, 3, 4 },
|
||||
{6, 7, 2 }};;
|
||||
|
||||
public Magic(int matrix[][]) {
|
||||
if(matrix.length != matrix[0].length) {
|
||||
throw new IllegalArgumentException("Not Square");
|
||||
} else {
|
||||
for (int i = 0; i < matrix.length; i++) {
|
||||
for (int j = 0; j < matrix[0].length; j++) {
|
||||
_matrix[i][j] = matrix[i][j];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean rowSemiMagic() {
|
||||
int rowSums[] = new int[_matrix.length];
|
||||
int sumRow;
|
||||
for (int i = 0; i < _matrix.length; i++) {
|
||||
sumRow = 0;
|
||||
for (int j = 0; j <_matrix[0].length; j++) {
|
||||
sumRow += _matrix[i][j];
|
||||
rowSums[i] = sumRow;
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < rowSums.length; i++) {
|
||||
if (rowSums[0] != rowSums[i]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean columnSemiMagic() {
|
||||
int columnSums[] = new int[_matrix[0].length];
|
||||
int sumColumn;
|
||||
for (int i = 0; i < _matrix.length; i++) {
|
||||
sumColumn = 0;
|
||||
for (int j = 0; j <_matrix[0].length; j++) {
|
||||
sumColumn += _matrix[i][j];
|
||||
columnSums[i] = sumColumn;
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < columnSums.length; i++) {
|
||||
if (columnSums[0] != columnSums[i]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean magic() {
|
||||
if (rowSemiMagic() && columnSemiMagic()) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
Vendored
+4
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"java.project.sourcePaths": ["src"],
|
||||
"java.project.outputPath": "bin"
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
## Getting Started
|
||||
|
||||
Welcome to the VS Code Java world. Here is a guideline to help you get started to write Java code in Visual Studio Code.
|
||||
|
||||
## Folder Structure
|
||||
|
||||
The workspace contains two folders by default, where:
|
||||
|
||||
- `src`: the folder to maintain sources
|
||||
- `lib`: the folder to maintain dependencies
|
||||
|
||||
Meanwhile, the compiled output files will be generated in the `bin` folder by default.
|
||||
|
||||
> If you want to customize the folder structure, open `.vscode/settings.json` and update the related settings there.
|
||||
|
||||
## Dependency Management
|
||||
|
||||
The `JAVA PROJECTS` view allows you to manage your dependencies. More details can be found [here](https://github.com/microsoft/vscode-java-dependency#manage-dependencies).
|
||||
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,57 @@
|
||||
public class Card
|
||||
{
|
||||
public enum SuitT
|
||||
{
|
||||
CLUBS ("Clubs"), DIAMONDS("Diamonds"), HEARTS("Hearts"), SPADES("Spades");
|
||||
|
||||
private final String description;
|
||||
|
||||
private SuitT(String value) { description = value; }
|
||||
|
||||
public String getDescription() { return description; }
|
||||
}
|
||||
|
||||
public enum FaceT
|
||||
{
|
||||
ACE ("Ace", 1),
|
||||
TWO ("Two", 2),
|
||||
THREE ("Three", 3),
|
||||
FOUR ("Four", 4),
|
||||
FIVE ("Five", 5),
|
||||
SIX ("Six", 6),
|
||||
SEVEN ("Seven", 7),
|
||||
EIGHT ("Eight", 8),
|
||||
NINE ("Nine", 9),
|
||||
TEN ("Ten", 10),
|
||||
JACK ("Jack", 11),
|
||||
QUEEN ("Queen", 12),
|
||||
KING ("King", 13);
|
||||
|
||||
private final String description;
|
||||
private final int value;
|
||||
|
||||
private FaceT(String desc, int val)
|
||||
{
|
||||
description = desc;
|
||||
value = val;
|
||||
}
|
||||
|
||||
public String getDescription() { return description; }
|
||||
public int getValue() { return value; }
|
||||
}
|
||||
|
||||
private SuitT suit;
|
||||
private FaceT faceValue;
|
||||
|
||||
|
||||
public Card(SuitT suit, FaceT face)
|
||||
{
|
||||
this.suit = suit;
|
||||
this.faceValue = face;
|
||||
}
|
||||
|
||||
public String toString()
|
||||
{
|
||||
return faceValue.getDescription() + " of " + this.suit.getDescription();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
import java.util.Random;
|
||||
|
||||
public class Deck
|
||||
{
|
||||
private final int DECK_SIZE = 52;
|
||||
private Card[] _deck;
|
||||
|
||||
// Top of the deck is index 0; bottom is index 51.
|
||||
private int currentTop;
|
||||
|
||||
//
|
||||
// Allocates a default deck of 52 cards with four suits.
|
||||
//
|
||||
public Deck()
|
||||
{
|
||||
_deck = new Card[DECK_SIZE];
|
||||
currentTop = 0;
|
||||
|
||||
int index = 0;
|
||||
for (Card.SuitT suit : Card.SuitT.values())
|
||||
{
|
||||
for (Card.FaceT face : Card.FaceT.values())
|
||||
{
|
||||
_deck[index++] = new Card(suit, face);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// May assume a full deck.
|
||||
//
|
||||
// Shuffles by switching two random cards in the deck many times.
|
||||
//
|
||||
public void shuffle()
|
||||
{
|
||||
Random rng = new Random();
|
||||
|
||||
final int ITERATIONS = 1000;
|
||||
for (int count = 0; count < ITERATIONS; count++) {
|
||||
int firstCard = rng.nextInt(52);
|
||||
int secondCard = rng.nextInt(52);
|
||||
Card tempCard = _deck[firstCard];
|
||||
_deck[firstCard] = _deck[secondCard];
|
||||
_deck[secondCard] = tempCard;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Computes the number of cards that remain in the deck:
|
||||
// deck count minus the current top index
|
||||
//
|
||||
public int cardsRemaining()
|
||||
{
|
||||
return DECK_SIZE - currentTop;
|
||||
}
|
||||
|
||||
//
|
||||
// Returns the top card from the deck.
|
||||
//
|
||||
public Card deal() throws DeckException
|
||||
{
|
||||
if(currentTop >= DECK_SIZE) {
|
||||
throw new DeckException("Empty Deck");
|
||||
}
|
||||
currentTop++;
|
||||
return _deck[currentTop];
|
||||
}
|
||||
|
||||
//
|
||||
// Returns the top card from the deck.
|
||||
//
|
||||
public Card[] deal(int numCards) throws DeckException
|
||||
{
|
||||
Card[] dealCard = new Card[numCards];
|
||||
for (int i = 0; i < numCards; i++) {
|
||||
Card card = deal();
|
||||
dealCard[i] = card;
|
||||
}
|
||||
return dealCard;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Builds and returns a meaningful representation of the cards that
|
||||
// remain in the deck.
|
||||
//
|
||||
public String toString()
|
||||
{
|
||||
String retStr = "";
|
||||
|
||||
for (int i = currentTop; i < DECK_SIZE; i++) {
|
||||
retStr += _deck[i].toString() + ", ";
|
||||
}
|
||||
|
||||
return retStr + "\n";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
|
||||
|
||||
public class DeckException extends Exception
|
||||
{
|
||||
public DeckException(String msg)
|
||||
{
|
||||
super(msg);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
|
||||
public class Lab18
|
||||
{
|
||||
public static void main(String[] args)
|
||||
{
|
||||
Deck deck = new Deck();
|
||||
|
||||
System.out.println("Original Deck:");
|
||||
System.out.println(deck);
|
||||
deck.shuffle();
|
||||
|
||||
System.out.println("Shuffled Deck:");
|
||||
System.out.println(deck);
|
||||
|
||||
Card[] hand = null;
|
||||
try
|
||||
{
|
||||
hand = deck.deal(50);
|
||||
}
|
||||
catch(DeckException e)
|
||||
{
|
||||
}
|
||||
|
||||
System.out.println("Cards in the hand: ");
|
||||
for (Card card : hand)
|
||||
{
|
||||
System.out.println(card);
|
||||
}
|
||||
|
||||
System.out.println();
|
||||
System.out.println("Cards remaining in the deck: ");
|
||||
System.out.println(deck);
|
||||
}
|
||||
|
||||
}
|
||||
Vendored
+4
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"java.project.sourcePaths": ["src"],
|
||||
"java.project.outputPath": "bin"
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
## Getting Started
|
||||
|
||||
Welcome to the VS Code Java world. Here is a guideline to help you get started to write Java code in Visual Studio Code.
|
||||
|
||||
## Folder Structure
|
||||
|
||||
The workspace contains two folders by default, where:
|
||||
|
||||
- `src`: the folder to maintain sources
|
||||
- `lib`: the folder to maintain dependencies
|
||||
|
||||
Meanwhile, the compiled output files will be generated in the `bin` folder by default.
|
||||
|
||||
> If you want to customize the folder structure, open `.vscode/settings.json` and update the related settings there.
|
||||
|
||||
## Dependency Management
|
||||
|
||||
The `JAVA PROJECTS` view allows you to manage your dependencies. More details can be found [here](https://github.com/microsoft/vscode-java-dependency#manage-dependencies).
|
||||
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,53 @@
|
||||
import javax.management.RuntimeErrorException;
|
||||
|
||||
public class Animal
|
||||
{
|
||||
//TODO: private member variables
|
||||
private String _soundMade;
|
||||
private boolean _hasLegs;
|
||||
private boolean _hasWings;
|
||||
private boolean _hasGills;
|
||||
|
||||
public Animal( String soundMade, boolean hasLegs, boolean hasWings, boolean hasGills )
|
||||
{
|
||||
_soundMade = soundMade;
|
||||
_hasLegs = hasLegs;
|
||||
_hasWings = hasWings;
|
||||
_hasGills = hasGills;
|
||||
}
|
||||
|
||||
public String getSoundMade()
|
||||
{
|
||||
return _soundMade;
|
||||
}
|
||||
|
||||
public boolean hasLegs()
|
||||
{
|
||||
return _hasLegs;
|
||||
}
|
||||
|
||||
public boolean hasWings()
|
||||
{
|
||||
return _hasWings;
|
||||
}
|
||||
|
||||
public boolean hasGills()
|
||||
{
|
||||
return _hasGills;
|
||||
}
|
||||
|
||||
public int numberOfLegs()
|
||||
{
|
||||
throw new RuntimeException("Unknown # of Legs");
|
||||
}
|
||||
|
||||
public int numberOfWings()
|
||||
{
|
||||
throw new RuntimeException("Unknown # of Wings");
|
||||
}
|
||||
|
||||
public void breatheUnderwater()
|
||||
{
|
||||
throw new RuntimeException("Unknown if animal can breathe underwater.");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
public class Bird extends Animal {
|
||||
public Bird() {
|
||||
super("tweet", true, true, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void breatheUnderwater() {
|
||||
throw new RuntimeException( "Birds can't breathe under water!");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int numberOfLegs() {
|
||||
return 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int numberOfWings() {
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
public class Cat extends Animal {
|
||||
public Cat() {
|
||||
super("meow", true, false, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void breatheUnderwater() {
|
||||
throw new RuntimeException( "Cats can't breathe under water!");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int numberOfLegs() {
|
||||
return 4;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int numberOfWings() {
|
||||
throw new RuntimeException("Cats don't have wings!");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
public class Dog extends Animal {
|
||||
|
||||
public Dog() {
|
||||
super("woof", true, false, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void breatheUnderwater() {
|
||||
throw new RuntimeException( "Dogs can't breathe under water!");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int numberOfLegs() {
|
||||
return 4;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int numberOfWings() {
|
||||
throw new RuntimeException("Dogs don't have wings!");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
public class Fish extends Animal{
|
||||
public Fish() {
|
||||
super("blub", false, false, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void breatheUnderwater() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int numberOfLegs() {
|
||||
throw new RuntimeException("Fish don't have legs!");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int numberOfWings() {
|
||||
throw new RuntimeException("Fish don't have wings!");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
public class Fox extends Animal {
|
||||
public Fox() {
|
||||
super("Ring-ding-ding-dingeringeding", true, false, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void breatheUnderwater() {
|
||||
throw new RuntimeException( "Foxes can't breathe under water!");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int numberOfLegs() {
|
||||
return 4;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int numberOfWings() {
|
||||
throw new RuntimeException("Foxes don't have wings!");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,186 @@
|
||||
public class Tester
|
||||
{
|
||||
public static void main( String[] args )
|
||||
{
|
||||
Dog d = new Dog () ;
|
||||
Cat c = new Cat () ;
|
||||
Bird b = new Bird() ;
|
||||
Fish f = new Fish() ;
|
||||
Fox x = new Fox () ;
|
||||
|
||||
//Dog
|
||||
if( d.hasLegs() )
|
||||
{
|
||||
System.out.println( "Dogs have " + d.numberOfLegs() + " legs." ) ;
|
||||
}
|
||||
|
||||
if( d.hasWings() )
|
||||
{
|
||||
System.out.println( "Dogs have " + d.numberOfWings() + " wings." ) ;
|
||||
}
|
||||
|
||||
if( d.hasGills() )
|
||||
{
|
||||
d.breatheUnderwater() ;
|
||||
System.out.println( "Dogs can breathe under water." ) ;
|
||||
}
|
||||
|
||||
//Cat
|
||||
if( c.hasLegs() )
|
||||
{
|
||||
System.out.println( "Cats have " + c.numberOfLegs() + " legs." ) ;
|
||||
}
|
||||
|
||||
if( d.hasWings() )
|
||||
{
|
||||
System.out.println( "Cats have " + c.numberOfWings() + " wings." ) ;
|
||||
}
|
||||
|
||||
if( c.hasGills() )
|
||||
{
|
||||
c.breatheUnderwater() ;
|
||||
System.out.println( "Cats can breathe under water." ) ;
|
||||
}
|
||||
|
||||
//Bird
|
||||
if( b.hasLegs() )
|
||||
{
|
||||
System.out.println( "Birds have " + b.numberOfLegs() + " legs." ) ;
|
||||
}
|
||||
|
||||
if( b.hasWings() )
|
||||
{
|
||||
System.out.println( "Birds have " + b.numberOfWings() + " wings." ) ;
|
||||
}
|
||||
|
||||
if( b.hasGills() )
|
||||
{
|
||||
b.breatheUnderwater() ;
|
||||
System.out.println( "Birds can breathe under water." ) ;
|
||||
}
|
||||
|
||||
//Fish
|
||||
if( f.hasLegs() )
|
||||
{
|
||||
System.out.println( "Fish have " + f.numberOfLegs() + " legs." ) ;
|
||||
}
|
||||
|
||||
if( f.hasWings() )
|
||||
{
|
||||
System.out.println( "Fish have " + f.numberOfWings() + " wings." ) ;
|
||||
}
|
||||
|
||||
if( f.hasGills() )
|
||||
{
|
||||
f.breatheUnderwater() ;
|
||||
System.out.println( "Fish can breathe under water." ) ;
|
||||
}
|
||||
|
||||
//Fox
|
||||
if( x.hasLegs() )
|
||||
{
|
||||
System.out.println( "Foxes have " + x.numberOfLegs() + " legs." ) ;
|
||||
}
|
||||
|
||||
if( x.hasWings() )
|
||||
{
|
||||
System.out.println( "Foxes have " + x.numberOfWings() + " wings." ) ;
|
||||
}
|
||||
|
||||
if( x.hasGills() )
|
||||
{
|
||||
x.breatheUnderwater() ;
|
||||
System.out.println( "Foxes can breathe under water." ) ;
|
||||
}
|
||||
|
||||
System.out.println() ;
|
||||
System.out.println( "Attempting things we shouldn't..." ) ;
|
||||
try
|
||||
{
|
||||
d.numberOfWings() ;
|
||||
}
|
||||
catch( RuntimeException e )
|
||||
{
|
||||
System.out.println( e.getMessage() ) ;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
d.breatheUnderwater() ;
|
||||
}
|
||||
catch( RuntimeException e )
|
||||
{
|
||||
System.out.println( e.getMessage() ) ;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
c.numberOfWings() ;
|
||||
}
|
||||
catch( RuntimeException e )
|
||||
{
|
||||
System.out.println( e.getMessage() ) ;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
c.breatheUnderwater() ;
|
||||
}
|
||||
catch( RuntimeException e )
|
||||
{
|
||||
System.out.println( e.getMessage() ) ;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
b.breatheUnderwater() ;
|
||||
}
|
||||
catch( RuntimeException e )
|
||||
{
|
||||
System.out.println( e.getMessage() ) ;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
f.numberOfLegs() ;
|
||||
}
|
||||
catch( RuntimeException e )
|
||||
{
|
||||
System.out.println( e.getMessage() ) ;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
f.numberOfWings() ;
|
||||
}
|
||||
catch( RuntimeException e )
|
||||
{
|
||||
System.out.println( e.getMessage() ) ;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
x.numberOfWings() ;
|
||||
}
|
||||
catch( RuntimeException e )
|
||||
{
|
||||
System.out.println( e.getMessage() ) ;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
x.breatheUnderwater() ;
|
||||
}
|
||||
catch( RuntimeException e )
|
||||
{
|
||||
System.out.println( e.getMessage() ) ;
|
||||
}
|
||||
|
||||
System.out.println() ;
|
||||
System.out.println( "Dog goes " + d.getSoundMade() ) ;
|
||||
System.out.println( "Cat goes " + c.getSoundMade() ) ;
|
||||
System.out.println( "Bird goes " + b.getSoundMade() ) ;
|
||||
System.out.println( "Fish goes " + f.getSoundMade() ) ;
|
||||
System.out.println( "What does the fox say? " + x.getSoundMade() ) ;
|
||||
}
|
||||
}
|
||||
Vendored
+4
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"java.project.sourcePaths": ["src"],
|
||||
"java.project.outputPath": "bin"
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
## Getting Started
|
||||
|
||||
Welcome to the VS Code Java world. Here is a guideline to help you get started to write Java code in Visual Studio Code.
|
||||
|
||||
## Folder Structure
|
||||
|
||||
The workspace contains two folders by default, where:
|
||||
|
||||
- `src`: the folder to maintain sources
|
||||
- `lib`: the folder to maintain dependencies
|
||||
|
||||
Meanwhile, the compiled output files will be generated in the `bin` folder by default.
|
||||
|
||||
> If you want to customize the folder structure, open `.vscode/settings.json` and update the related settings there.
|
||||
|
||||
## Dependency Management
|
||||
|
||||
The `JAVA PROJECTS` view allows you to manage your dependencies. More details can be found [here](https://github.com/microsoft/vscode-java-dependency#manage-dependencies).
|
||||
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,67 @@
|
||||
import javax.management.RuntimeErrorException;
|
||||
|
||||
public abstract class Animal
|
||||
{
|
||||
//TODO: private member variables
|
||||
private String _soundMade;
|
||||
private String _type;
|
||||
private boolean _hasLegs;
|
||||
private boolean _hasWings;
|
||||
private boolean _hasGills;
|
||||
|
||||
public Animal( String soundMade, boolean hasLegs, boolean hasWings, boolean hasGills, String type)
|
||||
{
|
||||
_soundMade = soundMade;
|
||||
_hasLegs = hasLegs;
|
||||
_hasWings = hasWings;
|
||||
_hasGills = hasGills;
|
||||
_type = type;
|
||||
}
|
||||
|
||||
public String getType()
|
||||
{
|
||||
return _type;
|
||||
}
|
||||
|
||||
public String getSoundMade()
|
||||
{
|
||||
return _soundMade;
|
||||
}
|
||||
|
||||
public boolean hasLegs()
|
||||
{
|
||||
return _hasLegs;
|
||||
}
|
||||
|
||||
public boolean hasWings()
|
||||
{
|
||||
return _hasWings;
|
||||
}
|
||||
|
||||
public boolean hasGills()
|
||||
{
|
||||
return _hasGills;
|
||||
}
|
||||
public abstract int numberOfLegs();
|
||||
public abstract int numberOfWings();
|
||||
public abstract void breatheUnderwater();
|
||||
|
||||
public void PrintDetails(Animal a) {
|
||||
String type = getType();
|
||||
try {
|
||||
int legs = numberOfLegs();
|
||||
System.out.println("A " + type + " has " + legs + " legs");
|
||||
} catch(RuntimeException e) {}
|
||||
try {
|
||||
int wings = numberOfWings();
|
||||
System.out.println("A " + type + " has " + wings + " wings");
|
||||
} catch(RuntimeException e) {}
|
||||
try {
|
||||
breatheUnderwater();
|
||||
} catch(RuntimeException e) {}
|
||||
try {
|
||||
String sound = getSoundMade();
|
||||
System.out.println("A " + type + " makes the sound " + sound);
|
||||
} catch (RuntimeException e) {}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
public class Bird extends Animal {
|
||||
public Bird() {
|
||||
super("tweet", true, true, false, "Bird");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void breatheUnderwater() {
|
||||
throw new RuntimeException( "Birds can't breathe under water!");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int numberOfLegs() {
|
||||
return 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int numberOfWings() {
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
public class Cat extends Animal {
|
||||
public Cat() {
|
||||
super("meow", true, false, false, "Cat");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void breatheUnderwater() {
|
||||
throw new RuntimeException( "Cats can't breathe under water!");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int numberOfLegs() {
|
||||
return 4;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int numberOfWings() {
|
||||
throw new RuntimeException("Cats don't have wings!");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
public class Dog extends Animal {
|
||||
|
||||
public Dog() {
|
||||
super("woof", true, false, false, "Dog");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void breatheUnderwater() {
|
||||
throw new RuntimeException( "Dogs can't breathe under water!");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int numberOfLegs() {
|
||||
return 4;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int numberOfWings() {
|
||||
throw new RuntimeException("Dogs don't have wings!");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
public class Fish extends Animal{
|
||||
public Fish() {
|
||||
super("blub", false, false, true, "Fish");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void breatheUnderwater() {
|
||||
System.out.println("A fish can breathe under water");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int numberOfLegs() {
|
||||
throw new RuntimeException("Fish don't have legs!");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int numberOfWings() {
|
||||
throw new RuntimeException("Fish don't have wings!");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
public class Fox extends Animal {
|
||||
public Fox() {
|
||||
super("Ring-ding-ding-dingeringeding", true, false, false, "Fox");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void breatheUnderwater() {
|
||||
throw new RuntimeException( "Foxes can't breathe under water!");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int numberOfLegs() {
|
||||
return 4;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int numberOfWings() {
|
||||
throw new RuntimeException("Foxes don't have wings!");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Tester
|
||||
{
|
||||
public static void main( String[] args )
|
||||
{
|
||||
Dog d = new Dog () ;
|
||||
Cat c = new Cat () ;
|
||||
Bird b = new Bird() ;
|
||||
Fish f = new Fish() ;
|
||||
Fox x = new Fox () ;
|
||||
|
||||
ArrayList<Animal> animals = new ArrayList<>();
|
||||
animals.add(d);
|
||||
animals.add(c);
|
||||
animals.add(b);
|
||||
animals.add(f);
|
||||
animals.add(x);
|
||||
|
||||
for (Animal a:animals) {
|
||||
a.PrintDetails(a);
|
||||
}
|
||||
}
|
||||
}
|
||||
Vendored
+4
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"java.project.sourcePaths": ["src"],
|
||||
"java.project.outputPath": "bin"
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
## Getting Started
|
||||
|
||||
Welcome to the VS Code Java world. Here is a guideline to help you get started to write Java code in Visual Studio Code.
|
||||
|
||||
## Folder Structure
|
||||
|
||||
The workspace contains two folders by default, where:
|
||||
|
||||
- `src`: the folder to maintain sources
|
||||
- `lib`: the folder to maintain dependencies
|
||||
|
||||
Meanwhile, the compiled output files will be generated in the `bin` folder by default.
|
||||
|
||||
> If you want to customize the folder structure, open `.vscode/settings.json` and update the related settings there.
|
||||
|
||||
## Dependency Management
|
||||
|
||||
The `JAVA PROJECTS` view allows you to manage your dependencies. More details can be found [here](https://github.com/microsoft/vscode-java-dependency#manage-dependencies).
|
||||
Binary file not shown.
Binary file not shown.
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user