I'm currently working on a project that was assigned to me and I'm having a bit of trouble trying to find out how I should start. This assignment is to rewrite a program using classes instead of just putting everything into the main program. Here is my code that I created that has to rewritten:
public class Lab14 {
public static void main(String[] args) {
int Numbook1=0;
int Numbook2=0;
int Numbook3=0;
double priceOfDesignPatterns=32.46;
double priceOfEffectiveJava=35.48;
double priceOfJavaPuzzlers=27.86;
String book1="Design Patterns";
String book2="Effective Java";
String book3="Java Puzzlers";
final double SALES_TAX=.065;
String choice;
int finished=0;
Scanner input=new Scanner(System.in);
System.out.println("Welcome to ECommerce!");
System.out.println("The books we have in stock are: ");
System.out.println(book1+", "+book2+", "+book3);
System.out.println("Please enter the name of the book you wish to purchase. Press 'q' to quit.");
while (finished==0)
{
choice=input.nextLine();
if (choice.equals(book1))
{
System.out.println("How many "+book1+"(s) do you wish to buy?");
Numbook1=(input.nextInt())+Numbook1;
System.out.println(Numbook1+" copies of "+book1+" are in your cart.");
System.out.println("Enter the name of the next book you would like to purchase, or press 'q' to quit.");
}
else if (choice.equals(book2))
{
System.out.println("How many "+book2+"(s) do you wish to buy?");
Numbook2=(input.nextInt())+Numbook2;
System.out.println(Numbook2+" copies of "+book2+" are in your cart.");
System.out.println("Enter the name of the next book you would like to purchase, or press 'q' to quit.");
}
if (choice.equals(book3))
{
System.out.println("How many "+book3+"(s) do you wish to buy?");
Numbook3=(input.nextInt())+Numbook3;
System.out.println(Numbook3+" copies of "+book3+" are in your cart.");
System.out.println("Enter the name of the next book you would like to purchase, or press 'q' to quit.");
}
if (choice.equals("q"))
{
double total=0;
double totalTax=0;
total=(Numbook1*priceOfDesignPatterns)+(Numbook2*priceOfEffectiveJava)+(Numbook3*priceOfJavaPuzzlers);
totalTax=total*SALES_TAX;
System.out.println("Your cart contains: ");
System.out.println(Numbook1+" "+book1+"(s), "+Numbook2+" "+book2+"(s), "+Numbook3+" "+book3+"(s).");
System.out.println("Sales Tax: $"+totalTax);
System.out.println("Your total cost is: $"+(totalTax+total));
finished=1;
}
}
}
}
Now I know that I have to write a couple of classes to construct book1,2,3
and also to set the price and access them later, but I'm just really lost on how to start the process and aggregate everything together. If someone could guide me in the right direction it would be greatly appreciated! Thank you so much.