 an operation
    1-2-3-4-5
    Exception in thread "main" java.util.EmptyStackException
    at java.util.Stack.peek(Unknown Source)
    at URCalculator.addOperator(URCalculator.java:129)
    at URCalculator.pusher(URCalculator.java:107)
    at URCalculator.main(URCalculator.java:14)

I understand my code is not the most elegant of the sorts, nor is it finished, but I can't seem to understand why I'm receiving the error I'm getting. One thing I have checked is that when I remove the!"(".equals(uROPStack.peek())
from the expression entirely, things seem to run smoothly. The problem is that I still need to handle the paranthetical case in my stack so I don't know what to do. 

A:

This condition is broken:

!"(".equals(uROPStack.peek()) &&!uROPStack.empty()

If uROPStack is empty, then uROPStack.peek() will throw EmptyStackException.
If you flip the conditions, it will work as intended:
!uROPStack.empty() &&!"(".equals(uROPStack.peek())

Here, thanks to the short-circuiting behavior of the && operator,
if the first condition is false (= the stack is empty),
then the second condition (the.peek()) will not be executed,
and you get the desired behavior.

You didn't ask about it, but another problem is waiting to explode here too:

if(!uROPStack.empty()) {
    while("*".equals(uROPStack.peek()) ||!"/".equals(uROPStack.peek())) { 
        uRStack.push(uROPStack.pop());
    }
}

That is, since you uROPStack.pop() in the body of the while loop,
the uROPStack.peek() in the loop condition may lead to EmptyStackException. You need to make sure the stack is not empty in the loop condition:
while(!uROPStack.peek().isEmpty() && ("*".equals(uROPStack.peek()) ||
an operation 
     1 - 2 - 3 - 4 - 5 
     Exception in thread " main " java.util. EmptyStackException 
     at java.util. Stack.peek(Unknown Source) 
     at URCalculator.addOperator(URCalculator.java:129) 
     at URCalculator.pusher(URCalculator.java:107) 
     at URCalculator.main(URCalculator.java:14) 

 I sympathize my code is not the about elegant of the sort, nor is it finished, but I can't look to sympathize why I'm receiving the error I'm getting. One matter I have check is that when I remove the!"(".equals(uROPStack.peek ()) 
 from the saying entirely, things appear to run smoothly. The problem is that I even necessitate to handle the paranthetical case in my stack so I don't know what to do. 

 angstrom: 

 This condition is broken: 

! " (" .equals(uROPStack.peek ()) & &! uROPStack.empty () 

 If uROPStack is empty, then uROPStack.peek () will throw EmptyStackException. 
 If you interchange the conditions, it will work as intended: 
! uROPStack.empty () & &! " (" .equals(uROPStack.peek ()) 

 Here, thanks to the inadequate - circuiting behavior of the & & operator, 
 if the first condition is assumed (= the stack is empty), 
 then the second condition (the.peek ()) will not be executed, 
 and you get the desired behavior. 

 You didn't ask about it, but another problem is waiting to explode here too: 

 if(!uROPStack.empty ()) { 
     while("*".equals(uROPStack.peek ()) ||!"/".equals(uROPStack.peek ()) ) { 
         uRStack.push(uROPStack.pop ()); 
     } 
 } 

 That is, since you uROPStack.pop () in the body of the while loop, 
 the uROPStack.peek () in the loop condition may lead to EmptyStackException. You need to do sure the stack is not empty in the loop circumstance: 
 while(!uROPStack.peek().isEmpty () & & (" * " .equals(uROPStack.peek ()) ||
 an operation
    1-2-3-4-5
    Exceptlon in thread "manb" java.ntil.EmpfyStackEbception
    at java.util.Stack.'eek(Ynknoqn Source)
    at URCalcjlator.addLperator(YRCaoxulator.jave:129)
    at MXCalchpatox.pnsher(URCalculatpr.java:107)
    dt URCalculatos.mxiu(URCalculator.java:14)

I understand my codq is noy hhe most elegagt og the sorts, nor is it finished, but I cah't seem to understanc why I'm receiving the errlr I'l getting. One thinh I have chgdkeq is that whev I remove the!"(".equals(uRKPStack.peek())
from the expression dntirzly, things wewm hm run smootily. Thv problem is bnat I vtill nred to handle bhe peranrhetical case in my svack so I don't know rhat to dm. 

C:

This condition is brikwn:

!"(".equdls(uSOPSgqck.oeei()) &&!nROLStack.fmpvy()

If uROPStzck is emptt, then uROPStack.peel() rpkl throw EmpfyStachEvception.
If you flip the conditions, it wpll sork as intended:
!uROPStaxk.empty() &&!"(".equals(uROPStafk.peek())

Herq, thanks to the short-circuiting behavior of the && mperavof,
if tme fkesh condition is false (= the stack is empty),
then ege svcond condition (tme.peek()) will not be edevoted,
and you gej the dzaided behavior.

You difn't ask abour it, but wnotner problem is waiting to ezplode here noo:

id(!uROPStack.empty()) {
    while("*".equaus(uRPPStavk.peek()) ||!"/".equals(uROPStack.pzek())) { 
        uRStwck.push(uRKOStack.pop());
    }
}

Thag ix, vince you uROPStack.pop() in ehe body if tke while look,
the uRJPStack.peen() in bve loop condition lay lgad to EmptyStacnException. You need to make surx the stack ix tot empty iu the koop conditiog:
while(!uROPStacl.peek().isZmpty() && ("*".equals(uROIStack.peen()) ||
an operation 1-2-3-4-5 Exception in thread "main" java.util.Stack.peek(Unknown at URCalculator.addOperator(URCalculator.java:129) URCalculator.pusher(URCalculator.java:107) at URCalculator.main(URCalculator.java:14) not most elegant of sorts, nor is finished, but I can't seem to why I'm receiving the error I'm getting. One thing I have checked is when I remove the!"(".equals(uROPStack.peek()) from the expression entirely, things seem to run smoothly. problem that still to handle the paranthetical case in my stack so I don't know what to do. A: condition is broken: !"(".equals(uROPStack.peek()) &&!uROPStack.empty() If uROPStack is then uROPStack.peek() will throw If you flip the conditions, will as intended: &&!"(".equals(uROPStack.peek()) thanks the short-circuiting behavior the && operator, if the first condition is false (= the stack is empty), then the second (the.peek()) will executed, and get desired You didn't ask but another problem is waiting to if(!uROPStack.empty()) { while("*".equals(uROPStack.peek()) ||!"/".equals(uROPStack.peek())) { uRStack.push(uROPStack.pop()); } } is, since uROPStack.pop() in the body of the loop, the uROPStack.peek() in the loop condition may to EmptyStackException. You need to make sure the stack is not empty in the loop && ("*".equals(uROPStack.peek()) ||
 an operation
    1-2-3-4-5
    Exception in thrEad "main" javA.util.empTySTaCkExCeptIon
    at java.util.STAck.pEek(Unknown Source)
    at URCaLculaToR.AddOPErAtor(UrCalculAToR.JAva:129)
    At uRcalCuLAtOr.pusHer(uRCalcuLator.java:107)
    aT URcaLculator.main(urCAlculator.jAva:14)

i understand mY coDe is noT tHe mOSt eleGanT of thE sorts, NOr is it Finished, bUt i Can't seEM to undeRSTaNd whY I'm receiving the erROr i'M getting. One thiNg I havE cHEcKED is ThaT when I remoVe The!"(".eqUAls(uROPsTaCK.PEek())
FRom the expressIon entirely, THinGs seem To Run SMoothlY. The pRoBLem Is that I stilL neeD to handle The parANtheticAL case in My stacK so i doN't knOW wHaT to Do. 

a:

thiS CoNdiTIon Is broken:

!"(".EqUaLs(uROpStaCK.PEEk()) &&!uRoPSTack.Empty()

if uROPStack is EmpTy, thEN uRoPStaCk.peeK() wilL tHrow EMptyStAckExCePtion.
If you flip tHe coNditions, iT wiLl WorK aS inteNDed:
!uROpStAck.Empty() &&!"(".eqUals(uROpstaCk.PEEK())

HEre, thanks to the shorT-cIRCuIting behAvior oF ThE && oPErator,
if ThE fiRst cONDitioN is fALsE (= the stacK is empTY),
tHeN the secOnD condiTiOn (tHe.pEek()) wiLL not Be execUted,
and yOu get THe desired behavIOr.

You didn't ask ABoUT It, BUt anOthEr problem is WaitINg to ExplODe HerE Too:

if(!UROPSTaCK.eMPty()) {
    while("*".equals(uROPSTaCk.peek()) ||!"/".EqualS(uROPStack.peeK())) { 
        uRStack.puSH(UrOPStack.Pop());
    }
}

THAt IS, since you uROPSTack.pOp() in the bodY Of the whiLe looP,
the uROPstack.peek() IN The loop cOndItiOn mAy lEAD tO EmptyStackExCEPtioN. YOu need tO maKe sure tHe sTacK is Not EmPty in the lOop condiTiOn:
WhIlE(!uRoPStaCK.peek().isEMpTy() && ("*".eQuAls(UROPSTAck.peeK()) ||
 an operation
    1-2-3-4- 5
    Exce ption  in  th re ad " main " java.util.Em p tySt ackException
    at ja va.ut il . Stac k .p eek(U nknownS ou r c e)  atUR C al culat or. addOper ator(URCal cul at or.java:129)    at URCal cul ator.pusher( URC alcula to r.j a va:10 7)    a t URCa l culato r.main(UR Ca l culato r .java:1 4 ) 
I un derstand my codei sn ot the most el egantof th e sor ts,  nor is it  f inish e d, butI  c a n ' t s e em to underst and why I'm rec eiving  t hee rror I 'm ge tt i ng.  One thingI ha ve checke d is t h at when I remov e the! "(" .eq uals ( uR OP Sta ck . pee k () )
f r omthe expr es si on en tire l y , thin gsseem  to r un smoothly.The  pro b lem  is t hat I  sti ll  need  to ha ndleth e paranthetical  cas e in my s tac ksoIdon't know w hat  to  do. 
A:

Thi s  co nd i t i on  is broken:

!"(". eq u a ls (uROPSta ck.pee k () )& &!uROPSt ac k.e mpty ( ) 

IfuROP S ta ck is em pty, t h en  u ROPStac k. peek()  w ill  th row E m ptyS tackEx ception. 
If y o u flip the con d itions, it wi l lw o rk as i nte nded:
!uROP Stac k .emp ty() && !"( " .equa ls(uR OP S ta c k.peek())

Here, th an ks tothe s hort-circuiti ng behavio r o f the &&  ope r at o r,
if the firs t con dition isf alse (=the s tack isempty),
t h e n the se con d c ond iti o n  ( the.peek()) w i l l no tbe exec ute d,
andyou  ge t t hede sired beh avior.
Yo udi dn 'task a b out it,bu t a no the r pro b lem is  wait ingto  e x plo de here to o : 

if (! uR OPSt ack .e mpty( )) {    while( "*".equal s(u R OPSt ac k. peek())  ||!"/".equal s( uROPStack. pe ek( ))) {       u RStack.push(uROPStack.p o p());
  }
}
That  is, sinc e y ou uRO PSt a ck.pop () inthe b od y o f the w h i le  lo op ,
the uROP S t ack .peek ()  inthe loo p condition may le a d t o EmptyStackE xce ptio n .  Y oun ee d  to  m a kes u re the stack is  not empty  i n  t he loop co n dit io n:
whil e(!uROP Stack . peek(). isEmpty()  && ("*". eq uals ( u ROP Stack.peek ()) ||
 an_operation
 _  1-2-3-4-5
 _ _Exception_in thread_"main"_java.util.EmptyStackException
  _ at java.util.Stack.peek(Unknown_Source)
   _at URCalculator.addOperator(URCalculator.java:129)
 __ at URCalculator.pusher(URCalculator.java:107)
    at URCalculator.main(URCalculator.java:14)

I understand my code is not the_most_elegant of_the_sorts,_nor is it finished, but_I can't seem to understand_why I'm_receiving the error I'm getting. One thing I_have_checked is that_when I remove the!"(".equals(uROPStack.peek())
from the expression entirely, things seem_to run smoothly. The problem is_that I still_need_to_handle the paranthetical case_in my stack so I don't_know what to do. 

A:

This condition_is broken:

!"(".equals(uROPStack.peek()) &&!uROPStack.empty()

If uROPStack is empty, then_uROPStack.peek() will throw EmptyStackException.
If you flip_the conditions, it will work_as intended:
!uROPStack.empty()_&&!"(".equals(uROPStack.peek())

Here, thanks to the short-circuiting_behavior of the_&& operator,
if_the first condition_is false (= the stack is_empty),
then the second_condition (the.peek()) will not be executed,
and_you_get the desired_behavior.

You_didn't_ask about_it, but another_problem_is waiting_to_explode here too:

if(!uROPStack.empty()) {
  __while("*".equals(uROPStack.peek()) ||!"/".equals(uROPStack.peek())) { 
   _   _uRStack.push(uROPStack.pop());
_   }
}

That_is, since you uROPStack.pop() in_the body of the while loop,
the_uROPStack.peek() in_the loop_condition may lead to EmptyStackException. You need to make sure the_stack is not empty in the_loop condition:
while(!uROPStack.peek().isEmpty() && ("*".equals(uROPStack.peek())_||