The Artima Developer Community
Sponsored Link

Java Answers Forum
Java problems with my program

2 replies on 1 page. Most recent reply: Apr 12, 2003 5:32 PM by Charles Bell

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 2 replies on 1 page
Jeffrey Jones

Posts: 2
Nickname: zebedeeee
Registered: Apr, 2003

Java problems with my program Posted: Apr 12, 2003 11:38 AM
Reply to this message Reply
Advertisement
The following program is to be used to call up a class that tests for the barcode length and integrity, I am having problems compiling it as when it gets to the p = new Product etc it cannot resolve the symbol p can anyone help me to get this to work


/**
* This is a program to Enter and check product codes and prices
* and give a summary of values at the end
* @author (Jeffrey Jones)
* @version (version 2 5th April 2003)
*/
public class ProcessProduct
{
public static void main(String args[])
{

StaticProduct Product = new StaticProduct();
//declare variables

String manuf;
String name;
int sLength;
String p;
String barcode;
int price;
int quantity;
int totalPrice=0;
int transactions=1;
int totalQuantity=0;
int totalValue=0;
int averageCost=0;




//Input Details
System.out.print("Enter Product Manufacturer : ");
manuf = UserInput.readString();



//start of while loop checking for 0 to exit loop
while (!manuf.equals("0"))
{
System.out.print("Enter Product Name : ");
name = UserInput.readString();

System.out.print("Enter Bar Code : ");
barcode = UserInput.readString();

//check for invalid data

if (StaticProduct.isValidBarcode(barcode))

{barcode = new code();
p = new Product("manuf","name","quantity","price");
}//closing bracket of if

else
{//error handling
}//closing bracket of if

//check for quantity input and errors
System.out.print("Enter Quantity : ");
quantity = UserInput.readInt();

if (quantity<=0)
{ System.out.print(" Error, invalid value ");
System.exit(0);
}// check for invalid entries

System.out.print("Enter Price :");
price = UserInput.readInt();

//check for price input and errors
if (price<=0)
{ System.out.print(" Error, invalid value ");
}// check for invalid entries

//total price value
totalPrice=price*quantity;

//Output of correctly inputted data
System.out.println(manuf+":"+name+":"+barcode+":"+price);
System.out.println(quantity+" @ "+price+" = "+totalPrice);

//update variables quantities
//update total quantity
totalQuantity = (totalQuantity + quantity);
//keep count of total value
totalValue = (totalValue + totalPrice);
//keep count of totqal no of transactions
transactions = (transactions++);

//Input Details
System.out.print("Enter Product Manufacturer : ");
manuf = UserInput.readString();

}//closure of loop

//display final totals
System.out.println("Transactions: "+transactions);
System.out.println("Total quantity: "+totalQuantity);
System.out.println("Total value: "+totalValue);
System.out.println("Average Cost: "+totalValue/totalQuantity);

System.exit(0);




}//closing bracket input and output of data

}//end class


Senthoorkumaran Punniamoorthy

Posts: 335
Nickname: senthoor
Registered: Mar, 2002

Re: Java problems with my program Posted: Apr 12, 2003 4:56 PM
Reply to this message Reply
There is a statement in your code saying

StaticProduct Product = new StaticProduct(); 


But you have not imported any package or class which has the StaticProduct class into your program? Where have you defined the StaticProduct class?

Charles Bell

Posts: 519
Nickname: charles
Registered: Feb, 2002

Re: Java problems with my program Posted: Apr 12, 2003 5:32 PM
Reply to this message Reply
You have declared p as a String in the line:

String p;

maybe that should be:

Product p;

Flat View: This topic has 2 replies on 1 page
Topic: Pls explain on this GUI Previous Topic   Next Topic Topic: java internetworking

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use