first commit

This commit is contained in:
LinlyBoi
2021-11-06 23:35:03 +02:00
commit 63ba32bb3c
27 changed files with 498 additions and 0 deletions

12
BoringWindow.java Normal file
View File

@@ -0,0 +1,12 @@
import javax.swing.*;
public class BoringWindow extends JFrame
{
public static void main ( String[] args)
{
JFrame f = new BoringWindow();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setSize(690,420);
f.setVisible(true);
}
}

22
Constructor.java Normal file
View File

@@ -0,0 +1,22 @@
class Scratch //name class sth else lol depending on usage
{
public static void main(String[] args) {
}
public static class Constructor
{
String material;
int height;
double width;
Constructor(String material, int height, double width) //name self-explanatory
{
this.material = material;
this.height = height;
this.width = width;
void build();{
System.out.println("Building a house out of "+this.material + "that is " +this.height + " high and " + this.width + " wide" );
}
}
//they can also be overloaded! f
}
}

14
IfStatements.java Normal file
View File

@@ -0,0 +1,14 @@
import javax.swing.JOptionPane;
class Scratch {
public static void main(String[] args) {
int age = Integer.parseInt(JOptionPane.showInputDialog("How old are you?"));
if(age>=18)
{
JOptionPane.showMessageDialog(null,"You can do the fuck");
}
else {
JOptionPane.showMessageDialog(null,"No no no No FUCKING!!!");
}
}
}

48
Magic8Ball.java Normal file
View File

@@ -0,0 +1,48 @@
import javax.swing.*;
import java.util.Random;
public class Magic8Ball
{
public static void main ( String[] args )
{
Random r = new Random();
int choice = 1 + r.nextInt(15);
String response;
if ( choice == 1 )
response = "It is certain";
else if ( choice == 2 )
response = "It is decidedly so";
else if ( choice == 3 )
response = "Without a doubt";
else if ( choice == 4 )
response = "Yes - definitely";
else if ( choice == 5 )
response = "You may rely on it";
else if ( choice == 6 )
response = "As I see it, yes";
else if ( choice == 7 )
response = "Most likely";
else if ( choice == 8 )
response = "Outlook good";
else if ( choice == 9 )
response = "Signs point to yes";
else if ( choice == 10 )
response = "Yes";
else if ( choice == 11 )
response = "Reply hazy, try again";
else if ( choice == 12 )
response = "Ask again later";
else if ( choice == 13 )
response = "Better not tell you now";
else if ( choice == 14 )
response = "Cannot predict now";
else if ( choice == 15 )
response = "Concentrate and ask again";
else
response = "8-BALL ERROR!";
JOptionPane.showMessageDialog(null, response);
}
}

62
MathClassTest.java Normal file
View File

@@ -0,0 +1,62 @@
import java.util.ArrayList;
class Scratch {
public static void main(String[] args) {
//double x = 10;
//double y = 20;
//double z = x+y;
// Array
String[] noobs = {"Ggsleeb", "Glabnab", "Galanbees","Gegelfar","Gighalara"};
System.out.println("The element is " +noobs[0]); //start from 0 :D
//Print Array with foreach
for (String x : noobs)
{
System.out.println(x);
}
//2D arrays POG
String[] [] noobs2 = new String [3][3];
noobs2[0][0]= "Roosya";
noobs2[0][1]= "GGsya";
noobs2[0][2]= "Glabnab";
noobs2[1][0]= "KhaledHn1";
noobs2[1][1]= "Embty";
noobs2[1][2]= "Noob";
//print 2D array with for loop :D
for(int i=0;i<noobs2.length;i++)
{
System.out.println();
for(int j=0; j< noobs2[i].length;j++)
{
System.out.print(noobs2[i][j]+" ");
}
//can also define 2D array like this
String[][] idots = {
{"ex1","ex2","ex3"},
{"ex4","ex5","ex6"},
{"ex7","ex8","ex9"}
};
//ArrayLists! They need not primitive data types
ArrayList<String> food = new ArrayList<String>();
food.add("Pasta");
food.add("Pizza");
food.add("Rice");
//print with for statement yes
for(int y=0;y<food.size();y++){
System.out.println(food.get(y));
}
//ArrayList.set(Position,"element") , ArrayList.clear exist too :D
}
}
}

32
Methods.java Normal file
View File

