Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Paweł Randzio: Geometria i pierwsze zadania #71

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions Studenci/RandzioPaweł_2019/00-Pierwsze/CSVRep.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import java.io.*;
import java.lang.*;


class methods {
int countOccurence(String cardType) throws IOException {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tego typu metody powinny być statyczne. Należy tego unikać.

BufferedReader csvRead = new BufferedReader(new FileReader("SalesJan2009.csv"));
String row;
int count = 0;
while((row = csvRead.readLine()) != null) {
String[] data = row.split(",");
if(data[3].equals(cardType)) {
count += 1;
}
}
return count;
}
}
public class CSVRep {
public static void main(String[] args) throws IOException {
BufferedReader csvRead = new BufferedReader(new FileReader("SalesJan2009.csv"));
methods met = new methods();
String row;
while((row = csvRead.readLine()) != null) {
String[] data = row.split(",");
System.out.println();
System.out.print(data[0] + " " + data[1] + " " + data[2] + " " + data[3] + " " + data[4] + " " + data[5] + " " + data[6] + " " + data[7] + " " + data[8] + " " + data[9] + " " + data[10] + " " + data[11]);
}
System.out.println();
System.out.println("MasterCard used "+met.countOccurence("Mastercard")+" times, Visa used "+met.countOccurence("Visa")+" times.");
double occ = met.countOccurence("Mastercard");
double percentage = (occ/999.0)*100;
System.out.println("MasterCard was used in "+ Math.round(percentage)+"% of operations.");
csvRead.close();
}
}
33 changes: 33 additions & 0 deletions Studenci/RandzioPaweł_2019/00-Pierwsze/CaesarCipher.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import java.util.Scanner;

class CaesarCipher
{
public static StringBuffer encrypt(String text, int shift)
{
StringBuffer result = new StringBuffer();

for (int i=0; i<text.length(); i++) {
if (Character.isUpperCase(text.charAt(i))) {
char ch = (char)(((int)text.charAt(i) + shift - 65) % 26 + 65);
result.append(ch);
}
else {
char ch = (char)(((int)text.charAt(i) + shift - 97) % 26 + 97);
result.append(ch);
}
}
return result;
}

public static void main(String[] args)
{
Scanner scan = new Scanner(System.in);
System.out.println("Podaj wiadomość: ");
String text = scan.nextLine();
System.out.println("Podaj przesunięcie: ");
int s = scan.nextInt();
System.out.println("Wiadomość : " + text);
System.out.println("Przesunięcie : " + s);
System.out.println("Szyfr : " + encrypt(text, s));
}
}
28 changes: 28 additions & 0 deletions Studenci/RandzioPaweł_2019/00-Pierwsze/FileZip.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import java.util.ArrayList;
import java.io.File;
import net.lingala.zip4j.model.ZipParameters;
import net.lingala.zip4j.util.Zip4jConstants;
import net.lingala.zip4j.core.ZipFile;
import net.lingala.zip4j.exception.ZipException;

public class FileZip
{
public static void main(String[] args)
{
try {
ZipFile zipFile = new ZipFile("test.zip");
ArrayList<File> filesToAdd = new ArrayList<File>();
filesToAdd.add(new File("test1.txt"));
filesToAdd.add(new File("test2.txt"));
ZipParameters parameters = new ZipParameters();
parameters.setCompressionMethod(Zip4jConstants.COMP_DEFLATE);
parameters.setCompressionLevel(Zip4jConstants.DEFLATE_LEVEL_MAXIMUM);
parameters.setEncryptFiles(true);
parameters.setEncryptionMethod(Zip4jConstants.ENC_METHOD_STANDARD);
//parameters.setAesKeyStrength(Zip4jConstants.AES_STRENGTH_256);
parameters.setPassword("passwd1234");
zipFile.addFiles(filesToAdd, parameters);
}
catch (ZipException e) {e.printStackTrace();}
}
}
1 change: 1 addition & 0 deletions Studenci/RandzioPaweł_2019/00-Pierwsze/SalesJan2009.csv

Large diffs are not rendered by default.

42 changes: 42 additions & 0 deletions Studenci/RandzioPaweł_2019/01-Geometria/Odcinek.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import java.lang.*;

