Я абсолютный новичок, и я пишу программу для интернет-магазина, у меня есть 3 отдела, и я начал с женского отдела. Я спрашиваю пользователя, хотят ли они добавить еще один продукт, и если да, то я пытаюсь повторить программу и добавить значения для каждого повторения и вывести только итог, но мой код работает не так, как мне нужно это на работу.
public class WomenDep extends Shop{
int a,c,d,NoOfSizes=3,Counter;
double b,Total;
Prices P1 = new Prices();
double []arr = new double[NoOfSizes];
@Override
public void GetDet(){
System.out.println("Pls Select Product No., \n(1)--> Tshirt\n(2)--> Short\n(3)--> Jeans\n"
+ "(4)--> Dress\n(5)--> Skirts");
a = input.nextInt();
System.out.println("Pls Select required Size No., \n(1)-->S\n(2)-->M\n(3)-->L");
b = input.nextDouble();
System.out.println("Enter Number of Pieces");
c = input.nextInt();
this.Pieces=c;
System.out.println("Do you want to add another product to your cart?\n(1)-->Yes\n(2)-->No");
d = input.nextInt();
}
@Override
public double [] SearchArr(){
if(this.a==1){
this.ProductName = "Tshirt";
for (int i = 0; i<NoOfSizes; ++i)
arr[i]=P1.WTshirt[i];
}
if(this.a==2){
this.ProductName = "Short";
for (int i = 0; i<NoOfSizes; ++i)
arr[i]=P1.WShort[i];
}
if(this.a==3){
this.ProductName = "Jeans";
for (int i = 0; i<NoOfSizes; ++i)
arr[i]=P1.WJeans[i];
}
if(this.a==4){
this.ProductName = "Dress";
for (int i = 0; i<NoOfSizes; ++i)
arr[i]=P1.WDress[i];
}
if(this.a==5){
this.ProductName = "Skirts";
for (int i = 0; i<NoOfSizes; ++i)
arr[i]=P1.WSkirts[i];
}
return arr;
}
@Override
public double CalPrice(){
if(b==1){
Price = arr [0];}
if(b==2){
Price = arr [1];}
else if(b==3){
Price = arr [2];}
return Price;
}
@Override
public void TotalPrice(){
TPrice =Price * Pieces;
System.out.println("this is total Price "+TPrice);
}
@Override
public void Recal(){
do{
this.GetDet();
this.SearchArr();
this.CalPrice();
this.TotalPrice();
}while(d==1);
}
}
public class Prices extends Shop{
public double [] WTshirt = {60.00,100.5,120};//S,M,L
public double [] WShort = {50,110,130.5};//S,M,L
public double [] WJeans = {150.99,180,200};//S,M,L
public double [] WDress = {350,400,450.99};//S,M,L
public double [] WSkirts = {350.5,499.99,450.5};//S,M,L
}
public static void main(String[] args) {
WomenDep a = new WomenDep();
a.Recal();
}
Я ожидаю, что он будет добавлять общую стоимость рассчитанной цены каждый раз, но он только вычисляет единицу.