@@ -0,0 +1,32 @@
class Scratch {
public static void main(String[] args) {
// methods..functions but associated with objects?
int x = 3;
int y = 4;
int z = 5;
int result = sum(x,y); //both result(s) are local variables :D
System.out.println(result);
}
static int sum(int a,int b)
{
int result = a + b;
System.out.println("This adds only 2 values!");
return result; // return x+y; works too
}
//time to overload it!
static int sum(int a,int b,int c)
{
System.out.println("This adds THREE values!");
return a + b + c;
}
/* same method name but different signature
* Signatures are method name + method parameters(Number,Data type etc) */
}

30
NestedLoops.java Normal file
View File

@@ -0,0 +1,30 @@
import java.util.Scanner;
class Scratch {
public static void main(String[] args) {
//Loop in loops
Scanner scanner = new Scanner(System.in);
int rows;
int columns;
String symbol;
System.out.println("Enter # of rows: ");
rows = scanner.nextInt();
System.out.println("Enter # of columns: ");
columns = scanner.nextInt();
System.out.println("enter symbol");
symbol = scanner.next();
for(int i =1;i<=rows;i++)
{
System.out.println(); //moves us to next line each time to signify rows
for(int j =1;j<=columns;j++)
{
System.out.print(symbol); //prints symbol = to columns number
}
}
}
}
}

31
SampleGUI2.java Normal file
View File

@@ -0,0 +1,31 @@
import javax.swing.*;
import java.awt.*;
class Scratch {
public static void main(String[] args) {
Frame69 f = new Frame69();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setVisible(true); //wether it should run in background or not
}
static class Frame69 extends JFrame //sub class of JFrame which is the GUI class
{
public Frame69() {
setTitle("69 is best"); //this is title
setSize(690,420);
setLocation(100,100);
Panel69 panel = new Panel69();
Container cp = getContentPane(); //containers can do a lot in JFrame
cp.add(panel);
}
class Panel69 extends JPanel
{
public void paintComponent(Graphics g)
{
super.paintComponents(g);
g.drawString("Hi", 75 ,100);
}
}
}
}

14
Scanner.java Normal file
View File

@@ -0,0 +1,14 @@
import java.util.Scanner;
class Scratch {
public static void main(String[] args){
Scanner scanner = new Scanner(System.in);
System.out.println("What is your name? ");
String name = scanner.nextLine();
System.out.println(name +" what? ");
String lastname = scanner.nextLine();
System.out.println("That's a made up name!");
}
}

BIN
Scratch.class Normal file

Binary file not shown.

17
Switches.java Normal file
View File

@@ -0,0 +1,17 @@
import javax.swing.JOptionPane;
class Scratch {
public static void main(String[] args) {
String idots= JOptionPane.showInputDialog("What is your name?");
switch (idots) {
case "Ggsya" -> System.out.println("Lord Ggsleeb");
case "KhaledHn1" -> System.out.println("Lord Gigalara");
case "Roosya" -> System.out.println("Lord Galanbees");
default -> System.out.println("noob not found");
}
}
}

12
TestingMethods.java Normal file
View File

@@ -0,0 +1,12 @@
class Scratch {
public static void main(String[] args)
{
}
static void listnames(String a, String b, String c)
{
}
}

21
TryCatch.java Normal file
View File

@@ -0,0 +1,21 @@
import java.util.Scanner;
class TryCatch
{
public static void main(String[] args) {
//lets divide by 0 LOL
try {
Scanner scanner = new Scanner(System.in);
System.out.println("Enter a number to divide:");
int x = scanner.nextInt();
System.out.println("Enter a number to divide by:");
int y = scanner.nextInt();
int z = x/y;
}
catch(ArithmeticException e)
{
System.out.println("1 over zero equals infinity -Ggsya");
}
}
}

21
WhileDo.java Normal file
View File

@@ -0,0 +1,21 @@
import java.util.Scanner;
class Scratch {
public static void main(String[] args) {
String name;
Scanner scanner = new Scanner(System.in);
do {
System.out.print("What is your name? \n");
name = scanner.nextLine();
} while(name.isBlank());
/* can do the same with while first and without do
but that doesn't assure that the code runs at least once. */
System.out.println("Hello "+name);
//This is a for loop now
for(int i=10;i>=1;) {
System.out.println(i);
i--;
}
System.out.println("no more numbers!"); //Is for limited amounts of times pOG
}
}

21
art.txt Normal file
View File

