why java compiles but not run? -
so made program creates list of ships , creates menu can insert details of ships (such name, length, etc.).
class testvessel { public static void main(string args[]) { string name,idioktname,skafos,temp1; double length,width,ektopisma,maxspeed,max,ektop; int etos,epilogh,size=0,thesi,i=0,o,a,year; boolean shmaia=false,flag; vessel[] skafoi=new vessel[10]; for(;shmaia;) { system.out.println("lista epilogwn"); system.out.println("1.eisagwgh stoixeiwn skafous"); system.out.println("2.emfanish stoixeiwn skafous"); system.out.println("3.emfanish oloklhrou tou pinaka"); system.out.println("4.telos"); system.out.println("dwste epilogh(1-4):"); epilogh=userinput.getinteger(); if(epilogh==4)shmaia=true; switch(epilogh) { case 1 : system.out.println("dwste onoma skafous:"); name=userinput.getstring(); system.out.println("dwste mhkos:"); flag=true; length=0; for(;flag;) { length=userinput.getdouble(); if(length>=0 && length<=1000)flag=false; else system.out.println("mh apodekta oria xanadokimaste"); } system.out.println("dwste platos:"); width=userinput.getdouble(); system.out.println("dwste ektopisma:"); flag=true; ektopisma=0; for(;flag;) { ektopisma=userinput.getdouble(); if(ektopisma>=0 && ektopisma<=150000)flag=false; else system.out.println("mh apodekta oria xanadokimaste"); } system.out.println("dwste etos kataskeuhs:"); etos=userinput.getinteger(); system.out.println("dwste megisth taxhtyta:"); maxspeed=userinput.getdouble(); system.out.println("dwste onoma idioktith:"); idioktname=userinput.getstring(); skafoi[i]=new vessel(name,length,width,ektopisma,etos,maxspeed,idioktname); i++; size++; break; case 2 : if(size!=0) system.out.println("epilogh pediou anazhthshs"); system.out.println("1.onoma skafous"); system.out.println("2.etos kataskeuhs"); system.out.println("3.ektopisma"); system.out.println("4.megisto mhkos skafous"); system.out.println("5.epistrodh sthn arxikh lista epilogwn"); system.out.println("dwste epilogh(1-5):"); epilogh=userinput.getinteger(); switch(epilogh) { case 1: myutils.epiloghmethodou(); epilogh=userinput.getinteger(); switch(epilogh) { case 1: system.out.println("dwste onoma skafous"); skafos=userinput.getstring(); thesi=myutils.seqsearch(skafoi,skafos); system.out.println(skafoi[thesi].emfanisholwn()); break; case 2: system.out.println("dwste onoma skafous"); skafos=userinput.getstring(); thesi=myutils.binsearch(skafoi,skafos,size); system.out.println(skafoi[thesi].emfanisholwn()); break; case 3: break; default: system.out.print("\n\tlathos epilogi methodou ... eisagete ari8mo 1-3\n"); }break; case 2: myutils.epiloghmethodou(); epilogh=userinput.getinteger(); switch(epilogh) { case 1: system.out.println("dwste etos kataskeuhs"); year=userinput.getinteger(); myutils.seqsearch(skafoi,year,size); break; case 2: system.out.println("dwste etos kataskeuhs"); year=userinput.getinteger(); myutils.binsearch(skafoi,year,size); break; case 3: break; default: system.out.print("\n\tlathos epilogi methodou ... eisagete ari8mo 1-3\n"); }break; case 3: myutils.epiloghmethodou(); epilogh=userinput.getinteger(); switch(epilogh) { case 1: system.out.println("dwste ektopisma"); ektop=userinput.getdouble(); myutils.seqsearch(skafoi,ektop,size); break; case 2: system.out.println("dwste ektopisma"); ektop=userinput.getdouble(); myutils.binsearch(skafoi,ektop,size); break; case 3: break; default: system.out.print("\n\tlathos epilogi methodou ... eisagete ari8mo 1-3\n"); }break; case 4: myutils.epiloghmethodou(); epilogh=userinput.getinteger(); max=0; a=0; switch(epilogh) { case 1: myutils.seqsearch(skafoi,max,size,a); system.out.println("h max taxhthta einai:"+max); break; case 2: myutils.binsearch(skafoi,max,size); system.out.println("h max taxhthta einai:"+max); break; case 3: break; default: system.out.print("\n\tlathos epilogi methodou ... eisagete ari8mo 1-3\n"); } case 5: break; default: system.out.print("\n\tlathos epilogi methodou ... eisagete ari8mo 1-5\n"); } if(size==0)system.out.println("den uparxoun skafoi sth lista"); break; case 3: if(size!=0) {for(i=0;i<=size;i++) { system.out.println(skafoi[i].emfanisholwn()); } } if(size==0) {system.out.println("den uparxoun skafoi sth lista");} break; case 4: system.out.println("telos programmatos"); break; default: system.out.print("\n\tlathos epilogi methodou ... eisagete ari8mo 1-4\n"); } } } } class myutils { public static void seqsearch(vessel[] a,int key,int size) { int x=0; for(int i=0;i<=size;i++) if(a[i].getetos()==key) {system.out.println(a[i].emfanisholwn()); x++;} if(x==0)system.out.println("den uparxoun skafoi autou tou etous"); } public static int seqsearch(vessel[] a,string key) { for(int i=0;i<a.length;i++) if(a[i].getname()==key) return i; return -1; } public static void seqsearch(vessel[] a,double key,int size) { int x=0; for(int i=0;i<=size;i++) if(a[i].getektopisma()==key) {system.out.println(a[i].emfanisholwn()); x++;} if(x==0)system.out.println("den uparxoun skafoi me tetoio ektopisma"); } public static void seqsearch(vessel[] a,double max,int size,int l) { l=0; max=0; for(int i=0;i<=size;i++) if(a[i].getmaxspeed()>max)max=a[i].getmaxspeed(); } public static int binsearch(vessel[] a,string key,int size) { int left=0,right=size-1; return binarysearch(a,key,left,right); } private static int binarysearch(vessel[] numbers,string key,int left,int right) { int mid,pos=-1; while(pos==-1 && left<=right) { mid=(left+right)/2; if(numbers[mid].getname().compareto(key)>0) right=mid-1; else if(numbers[mid].getname().compareto(key)<0) left=mid+1; else pos=mid; } return pos; } public static void binsearch(vessel[] a,int key,int size) { int left=0,right=size-1; for(int i=0;i<=size;i++) if(a[i].getetos()==a[binarysearch(a,key,left,right)].getetos())system.out.println(a[i].emfanisholwn()); } private static int binarysearch(vessel[] numbers,int key,int left,int right) { int mid,pos=-1; while(pos==-1 && left<=right) { mid=(left+right)/2; if(key<numbers[mid].getetos()) right=mid-1; else if(key>numbers[mid].getetos()) left=mid+1; else pos=mid; } return pos; } public static void binsearch(vessel[] a,double key,int size) { int left=0,right=size-1; for(int i=0;i<=size;i++) if(a[i].getektopisma()==a[binarysearch(a,key,left,right)].getektopisma())system.out.println(a[i].emfanisholwn()); } private static int binarysearch(vessel[] numbers,double key,int left,int right) { int mid,pos=-1; while(pos==-1 && left<=right) { mid=(left+right)/2; if(key<numbers[mid].getektopisma()) right=mid-1; else if(key>numbers[mid].getektopisma()) left=mid+1; else pos=mid; } return pos; } public static void epiloghmethodou() { system.out.println("epilogh methodou anazhthshs"); system.out.println("1.seiriakh anazhthsh"); system.out.println("2.duadiki anazhthsh"); system.out.println("3.epistrofh sthn epilogh pediou anazhthshs"); system.out.println("dwste epilogh(1-3):"); } } class vessel { private string name; private double length; private double width; private double ektopisma; private int etos; private double maxspeed; private string idiokname; vessel(string n,double l,double w,double e,int et,double ms,string cn) { name=n; length=l; width=w; ektopisma=e; etos=et; maxspeed=ms; idiokname=cn; } public string getname() { return name; } public double getlength() { return length; } public double getwidth() { return width; } public double getektopisma() { return ektopisma; } public int getetos() { return etos; } public double getmaxspeed() { return maxspeed; } public string getidiokname() { return idiokname; } public string emfanisholwn() { string tostring=("to onoma einai:"+name); tostring+=("to mhkos einai:"+length); tostring+=("to platos einai:"+width); tostring+=("to ektopisma einai:"+ektopisma); tostring+=("to etos einai:"+etos); tostring+=("h megisth taxhtyta einai:"+maxspeed); tostring+=("to onoma tou idiokthth einai:"+idiokname); return tostring; } }
so...the program compiles, when try run it, doesn't work expected or throw exceptions.
you go main loop if shmaia
true. set false. main loop never executed , program nothing.
Comments
Post a Comment