The Inventory System Implement the class diagram and the sequence diagram. [Help
ID: 3851603 • Letter: T
Question
The Inventory System Implement the class diagram and the sequence diagram.
[Help modify the source code]:
import java.util.Scanner;
// Product class
public class Product
{
private String name;
private int productNum;
private int barCode;
public Product(String p_name, int p_num, int p_bar)
{
name = p_name;
productNum = p_num;
barCode = p_bar;
}
}
// User Class
public class User
{
private int id;
public User(int a)
{
id = a;
}
public void scan()
{
}
}
//Driver Class
public class driver
{
public static void main( String[] args )
{
Product p1 = new Product("product01", 012, 0123212);
User u1 = new User(01);
}
}
Explanation / Answer
import java.util.Scanner;
// Product class
public class Product {
private String name;
private int productNum;
private int barCode;
public Product() {
// TODO Auto-generated constructor stub
}
public Product(String p_name, int p_num, int p_bar) {
name = p_name;
productNum = p_num;
barCode = p_bar;
}
public void scan() {
Scanner scanner = null;
try {
scanner = new Scanner(System.in);
System.out.print("Enter product name:");
this.name = scanner.next();
System.out.print("Enter product number:");
this.productNum = scanner.nextInt();
System.out.print("Enter product barcode:");
this.barCode = scanner.nextInt();
} catch (Exception e) {
// TODO: handle exception
}
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
return "Product [name=" + name + ", productNum=" + productNum
+ ", barCode=" + barCode + "]";
}
}
import java.util.Scanner;
public class User {
private int id;
public User() {
// TODO Auto-generated constructor stub
}
public User(int a) {
id = a;
}
public void scan() {
Scanner scanner = null;
try {
scanner = new Scanner(System.in);
System.out.print("Enter user id:");
this.id = scanner.nextInt();
} catch (Exception e) {
// TODO: handle exception
}
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
return "User [id=" + id + "]";
}
}
public class Error extends Exception {
private String message;
/**
* @param message
*/
public Error(String message) {
super(message);
this.message = message;
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
return "Error [message=" + message + "]";
}
}
public class driver {
public static void main(String[] args) {
Product p1 = new Product("product01", 12, 123212);
Product p2 = new Product();
User u = new User();
p2.scan();
u.scan();
System.out.println(p1);
System.out.println(p2);
System.out.println(u);
}
}
OUTPUT:
Enter product name:prod02
Enter product number:13
Enter product barcode:123321
Enter user id:1
Product [name=product01, productNum=12, barCode=123212]
Product [name=prod02, productNum=13, barCode=123321]
User [id=1]
NOTE: please share details/conditions about using Error class
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.