PHP Code:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author FritzEam
*/
import java.util.*;
public class Dubg {
public static Scanner input = new Scanner(System.in);
public static int[] code = new int[10];
public static String[] name = new String[30];
public static int[] qty = new int[10];
public static double[] price = new double[10];
public static int[] pcode = {1112, 1122, 1133, 1144, 1155};
public static String[] pname = {"Comics", "Horror Book", "Novel", "Nature", "Magazine"};
public static int[] nqty = {10, 15, 15, 5, 10};
public static double[] nprice = {49.99, 79.99, 59.99, 109.99, 59.99};
public static int j, srp = 0, m, n, num, nwqty=0, trans=0;
public static double total = 0, tot = 0, change = 0, nwprice=0;
public static boolean c = false;
public static void main(String[] args){
CountItems();
for ( int z = 0; z < 5; z++ ) {
code[z] = pcode[z];
name[z] = pname[z];
qty[z] = nqty[z];
price[z] = nprice[z];
}
while(j < 5 ) {
System.out.println("\n1. ADD ITEMS ");
System.out.println("2. VIEW ITEMS ");
System.out.println("3. SEARCH ITEMS ");
System.out.println("4. MODIFY ITEMS ");
System.out.println("5. DELETE ITEMS ");
System.out.println("6. PROCESS TRANSACTION ");
System.out.println("7. SALES OVERVIEW ");
System.out.println("8. EXIT ");
System.out.print("Enter number of your choice: ");
j = input.nextInt();
System.out.println();
switch(j) {
case 1: System.out.println("---ADD RECORDS---"); add(); break;
case 2: System.out.println("---VIEW RECORDS---"); view(); break;
case 3: System.out.println("---SEARCH RECORDS---"); search(); break;
case 4: System.out.println("---MODIFY RECORDS---"); modify(); break;
case 5: System.out.println("---DELETE---"); delete(); break;
case 6: System.out.println("---PROCESS TRANSACTION---"); transaction(); break;
case 7: System.out.println("---SALES OVERVIEW---"); overview(); break;
case 8: System.out.println("END APPLICATION"); break;
}
}
}
public static void CountItems() {
srp=0;
for ( int z = 0; z < 10; z++ ) {
if ( !(name[z] == null)) {
srp++;
}
}
}
public static void add(){
CountItems();
/*System.out.print("Enter number of data to be entered: ");
num = input.nextInt();
for(int a = 0; a < num; a++) {*/
System.out.print(" Enter Product Code: "); code[srp] = input.nextInt();
System.out.print(" Enter Product Name: "); name[srp] = input.next();
System.out.print(" Enter Quantity: "); qty[srp] = input.nextInt();
System.out.print(" Enter Price: "); price[srp] = input.nextInt();
}
//}
public static void view(){
CountItems();
for(int i = 0; i < srp; i++) {
System.out.println("\n Product Code: " + code[i] + " \n Product Name: " + name[i] +
"\n Quantity: " + qty[i] + "\n Price: " + price[i]);
}
}
public static void search(){
System.out.print("Enter Product Code: ");
int search = input.nextInt();
for(int a = 0; a < srp; a++) {
if(search == (code[a]))
{
System.out.println("\n Product Code: " + code[a] + " \n Product Name: " + name[a] + "\n Quantity: " + qty[a] +
"\n Price: " + price[a]);
c = true;
}
}
if(c == false) System.out.println("NO BOOK FOUND!");
}
public static void modify(){
System.out.print("\nEnter Product Code: ");
int mod = input.nextInt();
for (int a = 0; a < srp; a++ ) {
if ( mod == (code[a])) {
System.out.print("\nEnter a new Product Name : "); name[a] = input.next();
System.out.print("Enter a new Price : "); price[a] = input.nextInt();
System.out.println("SAVE CHANGES!!!");
c = true;
}
}
if ( c == false ) System.out.println("CANNOT BE FOUND!");
}
public static void delete(){
String s= " ", unknown= " " ;
System.out.print("\nEnter Product Name: "); s=input.next();
for(int a = 0; a < 10; a++){
if(s.equalsIgnoreCase(name[a])){
code[a] = 0;
name[a] = unknown;
price[a] = 0.0;
qty[a] = 0 ;
System.out.println("ITEM DELETED!!!");
c = true;
}
}
if(c == false)
System.out.println("CANNOT BE FOUND!");
}
public static void transaction(){
System.out.print("\nEnter No. of Items to Buy: ");
trans = input.nextInt();
for(int a = 0; a < trans; a++) {
System.out.print("Enter code "+(a+1)+": "); m = input.nextInt();
System.out.print("Enter quantity: "); n = input.nextInt();
for (int i = 0; i < srp; i++) {
if ( m == code[i] ) {
total += (price[i] * n);
}
}
}
System.out.println("\nTotal Payable: "+ "Php" + total);
System.out.print("Enter cash: ");
int mon = input.nextInt();
change = mon - total;
if(mon>=total)
System.out.println("Change: " + "Php" + change);
else
System.out.println("YOUR MONEY IS NOT ENOUGH!!!");
}
public static void overview(){
for (int i = 0; i < srp; i++) {
nwqty = qty[i] - n;
nwprice = price[i] * qty[i];
System.out.print("\n\nProduct Code: " + code[i]);
System.out.print("\nProduct Name: " + name[i]);
System.out.print("\nQuantity: " + nwqty);
System.out.println("\nTotal Price: " + nwprice);
}
}
}