icse-promo

Question

Define a class called FruitJuice with the following description:

Instance variables/data members:
int product_code – stores the product code number
String flavour – stores the flavour of the juice.(orange, apple, etc)
String pack_type – stores the type of packaging (tetra-pack, bottle etc)
int pack_size – stores package size (200ml, 400ml etc)
int product_price – stores the price of the product

Member Methods:
FruitJuice() – default constructor to initialize integer data members
to zero and string data members to “”.
void input() – to input and store the product code, flavor, pack type,
pack size and product price.
void discount() – to reduce the product price by 10.
void display() – to display the product code, flavor, pack type,
pack size and product price.

Share code with your friends

Share on whatsapp
Share on facebook
Share on twitter
Share on telegram

Code

				
					import java.util.Scanner;

public class FruitJuice 
{
	int product_code;
	String flavour;
	String pack_type;
	int pack_size;
	int product_price;
	public FruitJuice()
	{
		product_code = 0;
		flavour = "";
		pack_type = "";
		pack_size = 0;
		product_price = 0;
	}
	public void input()
	{
		Scanner sc = new Scanner(System.in);
		System.out.println("Enter product code: ");
		product_code = sc.nextInt();
		System.out.println("Enter flavour: ");
		flavour = sc.next();
		System.out.println("Enter pack type: ");
		pack_type = sc.next();
		System.out.println("Enter pack size: ");
		pack_size = sc.nextInt();
		System.out.println("Enter product price: ");
		product_price = sc.nextInt();
	}
	public void discount()
	{
		product_price = product_price-10;
	}
	public void display()
	{
		System.out.println("Product Code: " + product_code);
		System.out.println("Flavour: " + flavour);
		System.out.println("Pack Type: " + pack_type);
		System.out.println("Pack Size: " + pack_size);
		System.out.println("Product Price: " + product_price);
	}
}


				
			

Coding Store

Leave a Reply

Your email address will not be published. Required fields are marked *