-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHelloWorld.java
80 lines (70 loc) · 2.38 KB
/
HelloWorld.java
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
68
69
70
71
72
73
74
75
76
77
78
79
80
package com.example.helloworld;
import java.io.IOException;
import java.util.Scanner;
import com.beust.jcommander.Parameter;
import com.beust.jcommander.JCommander;
import javax.swing.text.html.HTMLDocument;
import javax.xml.soap.Detail;
import java.util.*;
import java.io.*;
class details{
String name,type;
float price;
int quantity;
details(String name_,String type_,float price_,int quantity){
this.name = name_;
this.type = type_;
this.price = price_;
this.quantity = quantity;
}
}
public class HelloWorld {
@Parameter(names={"-name"})
String Name;
@Parameter(names={"-price"})
float price;
@Parameter(names={"-quantity"})
int quantity;
@Parameter(names={"-type"},required = true)
String type;
public static void main(String[] args) throws IOException {
HelloWorld main = new HelloWorld();
JCommander.newBuilder()
.addObject(main)
.build()
.parse(args);
//we shall implement a data structure with name as key and other vals as Values;
main.run();
//System.out.println(System.getProperty(sysProp));
}
public void run() throws IOException{
Vector<details>detailsArray = new Vector<>();
details d = new details(Name,type,price,quantity);
detailsArray.add(d);
System.out.println("Do you want one more item ? ");
Scanner sc = new Scanner(System.in);
char choice ;
System.out.println("Do you want to add more ? ");
choice = sc.next().charAt(0);
do{
String name,type;
int quantity;
float price;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
name = br.readLine();
type = br.readLine();
quantity = Integer.parseInt(br.readLine());
price = Float.parseFloat(br.readLine());
d = new details(name,type,price,quantity);
detailsArray.add(d);
System.out.println("Do you want to add more ? ");
choice = sc.next().charAt(0);
}while(choice=='y');
//lets print the stored information
Iterator itr = detailsArray.iterator();
while(itr.hasNext()){
details dt = (details) itr.next();
System.out.println(dt.name + dt.type + dt.quantity + dt.price);
}
}
}