0% found this document useful (0 votes)
9 views

message

The Java program 'SaleRecord' allows users to input product details such as ID, name, price, and quantity, and calculates total revenue, discount, and net revenue based on the input. It includes methods for saving records, calculating totals and discounts, displaying records, and searching for a product by ID. The program utilizes arrays to store product information and performs calculations based on user input.

Uploaded by

Thiha Zaw
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

message

The Java program 'SaleRecord' allows users to input product details such as ID, name, price, and quantity, and calculates total revenue, discount, and net revenue based on the input. It includes methods for saving records, calculating totals and discounts, displaying records, and searching for a product by ID. The program utilizes arrays to store product information and performs calculations based on user input.

Uploaded by

Thiha Zaw
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

import java.util.

Scanner;

public class SaleRecord {

public static void main(String[] args) {


Scanner scan = new Scanner(System.in);
System.out.print("Enter your index:");
int index = scan.nextInt();
int[ ] pdID = new int [index];
String[ ] pdName = new String [index];
int[ ] pdPrice = new int [index];
int[ ] pdQty = new int [index];
double[ ] pdRevenue = new double [index];
double discount = 0;
double netRevenue =0;
double totalRevenue, rate = 0.1;
saveRecord(pdID,pdName,pdPrice,pdQty,pdRevenue);
totalRevenue = calculateTotalRevenue(pdRevenue);
discount =calculateDiscount(totalRevenue,rate);
netRevenue= calculateNetRevenue(totalRevenue,discount);

showRecord(pdID,pdName,pdPrice,pdQty,pdRevenue,discount,netRevenue,totalRevenue);
System.out.print("Enter ID which one you want to search:");
int id= scan.nextInt();
searchByID(id,pdID,pdName,pdPrice,pdQty,pdRevenue);
}

public static void saveRecord(int[ ] id, String [ ] name, int[ ]


price,int[ ]qty , double[] revenue) {

Scanner scan = new Scanner(System.in);


for (int i =0 ; i <id.length; i++){
System.out.print("Enter Product ID:\t");
id[i] = scan.nextInt();
System.out.print("Enter Product Name:\t");
name[i] = scan.next();
System.out.print("Enter Product Price:\t");
price[i] = scan.nextInt();
System.out.print("Enter Product Quantity:\t");
qty[i] = scan.nextInt();

revenue[i]= price[i] *qty[i] ;

}
}
public static double calculateTotalRevenue(double[] revenue) {
double totalRevenue =0;
for(int i= 0; i<revenue.length; i++){
totalRevenue+=revenue[i];
}
return totalRevenue;
}
public static double calculateDiscount(double total,double rate) {
double discount = 0;
if (total >10000){
discount = total *rate;
}
return discount;
}
public static double calculateNetRevenue(double totalRevenue, double discount)
{
double netRevenue=0;
netRevenue = totalRevenue-discount;
return netRevenue;
}

public static void showRecord(int[ ] id, String [ ] name, int[ ]


price,int[ ]qty, double[] revenue,double discount,double netRevenue,double total) {
System.out.println("ID\tProductName\tProductPrice\tProductQty\
tRevenue");

System.out.println("===============================================================
");
for(int i= 0; i<id.length; i++){
System.out.println(id[i]+"\t"+name[i]+"\t\t"+price[i]+"\t\t"+qty[i]+"\t\
t"+revenue[i]);
}

System.out.println("===============================================================
");
System.out.println("\t\t\t\t\t Total Revenue:\t "+total);
System.out.println("\t\t\t\t\t Discount \t "+discount);
System.out.println("\t\t\t\t\t Net Revenue:\t "+netRevenue);

private static void searchByID(int searchID, int[] id, String[] name, int[]
price, int[] qty, double[] revenue) {
for(int i= 0; i<id.length; i++){
if(id[i]==searchID){
System.out.println(id[i]+"\t"+name[i]+"\t\t"+price[i]+"\t\t"+qty[i]
+"\t\t"+revenue[i]);
}
}

}
}

You might also like