The Artima Developer Community
Sponsored Link

Java Answers Forum
How To Continue With The Code for Sales Program

3 replies on 1 page. Most recent reply: Feb 23, 2004 1:50 AM by leonglkw

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 3 replies on 1 page
leonglkw

Posts: 43
Nickname: leonglkw
Registered: Feb, 2004

How To Continue With The Code for Sales Program Posted: Feb 22, 2004 7:47 PM
Reply to this message Reply
Advertisement
Hi guys, need your help to continue writing the code for my sales program.

The sample outcome should look something like this:

Item sold:-
Enter product code:c1
Enter quantity:1
More items[Y/N]?:Y
Enter product code:p1
Enter quantity:5
More items[Y/N]?:N

Total amount due : $2700


This program will request the user to input the product code and the quantity, then the product code and quantity will be stored in the class variable for calculation.
User will be asked whether to input more or not[Y/N].

Below is the code that i write halfway but do not know how to continue:
import java.io.*;
 
class Product {
	String category;
	String favourite;
	int qtyPrepared;
	int qtySold;
	int costPrice;
	int sellingPrice;
	int difference;
}
 
class Sales {
	public static void main(String[] args) throws IOException{
		Product c1 = new Product();
		Product c2 = new Product();
		Product c3 = new Product();
		Product p1 = new Product();
		Product p2 = new Product();
		Product s1 = new Product();
		Product s2 = new Product();
 
		c1.category = "Computer";
		c1.favourite = "[c1]DELL";
		c1.qtyPrepared = 0;
		c1.qtySold = 0;
		c1.costPrice = 1000;
		c1.sellingPrice = 1700;
		c1.difference = 0;
 
		c2.category = "Computer";
		c2.favourite = "[c2]Compaq";
		c2.qtyPrepared = 0;
		c2.qtySold = 0;
		c2.costPrice = 900;
		c2.sellingPrice = 1200;
		c2.difference = 0;
 
		c3.category = "Computer";
		c3.favourite = "[c3]HP";
		c3.qtyPrepared = 0;
		c3.qtySold = 0;
		c3.costPrice = 1200;
		c3.sellingPrice = 1500;
		c3.difference = 0;
 
		p1.category = "Printer";
		p1.favourite = "[p1]Digitech";
		p1.qtyPrepared = 0;
		p1.qtySold = 0;
		p1.costPrice = 150;
		p1.sellingPrice = 200;
		p1.difference = 0;
 
		p2.category = "Printer";
		p2.favourite = "[p2]HP";
		p2.qtyPrepared = 0;
		p2.qtySold = 0;
		p2.costPrice = 180;
		p2.sellingPrice = 300;
		p2.difference = 0;
 
		s1.category = "Scanner";
		s1.favourite = "[s1]HP";
		s1.qtyPrepared = 0;
		s1.qtySold = 0;
		s1.costPrice = 100;
		s1.sellingPrice = 150;
		s1.difference = 0;
 
		s2.category = "Scanner";
		s2.favourite = "[s2]Digitech";
		s2.qtyPrepared = 0;
		s2.qtySold = 0;
		s2.costPrice = 80;
		s2.sellingPrice = 120;
		s2.difference = 0;
		
		System.out.println("Items sold:-");
		InputStreamReader productCodeReader = new InputStreamReader(System.in);
		BufferedReader inputProductCode = new BufferedReader(productCodeReader);
		System.out.print("Enter product code: ");
		String productCode = inputProductCode.readLine();
		System.out.println("Your product code: " + productCode);
 
		InputStreamReader quantityReader = new InputStreamReader(System.in);
		BufferedReader inputQty = new BufferedReader(quantityReader);
		System.out.print("Enter quantity: ");
		String quantity = inputQty.readLine();
		System.out.println("Your quantity: " + quantity);
 
		
 
 
	}
}


Viswanatha Basavalingappa

Posts: 84
Nickname: viswagb
Registered: Nov, 2003

Re: How To Continue With The Code for Sales Program Posted: Feb 23, 2004 12:07 AM
Reply to this message Reply
Hi ,
Don't creat the BufferedReader /InputStreamReader object for each read line.use the same object and call the methods.

here is the code sample for your requirments...

try
{
String prdCode ="";
String prdQuantity = "0";
String morePrd ="";


InputStreamReader inReader = new InputStreamReader(System.in);
BufferedReader BuffReader = new BufferedReader(inReader);
System.out.println("Items sold:-");
while(true)
{
System.out.print("Enter product code: ");
prdCode = BuffReader.readLine();
System.out.print("Enter quantity: ");
prdQuantity = BuffReader.readLine();
System.out.print("More items[Y/N]?:");
morePrd = BuffReader.readLine();
if(morePrd.equalsIgnoreCase("N"))
break;
else
continue;

}
}
catch(Exception e )
{
System.out.println("ERROR" + e);
}

Hope this help you...
Viswa
---------

Viswanatha Basavalingappa

Posts: 84
Nickname: viswagb
Registered: Nov, 2003

Re: How To Continue With The Code for Sales Program Posted: Feb 23, 2004 12:09 AM
Reply to this message Reply
Reposted with java code format

	try
	{
		String prdCode ="";
		String    prdQuantity = "0";
		String morePrd ="";
		
		
		InputStreamReader inReader = new InputStreamReader(System.in);
		BufferedReader BuffReader = new BufferedReader(inReader);
		System.out.println("Items sold:-");
		while(true)
		{
			System.out.print("Enter product code: ");
			prdCode = BuffReader.readLine();
			System.out.print("Enter quantity: ");
			prdQuantity = BuffReader.readLine();
			System.out.print("More items[Y/N]?:");
			morePrd = BuffReader.readLine();
			if(morePrd.equalsIgnoreCase("N"))
			 break;
			else
			 continue;
			
		}
	}
	catch(Exception e )
	{
		System.out.println("ERROR " + e);
	}


Viswa
-------

leonglkw

Posts: 43
Nickname: leonglkw
Registered: Feb, 2004

Re: How To Continue With The Code for Sales Program Posted: Feb 23, 2004 1:50 AM
Reply to this message Reply
Thanks Viswa.
U have helped me a lot because i am beginner of java programming, there are a lot of java programming i still need to catch up.

Flat View: This topic has 3 replies on 1 page
Topic: J2ME help. datelist "select" button listener? Previous Topic   Next Topic Topic: Back to school for class...

Sponsored Links



Google
  Web Artima.com   

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