Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package javaapplication1;
- public class Aeroplano {
- private String company;
- private double pricePerTicket;
- public static double ekptwsiGiaPitsirikia = .5;
- private HumanV3[] passengers;
- public Aeroplano(String company, double pricePerTicket, int numberOfPassengers) {
- this.company = company;
- this.pricePerTicket = pricePerTicket;
- this.passengers = new HumanV3[numberOfPassengers];
- }
- public boolean addPassenger(int index, HumanV3 passenger) {
- if (index > this.passengers.length - 1 || index < 0
- || this.passengers[index] != null) {
- return false;
- } else {
- this.passengers[index] = passenger;
- return true;
- }
- }
- public double getProfit() {
- double profit = 0;
- for (int i = 0; i < this.passengers.length; i++) {
- if (this.passengers[i] != null) {
- if (this.passengers[i].getAge() <= 15) {
- profit += this.pricePerTicket * (1 - Aeroplano.ekptwsiGiaPitsirikia);
- } else {
- profit += this.pricePerTicket;
- }
- }
- }
- return profit;
- }
- public String toString() {
- String tmp = this.company +":\n";
- for (int i = 0; i < this.passengers.length; i++) {
- if (this.passengers[i] != null) {
- tmp += this.passengers[i].toString() +"\n";
- }
- }
- return tmp;
- }
- public String getCompany() {
- return company;
- }
- public void setCompany(String company) {
- this.company = company;
- }
- public double getPricePerTicket() {
- return pricePerTicket;
- }
- public void setPricePerTicket(double pricePerTicket) {
- this.pricePerTicket = pricePerTicket;
- }
- }
- /*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
- package javaapplication1;
- /**
- *
- * @author user
- */
- public class HumanV3 {
- private String name;
- private String surname;
- private int age;
- public HumanV3(String name, String surname, int age) {
- this.setName(name);
- this.setSurname(surname);
- this.setAge(age);
- }
- public String getName() {
- return name;
- }
- public void setName(String name) {
- this.name = name;
- }
- public String getSurname() {
- return surname;
- }
- public void setSurname(String surname) {
- this.surname = surname;
- }
- public int getAge() {
- return age;
- }
- public void setAge(int age) {
- this.age = age;
- }
- @Override
- public String toString() {
- return "HumanV3{" + "name=" + name + ", surname=" + surname + ", age=" + age + '}';
- }
- }
- /*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
- package javaapplication1;
- /**
- *
- * @author user
- */
- public class TestHuman2 {
- public static void main(String[] args){
- Human2 dimi = new Human2();
- Human2 gianni = new Human2("Giannis","lalas",25);
- Human2 mpampis = new Human2("Mpampis","Flou");
- dimi.setSurname("Foo");
- System.out.println(dimi);
- System.out.println(gianni.getName());
- dimi.setName("Dimi");
- String nameOfDimi = dimi.getName();
- dimi.setAge(50);
- System.out.println(dimi.getAge());
- dimi.setAge(-1);
- System.out.println(dimi.getAge());
- dimi.setAge(150);
- System.out.println(dimi.getAge());
- //
- //
- }
- }
- /*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
- package javaapplication1;
- import java.util.Random;
- import java.util.Scanner;
- /**
- *
- * @author user
- */
- public class Arrays {
- public static void main(String[] args) {
- int[] array = new int[10];
- Random r = new Random();
- for (int i = 0; i < array.length; i++) {
- //random integer from 5 to 15;
- array[i] = r.nextInt(10) + 5;
- }
- for (int i = 0; i < array.length; i++) {
- //random integer from 0 to 10;
- System.out.println(array[i]);
- }
- int[][] array2D = new int[10][10];
- for (int i = 0; i < array2D.length; i++) {
- for (int j = 0; j < array2D[i].length; j++) {
- array2D[i][j] = r.nextInt(50);
- }
- }
- int[][] array2Dv2 = new int[10][];
- for (int i = 0; i < array2Dv2.length; i++) {
- array2Dv2[i] = new int[r.nextInt(50)];
- for (int j = 0; j < array2Dv2[i].length; j++) {
- array2Dv2[i][j] = r.nextInt(50);
- }
- }
- int sum = 0;
- for (int i = 0; i < array2Dv2.length; i++) {
- array2Dv2[i] = new int[r.nextInt(50)];
- for (int j = 0; j < array2Dv2[i].length; j++) {
- sum += array2Dv2[i][j];
- }
- }
- // gemisma apo pliktrologio
- Scanner s = new Scanner(System.in);
- for (int i = 0; i < array2Dv2.length; i++) {
- array2Dv2[i] = new int[r.nextInt(50)];
- for (int j = 0; j < array2Dv2[i].length; j++) {
- System.out.println("Dwse stixio");
- array2Dv2[i][j] = s.nextInt();
- }
- }
- }
- }
- /*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
- package javaapplication1;
- /**
- *
- * @author user
- */
- public class Human2 {
- private String name;
- private int age;
- private String surname;
- public Human2(){
- System.out.println("You called me");
- this.age = 1;
- this.name = "Junior";
- }
- public Human2(String name,String surname,int age){
- this.name = name;
- this.surname = surname;
- this.setAge(age);
- }
- public Human2(String name,String surname){
- this.name = name;
- this.surname = surname;
- }
- public String getSurname() {
- return surname;
- }
- public void setSurname(String surname) {
- this.surname = surname;
- }
- public int getAge() {
- return this.age;
- }
- public void setAge(int age) {
- if (age < 0) {
- System.out.println("Not born yet");
- } else if (age > 120) {
- System.out.println("RIP");
- } else {
- this.age = age;
- }
- }
- public String getName() {
- return this.name;
- }
- public void setName(String name) {
- if (name.length() < 50) {
- this.name = name;
- }
- }
- @Override
- public String toString() {
- return "Human2{" + "name=" + name + ", age=" + age + ", surname=" + surname + '}';
- }
- }
- /*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
- package javaapplication1;
- public class Human {
- String name;
- String surname;
- int age;
- static int numberOfEyes = 2;
- public static double sum(double x, double y){
- return x +y;
- }
- public static void mutate(int eyes){
- // surname = "hello"; LATHOS einai idiotita stigmiotipou
- Human.numberOfEyes = eyes;
- //Human.numberOfEyes = (int)Human.sum(eyes,1);
- }
- public static void main(String[] args){
- double mySum = Human.sum(5, 6);
- System.out.println(mySum);
- Human a = new Human();
- Human b = new Human();
- a.name = "Giannis";
- a.surname = "Lala";
- b.name = "Mpampis";
- b.surname = "Flou";
- System.out.println(a.name + " I've got "+ a.numberOfEyes + " eyes" );
- Human.mutate(3);
- //a.numberOfEyes = 3;
- System.out.println(b.name + " I've got "+ b.numberOfEyes + " eyes" );
- System.out.println(a.name + " I've got "+ a.numberOfEyes + " eyes" );
- }
- }
- /*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
- package javaapplication1;
- /**
- *
- * @author user
- */
- public class Bottle {
- static double globalVAT = .24;
- String periexomeno;
- int ml;
- String brand;
- double price;
- boolean hasExpired;
- public void printMe() {
- System.out.println("My content is " + this.periexomeno);
- System.out.println("and I've got " + this.ml + "ml");
- }
- public double getPriceWithVat() {
- return this.price + (this.price * .24);
- }
- public double getPriceWithVat(double vat){
- return this.price + (this.price * vat);
- }
- public double getPriceWithGlobalVAT(){
- return this.price + (this.price * Bottle.globalVAT);
- }
- public static void main(String[] args) {
- Bottle.globalVAT = .5;
- Bottle water = new Bottle();
- Bottle ouzo = new Bottle();
- ouzo.globalVAT = .2;
- ouzo.periexomeno = "ouzo";
- ouzo.ml = 700;
- ouzo.brand = "Plomari";
- ouzo.price = 9;
- water.periexomeno = "nero";
- water.ml = 500;
- water.brand = "aura";
- water.price = .5;
- water.hasExpired = true;
- System.out.println(water.periexomeno + " with ml " + water.ml);
- water.printMe();
- ouzo.printMe();
- System.out.println(ouzo.getPriceWithGlobalVAT());
- //
- ///
- ///
- //Bottle.globalVAT = .35;
- System.out.println(ouzo.getPriceWithGlobalVAT());
- double taxedPrice = water.getPriceWithVat();
- double taxedPrice2 = water.getPriceWithVat(.31);
- }
- }
- package javaapplication1;
- import java.util.Scanner;
- public class UserInput {
- public static void main(String[] args) {
- Scanner s = new Scanner(System.in);
- String username = s.next();
- String password = s.next();
- int a = Integer.parseInt(s.next());
- double aDouble = s.nextDouble();
- if(username.equals("myusername") && password.equals("mypassword")){
- System.out.println("aniksa");
- }else{
- System.out.println("Lathos kodikos");
- }
- while(true){
- System.out.println("Dwse epilogi");
- System.out.println("1. Gia hello world!\n2. Gia prosthesi\n0. Exit");
- int epilogi = s.nextInt();
- if(epilogi == 1){
- System.out.println("Hello world");
- }else if(epilogi == 2){
- System.out.println("Dwse x");
- int x = s.nextInt();
- System.out.println("Dwse y");
- int y = s.nextInt();
- //System.out.printf("%d + %d = %d\n",x,y,x+y);
- System.out.println(x+"+"+y+"="+(x+y));
- }else if(epilogi ==0 ){
- System.exit(0);
- }else{
- System.out.println("Lathos epilogi");
- }
- }
- }
- }
- /*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
- package javaapplication1;
- /**
- *
- * @author user
- */
- public class Loops {
- public static void main(String[] args) {
- for (int i = 0; i < 10; i++) {
- System.out.println("i = " + i);
- }
- for (int i = 10; i >= 0; i--) {
- System.out.println("i = " + i);
- }
- int i = 0;
- System.out.println("With while:");
- while (i < 10) {
- i++;
- System.out.println("i = " + i);
- }
- i = 0;
- System.out.println("With do{}while();");
- do {
- System.out.println("i = " + i);
- i++;
- } while (i < 10);
- System.exit(0);
- i = 0;
- while (true) {
- System.out.println("i = " + i);
- if (i == 5) {
- System.out.println("stopping");
- break;
- }
- i++;
- }
- }
- }
- /*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
- package javaapplication1;
- /**
- *
- * @author user
- */
- public class IfElse {
- public static void main(String[] args){
- if(1 != 1){
- System.out.println("Hello");
- }else{
- System.out.println("World");
- }
- if(1!=1){//== true
- System.out.println("Hello");
- }else if(1 > 2){
- System.out.println("Hello2");
- }else if(1 < 2){
- System.out.println("Hello3");
- }else{
- System.out.println("World");
- }
- int a = 5;
- int b = 2;
- if (a > b){
- if(a +2 <b){
- System.out.println((a+2) + "<"+b);
- }else{
- System.out.println("something else");
- }
- }
- }
- }
- package javaapplication1;
- public class JavaApplication1 {
- public static void main(String[] args) {
- int onoma = 5;
- double enasArithmos = 5.2;
- char xaraktiras = 'a';
- boolean logical = true;
- boolean logical2 = false;
- String alfarithmitiko = "Hello";
- double x = enasArithmos + 5;
- alfarithmitiko = alfarithmitiko + " World!";
- System.out.println(alfarithmitiko);
- alfarithmitiko = alfarithmitiko + (5 + 5);
- System.out.println(alfarithmitiko);
- System.out.printf("Hello %d %s %.3f \n",5,"World",5.3);
- //System.out.printf("Hello "+5+" %s %.3f");
- double y = 5.6;
- int y2 = 2 + (int)y;
- System.out.println("y2 is "+y2);
- double a = 16;
- double aSqrt = Math.sqrt(a);
- System.out.println("aSqrt = "+ aSqrt);
- double b = 2.6;
- b = Math.floor(b);
- b = Math.ceil(b);
- b = Math.abs(-5);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement