leonglkw
Posts: 43
Nickname: leonglkw
Registered: Feb, 2004
How To Continue With The Code for Sales Program
Posted: Feb 22, 2004 7:47 PM
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);
}
}