-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathobject_array_book.java
More file actions
67 lines (58 loc) · 1.93 KB
/
Copy pathobject_array_book.java
File metadata and controls
67 lines (58 loc) · 1.93 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package oop.basic;
import java.util.Scanner;
public class object_array_book {
private int code;
private String title;
private String subject;
private float price;
// defaul
public object_array_book(){
code = 129;
title = "teaching";
subject = "IT";
price = 2000;
}
// constructor with parameter
public object_array_book(int code, String title, String subject, float price){
this.code = code;
this.title = title;
this.subject = subject;
this.price = price;
}
// Input
public void Input(){
Scanner objin = new Scanner(System.in);
System.out.print("Input Code :");code = objin.nextInt();
System.out.print("Input Title :");title = objin.next();
System.out.print("Input Subject :");subject = objin.next();
System.out.print("Input Price :");price = objin.nextFloat();
}
// Output
public void Output(){
System.out.println(" Code :"+code);
System.out.println(" Tite :"+title);
System.out.println(" Subject :"+subject);
System.out.println(" Price :"+price);
}
public static void main(String[] args) {
// defual
object_array_book oba = new object_array_book();
oba.Output();
// constructor with parameter
object_array_book oba1 = new object_array_book(12000,"Art","Pobuler",2000);
oba1.Output();
// Input & Output
object_array_book oba2[];
oba2 = new object_array_book[30];
int i,n;
Scanner objin = new Scanner(System.in);
System.out.print("Input element of array :");
n = objin.nextInt();
for(i=0;i<n;i++){
oba2[i].Input();
}
for(i=0;i<n;i++){
oba2[i].Output();
}
}
}