Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class Interface
- {
- private Depot depot1, depot2;
- int choice;
- Scanner console = new Scanner(System.in);
- public Interface()
- {
- depot1 = new Depot();
- depot2 = new Depot();
- }
- public void run(){
- //System.out.println("Enter Depot name: ");
- //String dName = console.nextLine();
- //Depot d = new Depot();
- //d.setName(dName);
- //System.out.println("Name: " + d.getName());
- //this method should control the flow of the program
- do {
- System.out.println("Add Depot(1), Remove Depot(2), List Depots(3), Exit (9): ");
- choice = console.nextInt();
- if(choice<1){
- System.out.println("Negative numbers not allowed");
- }
- else
- switch(choice)
- {
- case 1:
- createDepot();
- break;
- case 2: removeDepot();
- break;
- case 3: listDepot();
- break;
- case 4: System.out.println("cool");
- break;
- case 5: addProduct();
- break;
- default: System.out.println("invalid option");
- }
- }
- while(choice!=9);
- }
- private void createDepot()
- {
- System.out.println("Please enter a Depot name");
- String n = console.nextLine();
- if(n.equals(depot1.getName()) || n.equals(depot2.getName()))
- {
- System.out.println("You have entered an already existing depot");
- System.out.println("Please enter a new Depot name");
- }
- else if (depot1.getName().equals("null")) {
- depot1.setName(n);
- System.out.println("else if reached");
- System.out.println(depot1.getName());
- }
- else {
- depot2.setName(n);
- System.out.println(" Final else reached");
- System.out.println(depot2.getName());
- }
- }
- private void removeDepot()
- {
- System.out.println("Please enter the name of the depot you wish to remove");
- String r = console.nextLine();
- if (r!= depot1.getName() || r!= depot2.getName()) {
- System.out.println("You have entered a non-existing Depot");
- System.out.println("Please enter the name of the depot you wish to remove");
- r = console.nextLine();
- }
- else if (r==depot1.getName()) {
- depot1 = null;
- System.out.print("You have removed depot1");
- }
- else depot2 = null;
- System.out.print("You have removed depot2");
- }
- private void listDepot()
- {
- if (depot1 == null && depot2 == null) {
- System.out.println("There are no Depots available");
- }
- else
- System.out.println(depot1.getName() + depot2.getName());
- }
- private void addProduct() {
- System.out.println("Enter product name");
- String nm = console.nextLine();
- System.out.println("Enter product price");
- double pr = console.nextDouble();
- System.out.println("Enter product weight");
- double wt = console.nextDouble();
- System.out.println("Enter product quantity");
- int qt = console.nextInt();
- depot1.addInfo(1, nm, pr, wt, qt);
- }
- public static void main(String[] args) {
- Interface intFace = new Interface();
- intFace.run();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement