/**
Saadman's ISU
**/

import java.io.*;
import java.util.*;


public class ISU
 {
     public static void main (String[]args)
     {

         //Keyboard Initialization
         Scanner kbin = new Scanner(System.in);




         //Variable Inititialization & Declaration;

            String list[] = new String [21];

            int price1 = 30;
            int price2 = 20;
            int price3 = 25;
            int price4 = 15;
            int price5 = 29;
            int price6 = 34;
            int price7 = 49;
            int price8 = 32;
            int price9 = 50;
            int price10 = 17;
            int price11 = 20;
            int price12 = 35;
            int price13 = 42;
            int price14 = 36;
            int price15 = 38;
            int price16 = 55;
            int price17 = 17;
            int price18 = 21;
            int price19 = 22;
            int price20 = 21;

            int j=21;
            int invalid=0;

            double totalcost=0;

            double discount1 = 0.10;
            double discount2 = 0.15;

            double tax = 0.13;

            String a = "Your total price is: ";
            String b = "(With Discount)";


            int choice;


list [0] = "Harry Potter";
list [1] = "Programming For Beginners";
list [2] = "Life Of Pi";
list [3] = "The Hunger Games";
list [4] = "Eragon";
list [5] = "A Lesson Before Dying";
list [6] = "David Copperfield";
list [7] = "Murder On 10th Street";
list [8] = "Easy Recipes";
list [9] = "Beginners Guide To Web Design";
list [10] = "Twilight";
list [11] = "Kids Stories Collection";
list [12] = "Catcher In The Rye";
list [13] = "Chronicles Of Narnia";
list [14] = "History Of Computers";
list [15] = "Photoshop For Dummies";
list [16] = "Complete Idiot's Guide To Learning Guitar";
list [17] = "The Alchemist";
list [18] = "Diary Of A Wimpy Kid";
list [19] = "The Lovely Bones";





//Display Menu


System.out.println("\n\n\t\t*************    *************");
System.out.println("\t\t*            *  *            *");
System.out.println("\t\t*             **             *");
System.out.println("\t\t*             **             *");
System.out.println("\t\t*             **             *");
System.out.println("\t\t*             **             *");
System.out.println("\t\t*             **             *");
System.out.println("\t\t*             **             *");
System.out.println("\t\t*             **             *");
System.out.println("\t\t*             **             *");
System.out.println("\t\t*             **             *");
System.out.println("\t\t*             **             *");
System.out.println("\t\t*             **             *");
System.out.println("\t\t*            *  *            *");
System.out.println("\t\t*************    *************");
System.out.println("\n");

System.out.println("\t\tWELCOME TO SAADMAN'S BOOK STORE!");

System.out.println("\tCheck out our latest offers on select books!");

System.out.println("\n\n\tThe Hunger Games: 10% Off!");

System.out.println("\n\tEragon: 15% Off!");





//Input;

choice = 1;
while (choice == 1) {



    if(j==21)
    {

System.out.println("\n\n\tWhat Book would you like to search? : ");
System.out.println
("\n");
System.out.print("  ");


String Target = kbin.nextLine();


//Processing;





for (int i=0; i<20; i++)

        if (list[i] != null && (list[i].equals(Target))){

        System.out.println("\n\n");

        invalid=1;

        j=i;

                System.out.print("\tYou chose: " + list[i]);
        }



        System.out.println("\n");

if(invalid==1)
{
//Output;


        if (list[j] != null && (list[j].equals(list[0]))){

        System.out.println("\n");


        try {
            Thread.sleep(2300);
        } catch(InterruptedException ex) {
            Thread.currentThread().interrupt();
        }


        System.out.print("\tPrice of book: $" + price1);

        //System.out.println("\n");

        totalcost = (price1+(price1*tax));

        System.out.printf("%n%n\t%s%.2f", a , totalcost);

System.out.println("\n");

        } else if (list[j] != null && (list[j].equals(list[1]))){

        System.out.println("\n");

                try {
                    Thread.sleep(2300);
                } catch(InterruptedException ex) {
                    Thread.currentThread().interrupt();
        }



        System.out.print("\tPrice of book: $" + price2);

        //System.out.println("\n");

        totalcost = (price2+(price2*tax));

        System.out.printf("%n%n\t%s%.2f", a , totalcost);

System.out.println("\n");
} else if (list[j] != null && (list[j].equals(list[2]))){

        System.out.println("\n");


        try {
            Thread.sleep(2300);
        } catch(InterruptedException ex) {
            Thread.currentThread().interrupt();
        }



        System.out.print("\tPrice of book: $" + price3);

        //System.out.println("\n");

        totalcost = (price3+(price3*tax));

        System.out.printf("%n%n\t%s%.2f", a , totalcost);

System.out.println("\n");
} else if (list[j] != null && (list[j].equals(list[3]))){

        System.out.println("\n");

        try {
            Thread.sleep(2300);
        } catch(InterruptedException ex) {
            Thread.currentThread().interrupt();
        }



        System.out.print("\tPrice of book: $" + price4);

        //System.out.println("\n");

        totalcost = (price4 + (((price4) - (price4*discount1))*tax));

        System.out.printf("%n%n\t%s%.2f%s", a , totalcost , b);

System.out.println("\n");
}else if (list[j] != null && (list[j].equals(list[4]))){

        System.out.println("\n");

        try {
            Thread.sleep(2300);
        } catch(InterruptedException ex) {
            Thread.currentThread().interrupt();
        }



        System.out.print("\tPrice of book: $" + price5);

        //System.out.println("\n");

        totalcost = (price5 + (((price5) - (price5*discount2))*tax));

        System.out.printf("%n%n\t%s%.2f%s", a , totalcost , b);

System.out.println("\n");
}else if (list[j] != null && (list[j].equals(list[5]))){

        System.out.println("\n");

        try {
            Thread.sleep(2300);
        } catch(InterruptedException ex) {
            Thread.currentThread().interrupt();
        }



        System.out.print("\tPrice of book: $" + price6);

        //System.out.println("\n");

        totalcost = (price6+(price6*tax));

        System.out.printf("%n%n\t%s%.2f", a , totalcost);

System.out.println("\n");
}else if (list[j] != null && (list[j].equals(list[6]))){

        System.out.println("\n");

        try {
            Thread.sleep(2300);
        } catch(InterruptedException ex) {
            Thread.currentThread().interrupt();
        }


        System.out.print("\tPrice of book: $" + price7);

        //System.out.println("\n");

        totalcost = (price7+(price7*tax));

        System.out.printf("%n%n\t%s%.2f", a , totalcost);

System.out.println("\n");
}else if (list[j] != null && (list[j].equals(list[7]))){

        System.out.println("\n");

        try {
            Thread.sleep(2300);
        } catch(InterruptedException ex) {
            Thread.currentThread().interrupt();
        }


        System.out.print("\tPrice of book: $" + price8);

        //System.out.println("\n");

        totalcost = (price8+(price8*tax));

        System.out.printf("%n%n\t%s%.2f", a , totalcost);

System.out.println("\n");
}else if (list[j] != null && (list[j].equals(list[8]))){

        System.out.println("\n");

        try {
            Thread.sleep(2300);
        } catch(InterruptedException ex) {
            Thread.currentThread().interrupt();
        }


        System.out.print("\tPrice of book: $" + price9);

        //System.out.println("\n");

        totalcost = (price9+(price9*tax));

        System.out.printf("%n%n\t%s%.2f", a , totalcost);

System.out.println("\n");
}else if (list[j] != null && (list[j].equals(list[9]))){

        System.out.println("\n");

        try {
            Thread.sleep(2300);
        } catch(InterruptedException ex) {
            Thread.currentThread().interrupt();
        }


        System.out.print("\tPrice of book: $" + price10);

        //System.out.println("\n");

        totalcost = (price10+(price10*tax));

        System.out.printf("%n%n\t%s%.2f", a , totalcost);

System.out.println("\n");
}else if (list[j] != null && (list[j].equals(list[10]))){

        System.out.println("\n");

        try {
            Thread.sleep(2300);
        } catch(InterruptedException ex) {
            Thread.currentThread().interrupt();
        }


        System.out.print("\tPrice of book: $" + price11);

        //System.out.println("\n");

        totalcost = (price11+(price11*tax));

        System.out.printf("%n%n\t%s%.2f", a , totalcost);

System.out.println("\n");
}else if (list[j] != null && (list[j].equals(list[11]))){

        System.out.println("\n");

        try {
            Thread.sleep(2300);
        } catch(InterruptedException ex) {
            Thread.currentThread().interrupt();
        }

        System.out.print("\tPrice of book: $" + price12);

        //System.out.println("\n");

        totalcost = (price12+(price12*tax));

        System.out.printf("%n%n\t%s%.2f", a , totalcost);

System.out.println("\n");
}else if (list[j] != null && (list[j].equals(list[12]))){

        System.out.println("\n");

        try {
            Thread.sleep(2300);
        } catch(InterruptedException ex) {
            Thread.currentThread().interrupt();
        }



        System.out.print("\tPrice of book: $" + price13);

        //System.out.println("\n");

        totalcost = (price13+(price13*tax));

        System.out.printf("%n%n\t%s%.2f", a , totalcost);

System.out.println("\n");
}else if (list[j] != null && (list[j].equals(list[13]))){

        System.out.println("\n");

        try {
            Thread.sleep(2300);
        } catch(InterruptedException ex) {
            Thread.currentThread().interrupt();
        }


        System.out.print("\tPrice of book: $" + price14);

        //System.out.println("\n");

        totalcost = (price14+(price14*tax));

        System.out.printf("%n%n\t%s%.2f", a , totalcost);

System.out.println("\n");
}else if (list[j] != null && (list[j].equals(list[14]))){

        System.out.println("\n");

        try {
            Thread.sleep(2300);
        } catch(InterruptedException ex) {
            Thread.currentThread().interrupt();
        }



        System.out.print("\tPrice of book: $" + price15);

        //System.out.println("\n");

        totalcost = (price15+(price15*tax));

        System.out.printf("%n%n\t%s%.2f", a , totalcost);

System.out.println("\n");
}else if (list[j] != null && (list[j].equals(list[15]))){

        System.out.println("\n");

        try {
            Thread.sleep(2300);
        } catch(InterruptedException ex) {
            Thread.currentThread().interrupt();
        }


        System.out.print("\tPrice of book: $" + price16);

        //System.out.println("\n");

        totalcost = (price16+(price16*tax));

        System.out.printf("%n%n\t%s%.2f", a , totalcost);

System.out.println("\n");
}else if (list[j] != null && (list[j].equals(list[16]))){

        System.out.println("\n");

        try {
            Thread.sleep(2300);
        } catch(InterruptedException ex) {
            Thread.currentThread().interrupt();
        }




        System.out.print("\tPrice of book: $" + price17);

        //System.out.println("\n");

        totalcost = (price17+(price17*tax));

        System.out.printf("%n%n\t%s%.2f", a , totalcost);

System.out.println("\n");
}else if (list[j] != null && (list[j].equals(list[17]))){

        System.out.println("\n");

        try {
            Thread.sleep(2300);
        } catch(InterruptedException ex) {
            Thread.currentThread().interrupt();
        }



        System.out.print("\tPrice of book: $" + price18);

        //System.out.println("\n");

        totalcost = (price18+(price18*tax));

        System.out.printf("%n%n\t%s%.2f", a , totalcost);

System.out.println("\n");
}else if (list[j] != null && (list[j].equals(list[18]))){

        System.out.println("\n");

        try {
            Thread.sleep(2300);
        } catch(InterruptedException ex) {
            Thread.currentThread().interrupt();
        }


        System.out.print("\tPrice of book: $" + price19);

        //System.out.println("\n");

        totalcost = (price19+(price19*tax));

        System.out.printf("%n%n\t%s%.2f", a , totalcost);

System.out.println("\n");
}else if (list[j] != null && (list[j].equals(list[19]))){

        System.out.println("\n");

        try {
            Thread.sleep(2300);
        } catch(InterruptedException ex) {
            Thread.currentThread().interrupt();
        }

        System.out.print("\tPrice of book: $" + price20);

        //System.out.println("\n");

        totalcost = (price20+(price20*tax));

        System.out.printf("%n%n\t%s%.2f", a , totalcost);

System.out.println("\n");









} else

    System.out.println("\n\tThis does not exist in our shop!");


}



}




        System.out.println("\n\tDo want to continue shopping? ");

        System.out.println("\n\n\tPress 1 for 'Yes' or 0 for 'No'  ");

        System.out.print("  ");
        choice  = kbin.nextInt();
choice = 2;
while (choice == 2) {

        if (choice == 1){

            choice = 1;

        } else if (choice == 0) {


        System.out.println("\n\tThank you for shopping here");

        System.out.println("\n\n");


        System.exi

        }else if (choice != 1 && choice != 0) {


        System.out.println("\n\tInput invalid. Please try again.  ");

        System.out.println("\n\n");

        choice = 2;

    }


}
}

//System.exit(0);












     } //end main;
 } // end class;

Recommended Answers

All 9 Replies

Hello JustLeftRavenholm, welcome to DaniWeb
That's a whole lot of code. It's unlikely that anyone will take the time to understand a 600 line method with very few comments, a strange mixture of arrays and repeated variables (price1-20), and little or no indentation to clarify the structure. Exactly what is your question?

JamesCherrill,

umm.. sorry for the messed up huge pile of code..

but im desperate.. this is due tuesday..

my program is like a book shop catalogue kinda thing..

at first it prompts the user to search what book they want.. and then takes the book and shows the price with tax and everything..

however, after thats done.. i want it to ask the user if they want to continue and search another book which should start the program again, or if they want to stop and the program would stop,

press 1 for yes and 0 for no... and if u press any other number.. it supposed to ask u the question...

i cant do the ending part.. :( please help

You need a loop that processes one search at at time. A do-while loop is ideal,eg (pseudo-code)

do {
   // search for book, show price etc
   prompt for continue 1/0
} while (answer is 1);

within that, in place of the "prompt for continue 1/0", you may have another loop to reject answers that are not 1 or 0, eg

   do  {
      prompt for continue 1/0
   } while (answer is not 1 or 0);

I'll leave the Java syntax up to you

ok so

do {

my whole program..

....

and then, 

        System.out.println("\n\tDo want to continue shopping? ");

        System.out.println("\n\n\tPress 1 for 'Yes' or 0 for 'No'  ");

        System.out.print("  ");
        choice  = kbin.nextInt();

}while (choice == 1);

but how do i make it so if choice is 0 it stops and if i press any other number than 1 or 0 it asks the user to input 1 or 0 again and gives the option to input again

In the code above, if choice is not 1 it will stop performing the do-while loop and go on to the next statement (line 17). If that's the end of your main method, your program will exit normally.
See previous post for general approach to re-prompting for numbers not 1 or 0.

at present, if i press 1 it just asks the question again if i want to continue again.. it doesnt restart the program.. it doesnt ask what book i want...

and if i press any other number it just stops..

how do i restart my program from the beginning after i press 1

Probably just an error in where you have the do statements and/or {}. With such a large unstructured method that was always going to be a danger. I'm going out any moment now, so can't look at it until tomorrow. Maybe someone else can help for now?

you could also show here what you've implemented...
for instance like:

do{
// ... previous code (you don't have to copy paste all of that
readInputForTest
}
while (test==1)

that might help us to see what's wrong with it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.