Advertisement
Guest User

Untitled

a guest
Apr 11th, 2019
361
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.16 KB | None | 0 0
  1.  
  2. package javaapplication1;
  3.  
  4. public class Aeroplano {
  5.  
  6. private String company;
  7. private double pricePerTicket;
  8. public static double ekptwsiGiaPitsirikia = .5;
  9. private HumanV3[] passengers;
  10.  
  11. public Aeroplano(String company, double pricePerTicket, int numberOfPassengers) {
  12. this.company = company;
  13. this.pricePerTicket = pricePerTicket;
  14. this.passengers = new HumanV3[numberOfPassengers];
  15. }
  16.  
  17. public boolean addPassenger(int index, HumanV3 passenger) {
  18. if (index > this.passengers.length - 1 || index < 0
  19. || this.passengers[index] != null) {
  20. return false;
  21. } else {
  22. this.passengers[index] = passenger;
  23. return true;
  24. }
  25. }
  26.  
  27. public double getProfit() {
  28. double profit = 0;
  29. for (int i = 0; i < this.passengers.length; i++) {
  30. if (this.passengers[i] != null) {
  31. if (this.passengers[i].getAge() <= 15) {
  32. profit += this.pricePerTicket * (1 - Aeroplano.ekptwsiGiaPitsirikia);
  33. } else {
  34. profit += this.pricePerTicket;
  35. }
  36. }
  37. }
  38. return profit;
  39. }
  40.  
  41. public String toString() {
  42. String tmp = this.company +":\n";
  43. for (int i = 0; i < this.passengers.length; i++) {
  44. if (this.passengers[i] != null) {
  45. tmp += this.passengers[i].toString() +"\n";
  46. }
  47. }
  48. return tmp;
  49. }
  50.  
  51. public String getCompany() {
  52. return company;
  53. }
  54.  
  55. public void setCompany(String company) {
  56. this.company = company;
  57. }
  58.  
  59. public double getPricePerTicket() {
  60. return pricePerTicket;
  61. }
  62.  
  63. public void setPricePerTicket(double pricePerTicket) {
  64. this.pricePerTicket = pricePerTicket;
  65. }
  66.  
  67. }
  68. /*
  69. * To change this template, choose Tools | Templates
  70. * and open the template in the editor.
  71. */
  72. package javaapplication1;
  73.  
  74. /**
  75. *
  76. * @author user
  77. */
  78. public class HumanV3 {
  79. private String name;
  80. private String surname;
  81. private int age;
  82.  
  83. public HumanV3(String name, String surname, int age) {
  84. this.setName(name);
  85. this.setSurname(surname);
  86. this.setAge(age);
  87. }
  88.  
  89. public String getName() {
  90. return name;
  91. }
  92.  
  93. public void setName(String name) {
  94. this.name = name;
  95. }
  96.  
  97. public String getSurname() {
  98. return surname;
  99. }
  100.  
  101. public void setSurname(String surname) {
  102. this.surname = surname;
  103. }
  104.  
  105. public int getAge() {
  106. return age;
  107. }
  108.  
  109. public void setAge(int age) {
  110. this.age = age;
  111. }
  112.  
  113. @Override
  114. public String toString() {
  115. return "HumanV3{" + "name=" + name + ", surname=" + surname + ", age=" + age + '}';
  116. }
  117.  
  118. }
  119. /*
  120. * To change this template, choose Tools | Templates
  121. * and open the template in the editor.
  122. */
  123. package javaapplication1;
  124.  
  125. /**
  126. *
  127. * @author user
  128. */
  129. public class TestHuman2 {
  130. public static void main(String[] args){
  131. Human2 dimi = new Human2();
  132. Human2 gianni = new Human2("Giannis","lalas",25);
  133. Human2 mpampis = new Human2("Mpampis","Flou");
  134. dimi.setSurname("Foo");
  135. System.out.println(dimi);
  136. System.out.println(gianni.getName());
  137. dimi.setName("Dimi");
  138.  
  139. String nameOfDimi = dimi.getName();
  140.  
  141. dimi.setAge(50);
  142. System.out.println(dimi.getAge());
  143. dimi.setAge(-1);
  144. System.out.println(dimi.getAge());
  145. dimi.setAge(150);
  146. System.out.println(dimi.getAge());
  147. //
  148. //
  149.  
  150. }
  151. }
  152. /*
  153. * To change this template, choose Tools | Templates
  154. * and open the template in the editor.
  155. */
  156. package javaapplication1;
  157.  
  158. import java.util.Random;
  159. import java.util.Scanner;
  160.  
  161. /**
  162. *
  163. * @author user
  164. */
  165. public class Arrays {
  166.  
  167. public static void main(String[] args) {
  168. int[] array = new int[10];
  169. Random r = new Random();
  170. for (int i = 0; i < array.length; i++) {
  171. //random integer from 5 to 15;
  172. array[i] = r.nextInt(10) + 5;
  173. }
  174. for (int i = 0; i < array.length; i++) {
  175. //random integer from 0 to 10;
  176. System.out.println(array[i]);
  177. }
  178.  
  179. int[][] array2D = new int[10][10];
  180. for (int i = 0; i < array2D.length; i++) {
  181. for (int j = 0; j < array2D[i].length; j++) {
  182. array2D[i][j] = r.nextInt(50);
  183. }
  184. }
  185.  
  186. int[][] array2Dv2 = new int[10][];
  187. for (int i = 0; i < array2Dv2.length; i++) {
  188. array2Dv2[i] = new int[r.nextInt(50)];
  189. for (int j = 0; j < array2Dv2[i].length; j++) {
  190. array2Dv2[i][j] = r.nextInt(50);
  191. }
  192. }
  193. int sum = 0;
  194. for (int i = 0; i < array2Dv2.length; i++) {
  195. array2Dv2[i] = new int[r.nextInt(50)];
  196. for (int j = 0; j < array2Dv2[i].length; j++) {
  197. sum += array2Dv2[i][j];
  198. }
  199. }
  200. // gemisma apo pliktrologio
  201. Scanner s = new Scanner(System.in);
  202. for (int i = 0; i < array2Dv2.length; i++) {
  203. array2Dv2[i] = new int[r.nextInt(50)];
  204. for (int j = 0; j < array2Dv2[i].length; j++) {
  205. System.out.println("Dwse stixio");
  206. array2Dv2[i][j] = s.nextInt();
  207. }
  208. }
  209. }
  210. }
  211. /*
  212. * To change this template, choose Tools | Templates
  213. * and open the template in the editor.
  214. */
  215. package javaapplication1;
  216.  
  217. /**
  218. *
  219. * @author user
  220. */
  221. public class Human2 {
  222.  
  223. private String name;
  224. private int age;
  225. private String surname;
  226.  
  227. public Human2(){
  228. System.out.println("You called me");
  229. this.age = 1;
  230. this.name = "Junior";
  231. }
  232. public Human2(String name,String surname,int age){
  233. this.name = name;
  234. this.surname = surname;
  235. this.setAge(age);
  236. }
  237. public Human2(String name,String surname){
  238. this.name = name;
  239. this.surname = surname;
  240. }
  241.  
  242. public String getSurname() {
  243. return surname;
  244. }
  245.  
  246. public void setSurname(String surname) {
  247. this.surname = surname;
  248. }
  249.  
  250. public int getAge() {
  251. return this.age;
  252. }
  253.  
  254. public void setAge(int age) {
  255. if (age < 0) {
  256. System.out.println("Not born yet");
  257. } else if (age > 120) {
  258. System.out.println("RIP");
  259. } else {
  260. this.age = age;
  261. }
  262. }
  263.  
  264. public String getName() {
  265. return this.name;
  266. }
  267.  
  268. public void setName(String name) {
  269. if (name.length() < 50) {
  270. this.name = name;
  271. }
  272. }
  273.  
  274. @Override
  275. public String toString() {
  276. return "Human2{" + "name=" + name + ", age=" + age + ", surname=" + surname + '}';
  277. }
  278.  
  279.  
  280. }
  281. /*
  282. * To change this template, choose Tools | Templates
  283. * and open the template in the editor.
  284. */
  285. package javaapplication1;
  286.  
  287. public class Human {
  288.  
  289. String name;
  290. String surname;
  291. int age;
  292. static int numberOfEyes = 2;
  293.  
  294. public static double sum(double x, double y){
  295. return x +y;
  296. }
  297. public static void mutate(int eyes){
  298. // surname = "hello"; LATHOS einai idiotita stigmiotipou
  299. Human.numberOfEyes = eyes;
  300. //Human.numberOfEyes = (int)Human.sum(eyes,1);
  301. }
  302. public static void main(String[] args){
  303. double mySum = Human.sum(5, 6);
  304. System.out.println(mySum);
  305. Human a = new Human();
  306. Human b = new Human();
  307. a.name = "Giannis";
  308. a.surname = "Lala";
  309. b.name = "Mpampis";
  310. b.surname = "Flou";
  311.  
  312. System.out.println(a.name + " I've got "+ a.numberOfEyes + " eyes" );
  313. Human.mutate(3);
  314. //a.numberOfEyes = 3;
  315. System.out.println(b.name + " I've got "+ b.numberOfEyes + " eyes" );
  316. System.out.println(a.name + " I've got "+ a.numberOfEyes + " eyes" );
  317. }
  318. }
  319. /*
  320. * To change this template, choose Tools | Templates
  321. * and open the template in the editor.
  322. */
  323. package javaapplication1;
  324.  
  325. /**
  326. *
  327. * @author user
  328. */
  329. public class Bottle {
  330. static double globalVAT = .24;
  331.  
  332. String periexomeno;
  333. int ml;
  334. String brand;
  335. double price;
  336. boolean hasExpired;
  337.  
  338. public void printMe() {
  339. System.out.println("My content is " + this.periexomeno);
  340. System.out.println("and I've got " + this.ml + "ml");
  341. }
  342.  
  343. public double getPriceWithVat() {
  344. return this.price + (this.price * .24);
  345. }
  346. public double getPriceWithVat(double vat){
  347. return this.price + (this.price * vat);
  348. }
  349. public double getPriceWithGlobalVAT(){
  350. return this.price + (this.price * Bottle.globalVAT);
  351. }
  352.  
  353.  
  354.  
  355.  
  356.  
  357.  
  358. public static void main(String[] args) {
  359. Bottle.globalVAT = .5;
  360. Bottle water = new Bottle();
  361. Bottle ouzo = new Bottle();
  362. ouzo.globalVAT = .2;
  363. ouzo.periexomeno = "ouzo";
  364. ouzo.ml = 700;
  365. ouzo.brand = "Plomari";
  366. ouzo.price = 9;
  367. water.periexomeno = "nero";
  368. water.ml = 500;
  369. water.brand = "aura";
  370. water.price = .5;
  371. water.hasExpired = true;
  372.  
  373. System.out.println(water.periexomeno + " with ml " + water.ml);
  374.  
  375. water.printMe();
  376. ouzo.printMe();
  377. System.out.println(ouzo.getPriceWithGlobalVAT());
  378. //
  379. ///
  380. ///
  381. //Bottle.globalVAT = .35;
  382. System.out.println(ouzo.getPriceWithGlobalVAT());
  383. double taxedPrice = water.getPriceWithVat();
  384. double taxedPrice2 = water.getPriceWithVat(.31);
  385.  
  386. }
  387. }
  388.  
  389. package javaapplication1;
  390. import java.util.Scanner;
  391.  
  392. public class UserInput {
  393.  
  394. public static void main(String[] args) {
  395. Scanner s = new Scanner(System.in);
  396. String username = s.next();
  397. String password = s.next();
  398. int a = Integer.parseInt(s.next());
  399. double aDouble = s.nextDouble();
  400. if(username.equals("myusername") && password.equals("mypassword")){
  401. System.out.println("aniksa");
  402. }else{
  403. System.out.println("Lathos kodikos");
  404. }
  405.  
  406. while(true){
  407. System.out.println("Dwse epilogi");
  408. System.out.println("1. Gia hello world!\n2. Gia prosthesi\n0. Exit");
  409. int epilogi = s.nextInt();
  410. if(epilogi == 1){
  411. System.out.println("Hello world");
  412. }else if(epilogi == 2){
  413. System.out.println("Dwse x");
  414. int x = s.nextInt();
  415. System.out.println("Dwse y");
  416. int y = s.nextInt();
  417. //System.out.printf("%d + %d = %d\n",x,y,x+y);
  418. System.out.println(x+"+"+y+"="+(x+y));
  419. }else if(epilogi ==0 ){
  420. System.exit(0);
  421. }else{
  422. System.out.println("Lathos epilogi");
  423. }
  424. }
  425.  
  426. }
  427. }
  428. /*
  429. * To change this template, choose Tools | Templates
  430. * and open the template in the editor.
  431. */
  432. package javaapplication1;
  433.  
  434. /**
  435. *
  436. * @author user
  437. */
  438. public class Loops {
  439.  
  440. public static void main(String[] args) {
  441. for (int i = 0; i < 10; i++) {
  442. System.out.println("i = " + i);
  443. }
  444.  
  445. for (int i = 10; i >= 0; i--) {
  446. System.out.println("i = " + i);
  447. }
  448. int i = 0;
  449. System.out.println("With while:");
  450. while (i < 10) {
  451. i++;
  452.  
  453. System.out.println("i = " + i);
  454. }
  455. i = 0;
  456. System.out.println("With do{}while();");
  457. do {
  458. System.out.println("i = " + i);
  459. i++;
  460. } while (i < 10);
  461.  
  462.  
  463. System.exit(0);
  464.  
  465. i = 0;
  466. while (true) {
  467. System.out.println("i = " + i);
  468. if (i == 5) {
  469. System.out.println("stopping");
  470. break;
  471. }
  472. i++;
  473. }
  474.  
  475.  
  476.  
  477. }
  478. }
  479. /*
  480. * To change this template, choose Tools | Templates
  481. * and open the template in the editor.
  482. */
  483. package javaapplication1;
  484.  
  485. /**
  486. *
  487. * @author user
  488. */
  489. public class IfElse {
  490. public static void main(String[] args){
  491. if(1 != 1){
  492. System.out.println("Hello");
  493. }else{
  494. System.out.println("World");
  495. }
  496.  
  497.  
  498. if(1!=1){//== true
  499. System.out.println("Hello");
  500. }else if(1 > 2){
  501. System.out.println("Hello2");
  502. }else if(1 < 2){
  503. System.out.println("Hello3");
  504. }else{
  505. System.out.println("World");
  506. }
  507.  
  508.  
  509. int a = 5;
  510. int b = 2;
  511. if (a > b){
  512. if(a +2 <b){
  513. System.out.println((a+2) + "<"+b);
  514. }else{
  515. System.out.println("something else");
  516. }
  517. }
  518.  
  519.  
  520.  
  521. }
  522. }
  523. package javaapplication1;
  524.  
  525. public class JavaApplication1 {
  526.  
  527. public static void main(String[] args) {
  528. int onoma = 5;
  529. double enasArithmos = 5.2;
  530. char xaraktiras = 'a';
  531. boolean logical = true;
  532. boolean logical2 = false;
  533. String alfarithmitiko = "Hello";
  534.  
  535. double x = enasArithmos + 5;
  536.  
  537. alfarithmitiko = alfarithmitiko + " World!";
  538.  
  539. System.out.println(alfarithmitiko);
  540. alfarithmitiko = alfarithmitiko + (5 + 5);
  541. System.out.println(alfarithmitiko);
  542.  
  543. System.out.printf("Hello %d %s %.3f \n",5,"World",5.3);
  544. //System.out.printf("Hello "+5+" %s %.3f");
  545. double y = 5.6;
  546. int y2 = 2 + (int)y;
  547. System.out.println("y2 is "+y2);
  548.  
  549. double a = 16;
  550. double aSqrt = Math.sqrt(a);
  551. System.out.println("aSqrt = "+ aSqrt);
  552. double b = 2.6;
  553. b = Math.floor(b);
  554. b = Math.ceil(b);
  555. b = Math.abs(-5);
  556.  
  557.  
  558.  
  559.  
  560.  
  561.  
  562.  
  563.  
  564.  
  565.  
  566.  
  567.  
  568.  
  569.  
  570. }
  571. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement