-
Notifications
You must be signed in to change notification settings - Fork 44
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
prandzio99
wants to merge
3
commits into
tborzyszkowski:master
Choose a base branch
from
prandzio99:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { | ||
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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();} | ||
} | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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ć.