Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 38 additions & 20 deletions Assignment1.java
Original file line number Diff line number Diff line change
@@ -1,30 +1,48 @@
package com.Mahi;
import java.util.Scanner;
import java.io.*;

import java.util.*;

public class Assignment1 {
static Product[] pd;
public static void main(String[] args) {
// TODO Auto-generated method stub
public class Assignment1{


public static void main(String[] args) throws Exception{
Product[] pd = new Product[6];
Scanner sc= new Scanner(System.in);
String prodID= new String();
FileOutputStream fos= new FileOutputStream("abc.ser");
ObjectOutputStream oos= new ObjectOutputStream(fos);
float cost=0;
int numberOfItems=0, totalProd=0;
float totcost = 0;
System.out.println("Specify the total no. of products to be bought altogether");
totalProd= sc.nextInt();
for(int i=0;i<6;i++){
System.out.println("Enter the product ID of the "+i+"th item");
String prodID= new String();
int noOfItems=0;
float totcost=0;
for(int i=0;i<2;i++){
System.out.println("Enter the product ID of "+i+"th item");
prodID= sc.next();
System.out.println("Enter the cost of the "+i+"th item");

System.out.println("Enter the cost of "+i+"th item");
cost= sc.nextFloat();
System.out.println("Enter the total number of items available for "+i+"th item");
numberOfItems= sc.nextInt();
pd[i]= new Product(prodID, cost, numberOfItems);

System.out.println("Enter the total no. of items available in "+i+"th item");
noOfItems= sc.nextInt();

pd[i]= new Product(prodID, cost, noOfItems);

totcost= totcost+ pd[i].getCost()*pd[i].getNoOfItems();
oos.writeObject(pd[i]);

}
Product[] pd1 = new Product[6];
FileInputStream fis= new FileInputStream("abc.ser");
ObjectInputStream ois= new ObjectInputStream(fis);
for(int j=0;j<2;j++){


totcost= totcost+ pd[j].getCost()*pd[j].getNoOfItems();
pd1[j]=(Product)ois.readObject();
System.out.println(pd1[j]);

totcost= totcost+pd[i].getCost();
System.out.println();
}
System.out.println("The total cost is "+totcost);
sc.close();
ois.close();
oos.close();
}
}