Question
You are supposed to write a complete Inventory system program in JAVA. All the parts’ details will be stored/retrieved using classes, methods, objects and Arrays.
Below are the details of Parts:
•
PartID :
integer
•
Description : alphanumeric of 30 character
Manufacturer
Date : 8 character max.
•
Quantity :
integer
•
Price :
integer
Perform the following tasks:
Main
Menu
[1]. Add new Parts
[2]. Display all records
[3]. Display a particular record by given the
PartID and Modify the existing information
[4]. Analysis of
record level
[5]. Sales update
Report
[6]. Exit
solutionimport java.util.Scanner;
class Part{
int partID;
String description;
String date;
int Quantity;
int price;
public Part() {
partID=0;
date=null;
Quantity=0;
price=0;
description=null;
}
@Override
public String toString() {
return "Part{" + "partID=" + partID + ", description=" + description + ", date=" + date + ", Quantity=" + Quantity + ", price=" + price + '}';
}
public Part(int partID, String description, String date, int Quantity, int price) {
this.partID = partID;
this.description = description;
this.date = date;
this.Quantity = Quantity;
this.price = price;
}
public void setPartID(int partID) {
this.partID = partID;
}
public void setDescription(String description) {
this.description = description;
}
public void setDate(String date) {
this.date = date;
}
public void setQuantity(int Quantity) {
this.Quantity = Quantity;
}
public void setPrice(int price) {
this.price = price;
}
public int getPartID() {
return partID;
}
public String getDescription() {
return description;
}
public String getDate() {
return date;
}
public int getQuantity() {
return Quantity;
}
public int getPrice() {
return price;
}
}
/**
*
* @author Oymaq Azizi
*/
public class AssigmentNo1 {
public static void main(String[] args) {
char choice = 'm';
Scanner input=new Scanner(System.in);
Part parts[] =new Part[20];
int loc=-1;
do
{
System.out.println("[1]. Add new Parts ");
System.out.println("[2]. Display all records ");
System.out.println("[3]. Display a particular record by given the PartID and Modify the existing information ");
System.out.println("[4]. Analysis of record level ");
System.out.println("[5]. Sales update Report ");
System.out.println("[6]. Exit ");
choice=input.next().charAt(0);
switch(choice)
{
case '1':
{
input.nextLine();
System.out.println("Enter description :");
String description=input.nextLine();
while(description.length()>=30)
{
System.out.println("Description must be less than 30 characters!");
System.out.print(" Try again :");
description=input.nextLine();
}
// enter date
System.out.println("Enter date :");
String date=input.nextLine();
while(date.length()>=9)
{
System.out.println("date must be less than 8 characters!");
System.out.print(" Try again :");
date=input.nextLine();
}
// end date
//get id
System.out.print("Enter item id :");
int partId=input.nextInt();
boolean check=true;
while(check==true)
{
check=false;
for(Part checkId:parts)
{
if(checkId!=null)
{
if(partId==checkId.getPartID())
{
check=true;
break;
}
}
}
if(check==true){
System.out.println("Id already exist ");
System.out.print(" Try again:");
partId=input.nextInt();
}
}
//end get id
System.out.print("Enter quantity :");
int quantity=input.nextInt();
System.out.println("enter price : ");
int price=input.nextInt();
Part temp = new Part(partId,description,date,quantity,price);
loc++;
parts[loc]=temp;
break;
}
case '2':
{
for(Part x:parts)
{
if(x!=null)
System.out.println(x);
}
break;
}
case '3':
{
System.out.println("Enter id for searching :");
int recordId=input.nextInt();
int flag=0;
int modifyLocation=-1;
for(Part x:parts)
{
modifyLocation++;
if(x!=null)
{
if(x.partID==recordId){
System.out.println("item found: ");
System.out.println(x);
flag++;
System.out.println("press y for modification.");
char ch=input.next().charAt(0);
if(ch=='y')
{
System.out.println("1.modify description");
System.out.println("2.Modify quantity");
System.out.println("3.modify date");
System.out.println("4.Modify price");
int modificationChoice=input.nextInt();
switch(modificationChoice)
{
case 1:
{
System.out.println("Enter description :");
input.nextLine();
parts[modifyLocation].setDescription(input.nextLine());
System.out.println("modified:\n"+parts[modifyLocation]);
break;
}
case 2:
{
System.out.println("Enter quantity:1");
parts[modifyLocation].setQuantity(input.nextInt());
System.out.println("modified:\n"+parts[modifyLocation]);
break;
}
case 3:
{
System.out.println("enter date");
parts[modifyLocation].setDate(input.nextLine());
System.out.println("modified:\n"+parts[modifyLocation]);
break;
}
case 4:
{
System.out.println("Enter price :");
parts[modifyLocation].setPrice(input.nextInt());
System.out.println("modified:\n"+parts[modifyLocation]);
break;
}
default:
{
System.out.println("Invalid input");
break;
}
}
}
break;
}
}
}
if(flag==0)
{
System.out.println("No record for id:"+recordId);
}
break;
}
case '4':
{
System.out.println("choice lowest Id:");
int recordId=input.nextInt();
int flag=0;
for(Part x:parts)
{
if(x!=null)
{
if(x.partID>=recordId){
System.out.println(x);
flag++;
}
}
}
if(flag==0)
System.out.println("no record");
else
System.out.println("total record ="+flag);
break;
}
case '5':
{
System.out.println("Enter id to sold");
int recordId=input.nextInt();
int flag=0;
int solloc=-1;
for(Part x:parts)
{
solloc++;
if(x!=null)
{
if(x.partID==recordId){
System.out.println("Enter quantity:");
int q=input.nextInt();
if(q>x.getQuantity())
{
System.out.println("Sorry toatl quantity is ="+x.getQuantity());
break;
}
else
{
System.out.println("you sold the item \n"+x.getDescription()+"\n unit price ="+x.getPrice()+"\n Total price ="+(x.getPrice()*q));
x.setQuantity(x.getQuantity()-q);
flag++;
}
break;
}
}
}
if(flag==0)
{
System.out.println("No record for id:"+recordId);
}
break;
}
case '6':
{
System.out.println("Are you sure to exits y/n");
choice=input.next().charAt(0);
}
default :
{
System.out.println("invalid input try again!");
choice=input.next().charAt(0);
break;
}
}
}
while(choice!='y');
}
}
Comments
Post a Comment