/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package dom;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Scanner;
/**
*
* @author Bilal
*/
public class Dom {
Ledger ledger = new Ledger();
DataBaseManager dbm = new DataBaseManager();
Distributor d=new Distributor();
d=dbm.getDistributor("10fd032d4ea80e8b68ddad72b616c81fa4b6779c83c379bb0cda796ae1cd29e8");
Scanner input
= new Scanner
(System.
in);
int loop = 0;
do {
+ "Press 1 to register \n"
+ "Press 2 to login \n"
+ "Press 3 to view ledger \n"
+ "Press 4 to exit \n"
+ "Choice : "
+ "");
loop = input.nextInt();
switch (loop) {
case 1: {
User u = new User();
input.nextLine();
System.
out.
println("Enter user name : ");
String name
= input.
nextLine();
while (true) {
System.
out.
println("Enter Primary Currency Type: \n"
+ "1- USD\n"
+ "2- PKR\n"
+ "3- EUR\n"
+ "Enter your choice: ");
int input1 = input.nextInt();
if (input1 == 1) {
u.setCurrencyType("USD");
break;
}
if (input1 == 2) {
u.setCurrencyType("PKR");
break;
}
if (input1 == 3) {
u.setCurrencyType("EUR");
break;
} else {
System.
out.
println("Invalid Input!");
}
}
// data base check
String digitalSignature
= DigitalSignature.
randomString();
System.
out.
println("Digital Signature : " + digitalSignature
);
String hash
= SHA256.
hash(name
);
System.
out.
println("Hash : " + hash
);
u.setName(name);
u.setHash(hash);
u.setDigitalSignature(digitalSignature);
dbm.insertUser(u);
// user data
// db
break;
}
case 2: {
input.nextLine();
boolean flag = false;
System.
out.
println("enter name : ");
String name
= input.
nextLine();
String hash
= SHA256.
hash(name
);
ArrayList<User> list = new ArrayList<>();
list = dbm.getAllUsers();
User u = new User();
for (int i = 0; i < list.size(); i++) {
if (list.get(i).getHash().equals(hash)) {
flag = true;
u = list.get(i);
break;
}
}
if (flag == false) {
break;
}
System.
out.
println(u.
toString());
input.nextLine();
DarkCoin dc = new DarkCoin();
int choice = 0;
do {
System.
out.
println("Press 1 to edit Profile\n"
+ "Press 2 to sell coin\n"
+ "Press 3 to buy coin\n"
+ "Press 4 to return\n"
+ "Enter your choice: ");
choice = input.nextInt();
switch (choice) {
case 1: {
System.
out.
println("Enter Account Number: ");
input.nextLine();
u.setAccountNumber(input.nextLine());
System.
out.
println("Enter Amount: ");
u.setAmount(input.nextDouble());
dbm.updateAccountNumber(u);
dbm.updateAccountAmount(u);
}
break;
case 2: {
System.
out.
println("Enter amount: ");
double coin = input.nextDouble();
input.nextLine();
User u2 = new User();
while (true) {
System.
out.
println("Enter username to which you want to sell coin: ");
name = input.nextLine();
hash = SHA256.hash(name);
boolean chk = true;
for (int i = 0; i < list.size(); i++) {
if (list.get(i).getHash().equals(hash)) {
u2 = list.get(i);
chk = false;
break;
}
}
if (chk == true) {
System.
out.
println("User not found\nEnter again..");
} else {
break;
}
}
dc.sellCoin(u, u2, coin);
}
break;
case 3: {
System.
out.
println("Enter amount: ");
dc.buyCoin(u, input.nextDouble());
}
break;
case 4: {
}
break;
}
} while (choice != 4);
System.
out.
println(u.
toString());
// db check
// profile
// options
break;
}
case 3: {
System.
out.
println(ledger.
getAll());
break;
}
case 4: {
loop = 0;
break;
}
default: {
System.
out.
println("Invalid input");
break;
}
}
} while (loop != 0);
}
}