The Artima Developer Community
Sponsored Link

Java Answers Forum
How To Continue With The Code for Daily Order Program

3 replies on 1 page. Most recent reply: Feb 25, 2004 5:52 AM by twc

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 Daily Order Program Posted: Feb 24, 2004 5:35 AM
Reply to this message Reply
Advertisement
Hi guys, pls help to solve this problem.
I already cannot come out with the solution.

The below program will do the Daily Order processing.
The main requirement for this program is that the additional order for each category as defined in Product class must be at least minimum 1 unit for Computer, minimum 10 units for Printer and minimum 20 units for Scanner.

This program will check whether the quantity ordered meets the minimum requirement.
If yes, the order is made and the additional quantity that meets the minimum requiremnet is updated in the Product class variable, that is, qtyPrepared and qtySold.

Otherwise, a message "Insufficient Qty.-Please come again" should be displayed.

Pls see the below sample screen that what i mentioned above,
the sample outcome should look something like this:

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

Total amount due : $6500


or
Item ordered:-
Enter product code:p1
Enter quantity:5

Insufficient Qty.-Please come again.


This is the code that i complete halfway:
import java.io.*;
 
class Product {
	String category;
	String favourite;
	int qtyPrepared;
	int qtySold;
	int costPrice;
	int sellingPrice;
	int difference;
}
 
class DailyOrder {
	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 Ordered:-");
			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 in advance.


Viswanatha Basavalingappa

Posts: 84
Nickname: viswagb
Registered: Nov, 2003

Re: How To Continue With The Code for Daily Order Program Posted: Feb 25, 2004 4:41 AM
Reply to this message Reply
Hi,

See this shows that that you have no flexibality to make your requirment it is due to the improper class design.

change your class deigbn as bellow and try to implement..use OOP concepts..
class Products
{
	String prodID;
}
class Computer extends Products
{
	String favourite;
	int MinQuantityOrder;
	int ActualPrice;
	int sellingPrice;
	
	public boolean verifyMinQuantity(int Qunatity)
	{
		if(Qunatity >=1)
		retunr true;
		return false;
	}	
}
class Scanner extends Products
{
	String favourite;
	int MinQuantityOrder;
	int ActualPrice;
	int sellingPrice;
	
	public boolean verifyMinQuantity(int Qunatity)
	{
		if(Qunatity >=10)
		retunr true;
		return false;
	}
}
class Printer extends Products
{
	String favourite;
	int MinQuantityOrder;
	int ActualPrice;
	int sellingPrice;
	
	public boolean verifyMinQuantity(int Qunatity)
	{
		if(Qunatity >=20)
		retunr true;
		return false;
	}
}


then try to change the implementation accordingly..

OR




solution for the old pattren is as bellow...

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();
			// convert the prdQuantity string to int value 
			if(!(prdCode.equalsIgnoreCase("Computer") && prdQuantity>=1) || prdCode.equalsIgnoreCase("Printer") && prdQuantity>=10) || prdCode.equalsIgnoreCase("Scanner") && prdQuantity>=20) )
			{
				System.out.print("Insufficient Qty.-Please come again");
				while(prdQuantity = BuffReader.readLine())
				{
					if((prdCode.equalsIgnoreCase("Computer") && prdQuantity>=1) || prdCode.equalsIgnoreCase("Printer") && prdQuantity>=10) || prdCode.equalsIgnoreCase("Scanner") && prdQuantity>=20)	)
					break;
					else
					continue;
				}
			}
			else
			{
				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);
	}	
	

Viswanatha Basavalingappa

Posts: 84
Nickname: viswagb
Registered: Nov, 2003

Re: How To Continue With The Code for Daily Order Program Posted: Feb 25, 2004 5:00 AM
Reply to this message Reply
Try this corrected code...it works

	try
	{
		String prdCode ="";
		String prdQuantitystr = "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: ");
			prdQuantitystr = BuffReader.readLine();
			// convert the prdQuantity string to int value 
			Integer Int = new Integer(prdQuantitystr);
			int prdQuantity = Int.intValue();
			if((prdCode.equalsIgnoreCase("Computer") && prdQuantity<1) || (prdCode.equalsIgnoreCase("Printer") && prdQuantity<10) || (prdCode.equalsIgnoreCase("Scanner") && prdQuantity<20) )
			{
				System.out.print("Insufficient Qty.-Please come again");
				while(true)
				{
					prdQuantitystr = BuffReader.readLine();
					Int = new Integer(prdQuantitystr);
					prdQuantity = Int.intValue();
			  		if((prdCode.equalsIgnoreCase("Computer") && prdQuantity>=1) || (prdCode.equalsIgnoreCase("Printer") && prdQuantity>=10)|| (prdCode.equalsIgnoreCase("Scanner") && prdQuantity>=20)	)
			  		{
						break;
					}
					else
					{
						System.out.print("Insufficient Qty.-Please come again");
						continue;
					}
				}
			}
				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
-------

twc

Posts: 129
Nickname: twc
Registered: Feb, 2004

Re: How To Continue With The Code for Daily Order Program Posted: Feb 25, 2004 5:52 AM
Reply to this message Reply
Viswanatha GB makes an excellent point on the general design of your program. You are using an approach that is many years out-of-date. If this is what you are being taught in a class, I am disappointed in the teacher.

I realize that if this is an assignment, you may not have time to rewrite everything, so you may be forced to use the modifications that Viswanatha GB suggested to fix your code. But later, when you have more time, look over his/her first approach. It is a much better way to design a program.

Flat View: This topic has 3 replies on 1 page
Topic: Searching a vector of objects Previous Topic   Next Topic Topic: re: class to JSP

Sponsored Links



Google
  Web Artima.com   

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