public class Odcinek{
double Ax;
double Ay;
double Bx;
double By;

public Odcinek(){}

public Odcinek(double ax, double ay, double bx, double by){
Ax = ax;
Ay = ay;
Bx = bx;
By = by;
}

public Odcinek(Punkt a, Punkt b){
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not DRY

Ax = a.x;
Ay = a.y;
Bx = b.x;
By = b.y;
}

public Odcinek(Punkt p, double a, double b){
Ax = p.x;
Ay = p.y;
Bx = a;
By = b;
}

public void shift(double a, double b){
this.Ax = this.Ax + a;
this.Bx = this.Bx + a;
this.Ay = this.Ay + b;
this.By = this.By + b;
}

public double pointDistance(Punkt p){
return (Math.abs(((this.By-this.Ay)/(this.Bx-this.Ax))*p.x-p.y+((this.Bx*this.Ay-this.Ax*this.By)/(this.Bx-this.Ax))))/Math.sqrt(Math.pow((this.By-this.Ay)/(this.Bx-this.Ax),2)+1);
}
}
22 changes: 22 additions & 0 deletions Studenci/RandzioPaweł_2019/01-Geometria/OdcinekTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import org.junit.Assert;
import org.junit.jupiter.api.Test;

class OdcinekTest {

@Test
void shift() {
Odcinek odc = new Odcinek(0.0, 0.0, 4.0, 4.0);
odc.shift(1.0,2.5);
Assert.assertEquals(1.0, odc.Ax, 0.0001);
Assert.assertEquals(5.0, odc.Bx, 0.0001);
Assert.assertEquals(2.5, odc.Ay, 0.0001);
Assert.assertEquals(6.5, odc.By, 0.0001);
}

@Test
void pointDistance() {
Odcinek odc = new Odcinek(1.0,3.4,2.2,5.5);
Punkt p = new Punkt();
Assert.assertEquals((Math.abs(((odc.By-odc.Ay)/(odc.Bx-odc.Ax))*p.x-p.y+((odc.Bx*odc.Ay-odc.Ax*odc.By)/(odc.Bx-odc.Ax))))/Math.sqrt(Math.pow((odc.By-odc.Ay)/(odc.Bx-odc.Ax),2)+1),odc.pointDistance(p),0.0001);
}
}
43 changes: 43 additions & 0 deletions Studenci/RandzioPaweł_2019/01-Geometria/Punkt.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import java.lang.*;

public class Punkt {
double x;
double y;

public Punkt(){}

public Punkt(double x, double y){
this.x = x;
this.y = y;
}

public Punkt(Punkt pkt){
x = pkt.x;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not DRY

y = pkt.y;
}

public double getX(){
return x;
}

public double getY(){
return y;
}

public void setX(double x){
this.x = x;
}

public void setY(double y){
this.y = y;
}

public void shift(double x, double y){
this.x = this.x + x;
this.y = this.y + y;
}

public double distance(Punkt p){
return Math.sqrt(Math.pow(this.x-p.x,2)+Math.pow(this.y-p.y,2));
}
}
49 changes: 49 additions & 0 deletions Studenci/RandzioPaweł_2019/01-Geometria/PunktTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import org.junit.Assert;

class PunktTest {

@org.junit.jupiter.api.Test
void getX() {
Punkt punkt = new Punkt(2.1,3.3);
Punkt punktTest = new Punkt(punkt);
Assert.assertEquals(2.1, punktTest.getX(), 0.0001);
}

@org.junit.jupiter.api.Test
void getY() {
Punkt punkt = new Punkt(1.9,4.2);
Punkt punktTest = new Punkt(punkt);
Assert.assertEquals(4.2,punktTest.getY(),0.0001);
}

@org.junit.jupiter.api.Test
void setX() {
Punkt punkt = new Punkt(0.2,6.3);
Punkt punktTest = new Punkt(punkt);
punktTest.setX(2.2);
Assert.assertEquals(2.2,punktTest.x,0.0001);
}

@org.junit.jupiter.api.Test
void setY() {
Punkt punkt = new Punkt(7.4,4.5);
Punkt punktTest = new Punkt(punkt);
punktTest.setY(5.6);
Assert.assertEquals(5.6,punktTest.y,0.0001);
}

@org.junit.jupiter.api.Test
void shift() {
Punkt punkt = new Punkt(2.0, 1.4);
punkt.shift(3.1,0.2);
Assert.assertEquals(5.1,punkt.getX(),0.0001);
Assert.assertEquals(1.6,punkt.getY(),0.0001);
}

@org.junit.jupiter.api.Test
void distance() {
Punkt punktA = new Punkt();
Punkt punktB = new Punkt(1.0,2.0);
Assert.assertEquals(Math.sqrt(Math.pow(punktA.x-punktB.x,2)+Math.pow(punktA.y-punktB.y,2)),punktA.distance(punktB),0.0001);
}
}