-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAssignment2p1.java
More file actions
33 lines (29 loc) · 852 Bytes
/
Assignment2p1.java
File metadata and controls
33 lines (29 loc) · 852 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import java.util.Scanner;
class Product {
int id;
String name;
double price;
public Product(int id, String name, double price) {
this.id = id;
this.name = name;
this.price = price;
}
public void displayDetails() {
System.out.println("Product Details:");
System.out.println("ID: " + id);
System.out.println("Name: " + name);
System.out.println("Price: " + price);
}
}
public class Assignment2p1 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int id = scanner.nextInt();
scanner.nextLine();
String name = scanner.nextLine();
double price = scanner.nextDouble();
Product product = new Product(id, name, price);
product.displayDetails();
scanner.close();
}
}