Skip to content

Instantly share code, notes, and snippets.

@derohimat
Last active March 4, 2019 13:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save derohimat/9364a7e6dd4d1d1162b6f653ef85f5b2 to your computer and use it in GitHub Desktop.
Save derohimat/9364a7e6dd4d1d1162b6f653ef85f5b2 to your computer and use it in GitHub Desktop.
Semester 6
public class MyClass {
public static void main(String args[]) {
Author author = new Author("Deni R", "rohimatdeni@gmail.com", 'L');
Book book = new Book("Pemrograman Android", author, 100000.0, 1000);
System.out.println("Book name : " + book.getName());
System.out.println(book.getAuthor());
System.out.println("Price : " + book.getPrice());
System.out.println("Quantity : " + book.getQty());
}
public static class Book {
private String name;
private Author author;
private double price;
private int qtyInStock = 0;
public Book(String name, Author author, double price) {
this.name = name;
this.author = author;
this.price = price;
}
public Book(String name, Author author, double price, int qtyInStock) {
this.name = name;
this.author = author;
this.price = price;
this.qtyInStock = qtyInStock;
}
public String getName() {
return this.name;
}
public Author getAuthor() {
return this.author;
}
public double getPrice() {
return this.price;
}
public void setPrice(double price) {
this.price = price;
}
public int getQty() {
return this.qtyInStock;
}
public void setQty(int qty) {
this.qtyInStock = qty;
}
}
public static class Author {
private String name;
private String email;
private char gender;
public Author(String name, String email, char gender) {
this.name = name;
this.email = email;
this.gender = gender;
}
public String getName() {
return this.name;
}
public String getEmail() {
return this.email;
}
public void setEmail(String email) {
this.email = email;
}
public char getGender() {
return this.gender;
}
public void setGender(char gender) {
this.gender = gender;
}
public String toString() {
return "Author Name : " + this.name +"\nAuthor Email : " + this.email + "\nAuthor Gender : " + this.gender;
}
}
}
// C code for hollow squares
#include <stdio.h>
// Function to print hollow square
void print_square(int n)
{
int i, j;
for (i = 1; i <= n; i++)
{
for (j = 1; j <= n; j++)
{
if (i==1) {
if (j == 1) {
printf("# ");
} else {
printf("| ");
}
} else if (i==j) {
printf("# ");
} else {
printf("* ");
}
}
printf("\n");
}
}
// Driver code for above function
int main()
{
int rows = 10;
print_square(rows);
return 0;
}
public class Line {
public static void main(String[] args) {
Point p1 = new Point();
p1.setX(10);
p1.setY(2);
Point p2 = new Point();
p2.setX(8);
p2.setY(4);
System.out.println(p1.divide() * p2.multiply());
System.out.println("Length : " + calculateLength(p1, p2));
}
public static double calculateLength(Point p1, Point p2){
return Math.sqrt(Math.pow(p1.x-p2.x, 2) +
Math.pow(p1.y-p2.y, 2));
}
}
class Point {
int x;
int y;
public void setX(int x) {
this.x = x;
}
public void setY(int y) {
this.y = y;
}
public int getX() {
return x;
}
public int getY() {
return y;
}
public int multiply() {
return x * y;
}
public int divide() {
if (y != 0) {
return x / y;
} else {
return 0;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment