You could use a flag for the admin mode. set it to true and you're in admin mode:
boolean admin = true
.
Then you could simply check if admin
is true
and if that is the case, print admin stuff, if not... print those normal outputs.
Example in case the user typed 1:
case 1:
if(admin)
{ //admin, change price
c.println("Please enter the new price for the Low Pile Carpet: ");
pileCost = c.readInt();
}
else
{ //non-admin, set price
price = 18.75;
}
break; //important! don't forget the break-keyword
If you forget to add break
at the end of a case-statement all of the following statements (e.g. for 2: 3,4,5..) will run.
That should be an inspiration, you should figure out the rest yourself :)
Oh of course you will end up with only 1 method this way, which is smaller than the two before combined since logic isn't duplicated.