@@ -0,0 +1,21 @@
.--..--..--..--..--..--.
.' \ (`._ (_) _ \
.' | '._) (_) |
\ _.')\ .----..---. /
|(_.' | / .-\-. \ |
\ 0| | ( O| O) | o|
| _ | .--.____.'._.-. |
\ (_) | o -` .-` |
| \ |`-._ _ _ _ _\ /
\ | | `. |_||_| |
| o | \_ \ | -. .-.
|.-. \ `--..-' O | `.`-' .'
_.' .' | `-.-' /-.__ ' .-'
.' `-.` '.|='=.='=.='=.='=|._/_ `-'.'
`-._ `. |________/\_____| `-.'
.' ).| '=' '='\/ '=' |
`._.` '---------------'
//___\ //___\
|| ||
||_.-. ||_.-.
(_.--__) (_.--__)

38
audio.java Normal file
View File

@@ -0,0 +1,38 @@
import javax.sound.sampled.*;
import java.io.*;
import java.util.Scanner;
class Scratch
{
public static void main(String[] args) throws UnsupportedAudioFileException,IOException, LineUnavailableException
{
Scanner scanner = new Scanner(System.in);
File file = new File("JansiFart3.wav");
AudioInputStream audioStream = AudioSystem.getAudioInputStream(file);
Clip clip = AudioSystem.getClip();
clip.open(audioStream);
String response = "pog";
while(!response.equals("Q"))
{
System.out.println("P = play , S = stop , R = reset, Q = quit");
System.out.print("Enter your choice:");
response = scanner.next();
response = response.toUpperCase();
switch(response)
{
case ("P"): clip.start();
break;
case("S"): clip.stop();
break;
case("R"): clip.setMicrosecondPosition(0);
case("Q"): clip.close();
break;
default: System.out.println("Not valid!");
}
clip.start();
}
}
}

0
deleteme.txt Normal file
View File

BIN
fart/JansiFart3.wav Normal file

Binary file not shown.

BIN
fart/Scratch.class Normal file

Binary file not shown.

21
fart/fart.java Normal file
View File

@@ -0,0 +1,21 @@
import javax.sound.sampled.*;
import java.io.*;
import java.util.Scanner;
class Scratch
{
public static void main(String[] args) throws UnsupportedAudioFileException,IOException, LineUnavailableException
{
Scanner scanner = new Scanner(System.in);
File file = new File("JansiFart3.wav");
AudioInputStream audioStream = AudioSystem.getAudioInputStream(file);
Clip clip = AudioSystem.getClip();
clip.open(audioStream);
String response = "pog";
clip.start();
scanner.next();
}
}

15
file.java Normal file
View File

@@ -0,0 +1,15 @@
import java.io.File;
class Scratch {
public static void main(String[] args)
{
File file = new File("ggsleeb_wisdom.txt");
if(file.exists())
{
System.out.println("File exists O:");
System.out.println(file.getPath());
System.out.println(file.getAbsolutePath());
}
}
}

29
filereader.java Normal file
View File

@@ -0,0 +1,29 @@
import java.io.FileReader;
import java.io.IOException;
import java.io.FileNotFoundException;
class Scratch
{
public static void main(String[] args)
{
try
{
FileReader reader = new FileReader("art.txt");
int data = reader.read();
while(data != -1)
{
System.out.print((char)data);
data = reader.read();
}
reader.close();
}
catch(FileNotFoundException e)
{
e.printStackTrace();
}
catch(IOException e) {
e.printStackTrace();
}
}
}

20
filewriter.java Normal file
View File

@@ -0,0 +1,20 @@
import java.io.FileWriter;
import java.io.IOException;
import java.util.Scanner;
class Scratch {
public static void main(String[] args)
{
Scanner scanner = new Scanner(System.in);
try
{
FileWriter writer = new FileWriter("wisdom.txt");
System.out.println("Enter wisdom pls :D");
writer.append("\n"+scanner.nextLine());
writer.close();
}
catch(IOException e)
{
e.printStackTrace();
}
}
}

0
ggsleeb_wisdom.txt Normal file
View File

9
guiexample.java Normal file
View File

@@ -0,0 +1,9 @@
import javax.swing.JOptionPane;
class Scratch {
public static void main(String[] args) {
String name = JOptionPane.showInputDialog("What is your name?");
JOptionPane.showMessageDialog(null,"Hello "+name);
int age = Integer.parseInt(JOptionPane.showInputDialog("Enter your mental age"));
JOptionPane.showMessageDialog(null,"Your mental age is "+age);
}
}

7
printf.java Normal file
View File

@@ -0,0 +1,7 @@
class Scratch {
public static void main(String[] args) {
// printf method is for formatting things?
System.out.printf("Epic moment number %d",69); //%d represents decimal
// it is % [flags] [precision] [width] [conversion character]
}
}

2
wisdom.txt Normal file
View File

@@ -0,0 +1,2 @@
Yes I am