Last active
December 10, 2015 06:03
-
-
Save edinak1/05ea618f7a23b89dc69c 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
package birds; | |
import java.util.Arrays; | |
public class Birds { | |
static int size=1; | |
static int counterEmtyLine=size; | |
static String birds[][]=new String[size][]; | |
final static int NAME=0; | |
final static int NUMBER_BIRDS=1; | |
final static int COST_PRICE=2; | |
final static int FINAL_PRICE=3; | |
final static int NUMBER_SALE=4; | |
final static int SIZE=5; | |
public static void main(String[] args) { | |
init(); | |
printAllStatistics(); | |
printSaleStatistic("kalibri"); | |
printPriceStatistic("ostrich"); | |
printSaleAllBirds(); | |
printNumberBirdStatistic("kalibri"); | |
lessThree(); | |
profitStatistic(); | |
buyBirds("eagle",50); | |
saleBirds("penguin",30); | |
buyBirds("ostrich",50); | |
buyBirds("kakadu",40); | |
changeFinalPrice("kakadu",25); | |
changeCostPrice("kakadu",10); | |
printAllStatistics(); | |
profitStatistic(); | |
} | |
//////////////////////////////////////////////////////////////////// | |
static void bigestBirds() | |
{ | |
size*=2; | |
String [][]bigestBirds=new String [size][]; | |
for(int i=0;i<birds.length;i++) | |
{ | |
bigestBirds[i]=new String [SIZE]; | |
for(int j=0;j<bigestBirds[i].length;j++) | |
{ | |
bigestBirds[i][j]=birds[i][j]; | |
} | |
} | |
counterEmtyLine=size/2; | |
birds=bigestBirds; | |
} | |
///////////////////////////////////////////////////////////////////// | |
static void init() | |
{ | |
init("ostrich","2","5","10","10"); | |
init("penguin","50","10","20","3"); | |
init("kalibri","51","7","14","2"); | |
init("eagle","0","5","10","50"); | |
} | |
///////////////////////////////////////////////////////////////////// | |
static void init(String nameBird,String numberBird,String costPrice,String finalPrice,String namberSale) | |
{ | |
birds[findEmty()]=new String[]{nameBird,numberBird,costPrice,finalPrice,namberSale}; | |
counterEmtyLine--; | |
if(counterEmtyLine==0) | |
{ | |
bigestBirds(); | |
} | |
} | |
///////////////////////////////////////////////////////////////////// | |
static int findEmty() | |
{ | |
for(int i=0;i<size;i++) | |
if(birds[i]==null) | |
return i; | |
return -1; | |
} | |
///////////////////////////////////////////////////////////////////// | |
static void printAllStatistics() | |
{ | |
System.out.println("_________________________________________________________________________________________"); | |
System.out.println("Kind of bird || number of bird || cost price || final price || number of sale ||"); | |
System.out.println("_________________________________________________________________________________________"); | |
for(int i=0;i<birds.length-counterEmtyLine;i++) | |
{ | |
for(int j=0;j<birds[i].length;j++) | |
{ | |
if(birds[i][j]!=null) | |
{ | |
System.out.print(birds[i][j]); | |
for(int k=0;k<14-birds[i][j].length();k++) | |
{ | |
System.out.print(" "); | |
} | |
System.out.print(" || "); | |
} | |
} | |
System.out.println(); | |
System.out.println("_________________________________________________________________________________________"); | |
} | |
} | |
///////////////////////////////////////////////////////////////////// | |
static void printSaleStatistic(String nameBird) | |
{ | |
if(finderBird(nameBird)==-1) | |
System.out.println("This kind of birds is not found"); | |
else | |
System.out.println("Number of sold "+nameBird+" : "+birds[finderBird(nameBird)][4]); | |
} | |
///////////////////////////////////////////////////////////////////// | |
static void printPriceStatistic(String nameBird) | |
{ | |
if(finderBird(nameBird)==-1) | |
System.out.println("This kind of birds is not found"); | |
else | |
System.out.println("Price of "+nameBird+" : "+birds[finderBird(nameBird)][3]); | |
} | |
///////////////////////////////////////////////////////////////////// | |
static void printSaleAllBirds() | |
{ | |
for(int i=0;i<size;i++) | |
if(birds[i]!=null) | |
System.out.println("Number of sold "+birds[i][0]+" : "+birds[i][4]); | |
} | |
///////////////////////////////////////////////////////////////////// | |
static int finderBird(String nameBird) | |
{ | |
for(int i=0;i<size;i++) | |
if(birds[i]!=null && birds[i][NAME]==nameBird) | |
return i; | |
return -1; | |
} | |
///////////////////////////////////////////////////////////////////// | |
static void printNumberBirdStatistic(String nameBird) | |
{ | |
if(finderBird(nameBird)==-1) | |
System.out.println("This kind of birds is not found"); | |
else | |
System.out.println("Number of "+nameBird+" : "+birds[finderBird(nameBird)][1]); | |
} | |
///////////////////////////////////////////////////////////////////// | |
static void lessThree() | |
{ | |
System.out.println("It has less than three pieces :"); | |
for(int i=0;i<birds.length;i++) | |
if(birds[i]!=null && Integer.valueOf(birds[i][NUMBER_BIRDS])<3) | |
System.out.println(birds[i][NAME]); | |
} | |
///////////////////////////////////////////////////////////////////// | |
static void buyBirds(String nameBird,int numberBirds) | |
{ | |
if(finderBird(nameBird)==-1) | |
{ | |
init(nameBird,"0","10","20","0"); | |
} | |
birds[finderBird(nameBird)][NUMBER_BIRDS]=String.valueOf(numberBird(nameBird)+numberBirds); | |
} | |
///////////////////////////////////////////////////////////////////// | |
static void saleBirds(String nameBird,int numberBirds) | |
{ | |
if(finderBird(nameBird)==-1 || numberBird(nameBird)<numberBirds) | |
{ | |
System.out.println("Sale is impossible"); | |
return; | |
} | |
birds[finderBird(nameBird)][NUMBER_BIRDS]=String.valueOf(numberBird(nameBird)-numberBirds); | |
birds[finderBird(nameBird)][NUMBER_SALE]=String.valueOf(saleBird(nameBird)+numberBirds); | |
System.out.println("The sale took place"); | |
} | |
///////////////////////////////////////////////////////////////////// | |
static int numberBird(String nameBird) | |
{ | |
if(finderBird(nameBird)==-1) | |
return-1; | |
return Integer.valueOf(birds[finderBird(nameBird)][NUMBER_BIRDS]); | |
} | |
///////////////////////////////////////////////////////////////////// | |
static int saleBird(String nameBird) | |
{ | |
if(finderBird(nameBird)==-1) | |
return-1; | |
else | |
return Integer.valueOf(birds[finderBird(nameBird)][NUMBER_SALE]); | |
} | |
///////////////////////////////////////////////////////////////////// | |
static void changeFinalPrice(String nameBird, int price) | |
{ | |
if(finderBird(nameBird)==-1) | |
System.out.println("This kind of birds is not found"); | |
else | |
birds[finderBird(nameBird)][FINAL_PRICE]=String.valueOf(price); | |
} | |
///////////////////////////////////////////////////////////////////// | |
static void changeCostPrice(String nameBird, int price) | |
{ | |
if(finderBird(nameBird)==-1) | |
System.out.println("This kind of birds is not found"); | |
else | |
birds[finderBird(nameBird)][COST_PRICE]=String.valueOf(price); | |
} | |
///////////////////////////////////////////////////////////////////// | |
static void profitStatistic() | |
{ | |
int sum=0; | |
for(int i=0;i<birds.length-counterEmtyLine;i++) | |
{ | |
sum+=(Integer.valueOf(birds[i][FINAL_PRICE])*Integer.valueOf(birds[i][NUMBER_SALE])- | |
Integer.valueOf(birds[i][COST_PRICE])*(Integer.valueOf(birds[i][NUMBER_BIRDS]+Integer.valueOf(birds[i][NUMBER_SALE])))); | |
} | |
System.out.println("Profit is : "+sum); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment