merhabalar ögrenciyim 2.dönem itibari ile java ögreniyoruz asagıdaki programda ögrenme amacli ödevimiz yani cok anlamlı bi program sayılmayabilir:)asagida yanina soru isareti koydugum satira gelince program hata veriyor ben bi hata göremiyorum neden sorun yapıyor anlamadım sevabına bi bakın hele:)saat üc oldu kafayı yiyorum bnce gayet calismasi lazım yaw
import java.util.Scanner;
public class Store {
private Product[] products;
private Customers[] customers;
private int index;
public static int totalSoldP;
Scanner s=new Scanner(System.in);
public Store()
{
products=new Product[20];
setCustomers(new Customers[10]);
}
public void menu()
{
System.out.println("Menu\n 1-Products\n 2-Customers\n enter your choice:");
int sec=s.nextInt();
switch(sec)
{
case 1:System.out.println("PRODUCTS\n 1-Define new products\n 2-Sell products\n 3-Set selling price\n 4-List of products and how many are sold from each product \n enter your choice:");
switch(s.nextInt())
{
case 1:newProduct();break;
case 2:System.out.println("enter the name of the product to sell:");
int c=testCode(s.next());
if(c!=-1)
products[c].sellProduct();break;
case 3:System.out.println("enter the name of the product:");
c=testCode(s.next());
if(c!=-1){
System.out.println("enter the new price:");
products[c].setPrice(s.nextInt());}break;
case 4:listProduct();break;
}break;
case 2:System.out.println("CUSTOMERS");
}
}
private void newProduct()
{
do{
index++;
System.out.print("enter the name:");
String n=s.next();
System.out.print("the description:");
String d=s.next();
System.out.print("the price:");
int p=s.nextInt();
System.out.print("the stock:");
int st=s.nextInt();
?????????????? products[index]=new Product(n,index,d,p,st);
System.out.println("press -1 to exit");
}while(s.nextInt()!=-1);
}
private int testCode(String n)
{
for(int i=0;i<=index;i++)
{
if(n.equals(products.getName()))
return i;
}
System.out.println("the product you entered doesn't exist!");
return -1;
}
private void listProduct()
{int i=0;
System.out.println("to exit press -1");
System.out.println("code name amount");
do{
System.out.print("enter the index:");i=s.nextInt();
System.out.printf("%d %s %d\n",products.getPcode(),products.getName(),products.getSold());
}while(i!=-1);
}
public void setCustomers(Customers[] customers) {
this.customers = customers;
}
public Customers[] getCustomers() {
return customers;
}
}
**************************************************
import java.util.Scanner;
public class Product {
private String name;
private int pcode;
private String description;
private int price;
private int stock;
private int sold;
public Product(String name,int pcode,String description,int price,int stock)
{
this.name=name;
this.pcode=pcode;
setPrice(price);
this.stock=stock;
this.setDescription(description);
}
public Product()
{
}
public void sellProduct()
{ Scanner a=new Scanner(System.in);
System.out.println("enter the quantity you want to sell:");
int k=a.nextInt();
if(stock>=k){
stock-=k;
sold+=k;
Store.totalSoldP=Store.totalSoldP+k*this.price;}
else
System.out.println("There is only %d product(s) in inventory");
}
public void setVariable(String n,String d,int p,int pr,int s)
{
this.name=n;
this.description=d;
this.pcode=p;
this.price=pr;
this.stock=s;
}
public void setPrice(int price) {
this.price = price;
}
public String getName() {
return name;
}
public int getPrice() {
return price;
}
public int getSold() {
return sold;
}
public int getPcode() {
return pcode;
}
public int getStock() {
return stock;
}
public void setDescription(String description) {
this.description = description;
}
public String getDescription() {
return description;
}
}