Home Glossary Java Program
Java Code:
import java.util.*;
public class household {
private String name;
private int quantity;
public household(String
Pname, int Phouse){
name=Pname;
quantity=Phouse;
}
public String getName(){
return name;
}
public int getQuantity(){
return quantity;
}
public static void main(String[] args){
household
mouthWash = new household("mouth Wash", 3765);
household dentalFloss = new household("dental floss", 3800);
household grassSeed = new household("grass seed", 2400);
household grassFertilizer = new household("grass fertilizer", 4012);
household BlueRay = new household("Blue-Ray DVD unit", 3580);
System.out.println( "Choose of the following products" );
System.out.println( "by entering a number 1-5 and pressing
\"Enter:\"");
System.out.printf( "1 - mouth Wash: %s household\n",
mouthWash.getQuantity() );
System.out.printf( "2 - dental flossr: %s household\n",
dentalFloss.getQuantity() );
System.out.printf( "3 - grass Seed: %s household\n",
grassSeed.getQuantity() );
System.out.printf( "4 - grass fertilizer: %s household\n",
grassFertilizer.getQuantity() );
System.out.printf( "5 - Blur-Ray DVD unit: %s household\n", BlueRay.getQuantity()
);
Scanner input = new Scanner( System.in );
int select;
int option = 0;
double result = 0;
String itemName;
System.out.println( "Select your any item:" );
select = input.nextInt();
if ( select == 1 ){
option = (mouthWash.getQuantity() );
itemName = ( mouthWash.getName() );
result = (option * .01);
System.out.printf( "The product \"%s\" has %s household.\n", itemName, option );
System.out.printf( "1 Percent of %s household = %s follow-up.", option, result);
System.out.print("\n");
}
else if ( select == 2 ){
option = (dentalFloss.getQuantity() );
itemName = ( dentalFloss.getName() );
result = (option * .01);
System.out.printf( "The product \"%s\" has %s household.\n", itemName, option );
System.out.printf( "1 Percent of %s household = %s follow-up.", option, result);
System.out.print("\n");
}
else if ( select == 3 ){
option = (grassSeed.getQuantity() );
itemName = ( grassSeed.getName() );
result = (option * .01);
System.out.printf( "The product \"%s\" has %s household.\n", itemName, option );
System.out.printf( "1 Percent of %s household = %s follow-up.", option, result);
System.out.print("\n");
}
else if( select == 4 ){
option = (grassFertilizer.getQuantity() );
itemName = ( grassFertilizer.getName() );
result = (option * .01);
System.out.printf( "The product \"%s\" has %s household.\n", itemName, option );
System.out.printf( "1 Percent of %s household = %s follow-up.", option, result);
System.out.print("\n");
}
else if( select == 5 ){
option = (BlueRay.getQuantity() );
itemName = ( BlueRay.getName() );
result = (option * .01);
System.out.printf( "The product \"%s\" has %s household.\n", itemName, option );
System.out.printf( "1 Percent of %s household = %s follow-up.", option, result);
System.out.print("\n");
}
int [] customers = new int [(int)result];
int number;
int min=1;
int max=option;
int range=max-min;
int x= customers.length;
for(int i=1; i<=x;i++){
number = (int) ( range * Math.random()
) + 1;
System.out.print(number +",");
if(i%7==0){
System.out.print("\n");
}
}
}
}
No comments:
Post a Comment