I'm wanting to convert this part of the pseudo-code...

start

string name

string address

num item

num quantity

num price

num SIZE = 6

num VALID_ITEM = 106, 108, 307, 405, 457, 688

num VALID_ITEM_PRICE = 0.59, 0.99, 4.50, 15.99, 17.50, 39.00

num sub

string foundIt = “N”

string MSG_YES = “Item available”

string MSG_NO = “Item not found”

public class program
{
public static void main(string[] args)
{

String name ="";
String address =""; 

int item;
int quantity;
double price;

int[] size = new int[6];

I'm not sure how to do this here... and it looks like the array needs to be searched, too ?? I don't understand what it wants from me now..VALID ITEM and VALID ITEM PRICE. Perhaps posting the entire pseudo code will help to clear things up:

start

string name

string address

num item

num quantity

num price

num SIZE = 6

num VALID_ITEM = 106, 108, 307, 405, 457, 688

num VALID_ITEM_PRICE = 0.59, 0.99, 4.50, 15.99, 17.50, 39.00

num sub

string foundIt = “N”

string MSG_YES = “Item available”

string MSG_NO = “Item not found”

get name, address, item, quantity

sub = 1

while sub <= SIZE

if item = VALID_ITEM [sub] then

foundIt = “Y”

price = VALID_ITEM_PRICE [sub]

endif

sub = sub + 1

endwhile

if foundIt = “Y” then

print MSG_YES

print quantity, “ at “ , price, “ each”

print “Total “, quantity * price

else

print MSG_NO

endif

stop

Recommended Answers

All 6 Replies

I'm wanting to convert this part of the pseudo-code...

public class program
{
public static void main(string[] args)
{

String name ="";
String address =""; 

int item;
int quantity;
double price;

int[] size = new int[6];

I'm not sure how to do this here... and it looks like the array needs to be searched, too ?? I don't understand what it wants from me now..VALID ITEM and VALID ITEM PRICE. Perhaps posting the entire pseudo code will help to clear things up:

check this for declaring arrays and looping through them:http://www.javaclass.info/classes/java-array/array-examples-demonstration-and-code-snippets.php and check here for finding an element in an array:http://www.java.happycodings.com/Core_Java/code41.html and perhaps this:http://www.java2s.com/Code/Java/Collections-Data-Structure/ArraySearchTest.htm

So it is an int array and I'm supposed to search it? What's meant by "num sub" ? Also, what's "string foundIt = “N” ? I know you declare it, but what's the N here? Probably as in "not found", but I don't see where it actually checks for it.

also: size is not supposed to be an array. it's supposed to be a single int, which has the value that you should use to set the length for the arrays:VALID_ITEM and VALID_ITEM_PRICE

How do I do the last print ? I'm not sure how to do the "print quantity, “ at “ , price, “ each”". How do I do this?

How do I put the "at" in the print ? System.out.println (quantity, at, price, each );

I don't understand where the price for each is coming from. That's the "sub", isn't it?

public class program
{
public static void main(string[] args)
{

String name;
String address;

int item;
int quantity;
double price;



final int SIZE = 6;

int VALID_ITEM[ ] = { 106, 108, 307, 405, 457, 688 } ;

double VALID_ITEM_PRICE[ ] = { 0.59, 0.99, 4.50, 15.99, 17.50, 39.00 };

int sub

boolean foundit = false;
final String MSG_YES = "Item available";
final String MSG_NO = "Item not found";

name = JOptionPane.showInputDialog("Enter name: ");
address = JOptionPane.showInputDialog("Enter address: ");
itemString = JOptionPane.showInputDialog("Enter item number: ");
item = Integer.parseInt(itemString);
quantityString = JOptionPane.showDialog("Enter quantity: ");
quantity = Integer.parseInt(quantityString);

sub = 1;

while (sub < SIZE)
{
if (item == VALID_ITEM[sub] )
foundit = true;

if (price == VALID_ITEM_PRICE[sub] )

sub = sub + 1;
}
if (foundit == true)
System.out.println (MSG_YES );
System.out.println ( );
System.out.println (total, quantity*price);
else
System.out.println (MSG_NO );
System.exit(0);

}
}

well... you already know how to print a line:
you can format a String (concatenation) by using "<String>" + variable +"<String>"
for instance:
int a = 1;
int b = 2;
String b = b + "The value of a = " + a + " end of String";

test it, change it, and use it. the above is about all you need to solve your problem.

import javax.swing.*;

public class Project
{
public static void main(String args[])
{

String name;
String address;
String itemString;
String quantityString;

int item;
int quantity;
double price;



final int SIZE = 6;

int VALID_ITEM[ ] = { 106, 108, 307, 405, 457, 688 } ;

double VALID_ITEM_PRICE[ ] = { 0.59, 0.99, 4.50, 15.99, 17.50, 39.00 };

int sub;

boolean foundit = false;
final String MSG_YES = "Item available";
final String MSG_NO = "Item not found";

name = JOptionPane.showInputDialog("Enter name: ");
address = JOptionPane.showInputDialog("Enter address: ");
itemString = JOptionPane.showInputDialog("Enter item number: ");
item = Integer.parseInt(itemString);
quantityString = JOptionPane.showInputDialog("Enter quantity: ");
quantity = Integer.parseInt(quantityString);

sub = 1;

while (sub <= SIZE)
{
if (item == VALID_ITEM[sub] )
foundit = true;

if ( price == VALID_ITEM_PRICE[sub] )

sub = sub + 1;
}
if (foundit == true)
{
System.out.println (MSG_YES );
System.out.println (quantity + " at " + price + " each " );
System.out.println (total, quantity * price);
    }
else
System.out.println ( MSG_NO );
System.exit(0);

}
}

The total variable isn't declared. Do I just declare it as double at the top ? I just did that, though, and it still gives me this error:

cannot find symbol
symbol : method println(double,double)
location: class java.io.PrintStream
System.out.println ( total, quantity * price );
1 error

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.