Last active
August 29, 2015 13:12
-
-
Save nstanevski/ee1738a653350b9947a0 to your computer and use it in GitHub Desktop.
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
import java.util.Scanner; | |
public class Class_01_RectangleArea { | |
public static void main(String[] args) { | |
Scanner console = new Scanner(System.in); | |
System.out.print("a = "); | |
int a = Integer.parseInt(console.next()); | |
System.out.print("b = "); | |
int b = Integer.parseInt(console.next()); | |
int area = a*b; | |
System.out.println(String.format("area is: %d", area)); | |
console.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
import java.util.Locale; | |
import java.util.Scanner; | |
public class Class_02_TriangleArea { | |
public static void main(String[] args) { | |
Locale.setDefault(Locale.ROOT); | |
Scanner console = new Scanner(System.in); | |
Point[] triangle = new Point[3]; | |
for(int i=0; i<triangle.length; i++){ | |
System.out.print(String.format("x%d = ", i+1)); | |
double x = console.nextDouble(); | |
console.nextLine(); | |
System.out.print(String.format("y%d = ", i+1)); | |
double y = console.nextDouble(); | |
console.nextLine(); | |
triangle[i] = new Point(x,y); | |
} | |
double dist1 = triangle[0].distanceTo(triangle[1]); | |
double dist2 = triangle[1].distanceTo(triangle[2]); | |
double dist3 = triangle[2].distanceTo(triangle[0]); | |
double p = 0.5*(dist1+dist2+dist3); | |
double area = Math.sqrt(p*(p-dist1)*(p-dist2)*(p-dist3)); | |
System.out.println(String.format("%d",Math.round(area))); | |
console.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
import java.util.Locale; | |
import java.util.Scanner; | |
public class Class_03_PointInsideFigure { | |
public static void main(String[] args) { | |
Locale.setDefault(Locale.ROOT); | |
Scanner console = new Scanner(System.in); | |
Rectangle r1 = new Rectangle(new Point(12.5, 13.5), new Point(17.5, 8.5)); | |
Rectangle r2 = new Rectangle(new Point(12.5, 8.5), new Point(22.5, 6.0)); | |
Rectangle r3 = new Rectangle(new Point(20.0, 13.5), new Point(22.5, 8.5)); | |
System.out.print("Enter x and y, separated by a space: "); | |
String line = console.nextLine(); | |
while(line.length()>0){ | |
String[] items = line.split(" "); | |
double x = Double.parseDouble(items[0]); | |
double y = Double.parseDouble(items[1]); | |
Point p = new Point(x,y); | |
if(r1.pointInside(p) || r2.pointInside(p) || r3.pointInside(p)){ | |
System.out.println("Inside"); | |
}else{ | |
System.out.println("Outside"); | |
} | |
System.out.print("Enter x and y, separated by a space: "); | |
line = console.nextLine(); | |
} | |
console.close(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment