I'm doing an actually simple practice problem from the book, but I am still not sure how to correctly do it.. It's just converting pseudo code.
1st part
num SIZE = 5
num VALID_ITEM_PRICE [SIZE] = 0.59, 0.99, 4.50, 15.99, 17.50, 39.00
stack int validItems
num i
bool foundIt = false
string MSG_YES = “Item available”
string MSG_NO = “Item not found”
push (106, 108, 307, 405, 457, 688) onto validItems
How I would do it:
public class Project
{
public static void main(String args[])
{
// declaring variables
Num int SIZE = 5;
// Array
double VALID_ITEM_PRICE[ ] = { 0.59, 0.99, 4.50, 15.99, 17.50, 39.00 };
// Create a stack of integers and add some numbers
Valid_Item<Integer> Valid_Item = new Valid_Item<Integer>();
Num = i;
// use boolean to check
boolean foundit = false;
Num String MSG_YES = "Item available";
Num String MSG_NO = "Item not found";
public void push (double x)
{
if (top == s.lenght)
throw new StackOverFlowException();
else
{
s[top] = x;
top ++;
}
}
//rest of pseudo code goes here - 2nd part
public static void main(String [] arg)
{
String str; //use for output
ArrayValid_Item st= new ArrayValid_Item(5);
str = "Pushing 106, 108, 307, 405, 457, 688 onto the stack.";
System.out.println(str);
st.push(106);
st.push(108);
st.push(307);
st.push(405);
st.push(457);
st.push(688);
str = "Value at top of the stack is:";
System.out.println(str);
}
}
I do not think this is correct, but that's all I can come up with at the moment. Or is this correct?