The Artima Developer Community
Sponsored Link

Java Answers Forum
How To Continue With The Code for Sales Program(Part 2)

1 reply on 1 page. Most recent reply: Feb 24, 2004 7:38 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 1 reply on 1 page
leonglkw

Posts: 43
Nickname: leonglkw
Registered: Feb, 2004

How To Continue With The Code for Sales Program(Part 2) Posted: Feb 24, 2004 2:59 AM
Reply to this message Reply
Advertisement
Can anyone help continue my program?

After complete the below part of the sales program, I need to add function to do the calculation of the sales.

For example, after i obtain the input of product code and quantity of sales from user, i want to update the quantity in Product class in the code.

If the user input c1 for product code and quantity 8 for quantity sold.
Then i should have a function to update the c1.quantitySold.

And after the user input the first product, the user still want to continue input more products, how can i update the respective quantitySold.

After that, I also need to calculate the total amount due.

Pls see the below sample screen that what i mentioned,
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 is the code that i need 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;
 
		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);
		}
	}
}


Thanks a million.


leonglkw

Posts: 43
Nickname: leonglkw
Registered: Feb, 2004

Re: How To Continue With The Code for Sales Program(Part 2) Posted: Feb 24, 2004 7:38 AM
Reply to this message Reply
I try to solve the above code but my code still does not work.

Below is the code that i tried to write:
import java.io.*;
 
class Product {
	String category;
	String favourite;
	int qtyPrepared;
	int qtySold;
	int costPrice;
	int sellingPrice;
	int difference;
 
	[b]Product updateSales(String productCode, int productQty){
		productCode.qtySold = productCode.qtySold + productQty;
		
 
	}[/b]
}
 
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;
 
		try
		{
			String prdCode ="";
			String prdQuantity = "0";
			String morePrd ="";
			int totalAmountDue = 0
		
			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();
				int prdQty = new Integer(prdQuantity).intValue();
				[b]totalAmountDue = updateSales(prdCode, prdQty);[/b]
				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);
		}
	}
}


Actually, in my SalesMade function, i intend to update the quantity sold of certain product.
And after one product sale is updated when user want to update more sale, the totalAmountDue is sum of qtySold.

Please advise.

Flat View: This topic has 1 reply on 1 page
Topic: Copying icon and string from one JList to another JList Previous Topic   Next Topic Topic: re: tearing my hair out!!!

Sponsored Links



Google
  Web Artima.com   

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