Hi
I am trying to solve an assignment question on Arrays... Pls see the code that i have written so far. Is there an alternative to System.exit(0) statement?
import java.util.*;
public class Computer
{
static String name;
static int size;
static int speed;
static String make;
static double price;
static int quantity;
public Computer(String n,int s,int sp,String m,double p,int q)
{
name=n;
size=s;
speed=sp;
make=m;
price=p;
quantity=q;
}
public String getName()
{
return name;
}
public int getSize()
{
return size;
}
public int getSpeed()
{
return speed;
}
public String getMake()
{
return make;
}
public double getPrice()
{
return price;
}
public int getQuantity()
{
return quantity;
}
public void valid()
{
if((price==0)||(price<0))
{
System.out.println("Please enter price");
System.exit(0);
}
else if((quantity==0)||(quantity<0))
{
System.out.println("Please enter quantity ");
System.exit(0);
}
else
{
displayData();
}
}
The code in main() displayed below reads the input from user and calls the constructor. I am unable to write the displayData() function. Can someone help?
public static void main(String args[])
{
System.out.println("Enter details");
Scanner input=new Scanner(System.in);
name=input.next();
size=input.nextInt();
speed=input.nextInt();
make=input.next();
price=input.nextDouble();
quantity=input.nextInt();
Computer comp=new Computer(name,size,speed,make,price,quantity);
comp.valid();
}
