ICSE Computer Science Java Programs | IT Developer
IT Developer

Java Programs - Solved 2013 ICSE Computer Science Paper



Share with a Friend

Solved 2013 ICSE Computer Science Paper

Class 10 - ICSE Computer Science Solved Papers

Class Object Fruit Juice Program - ICSE 2013 Computer Science

Define a class named FruitJuice with the following description:

Instance variables/data members:


int productCode – stores the product code number
String flavour – stores the flavour of the juice (Example: orange, apple, etc.)
String packType – stores the type of packaging (Example: tetra-pack, PET bottle, etc.)
int packSize – stores package size (Example: 200 ml, 400 ml, etc.)
int productPrice – stores the price of the product

Member methods:


FruitJuice() – default constructor to initialize integer data members to 0 and String data members to “”.
void input() – to input and store the product code, pack type, pack size and product price
void discount() – to reduce the price by 10
void display() – to display the product code, flavour, pack type, pack size and product price

import java.util.Scanner; class FruitJuice{ int productCode; String flavour; String packType; int packSize; int productPrice; public FruitJuice(){ productCode = 0; flavour = ""; packType = ""; packSize = 0; productPrice = 0; } public void input(){ Scanner in = new Scanner(System.in); System.out.print("Product code: "); productCode = Integer.parseInt(in.nextLine()); System.out.print("Flavour: "); flavour = in.nextLine(); System.out.print("Pack type: "); packType = in.nextLine(); System.out.print("Pack size: "); packSize = Integer.parseInt(in.nextLine()); System.out.print("Product price: "); productPrice = Integer.parseInt(in.nextLine()); } public void discount(){ productPrice -= 10; } public void display(){ System.out.println("Product code: " + productCode); System.out.println("Flavour: " + flavour); System.out.println("Pack type: " + packType); System.out.println("Pack size: " + packSize); System.out.println("Product price: " + productPrice); } public static void main(String[] args) { FruitJuice obj = new FruitJuice(); obj.input(); obj.discount(); obj.display(); } }

Output

 
 OUTPUT  : 
Product code: 1001
Flavour: Orange
Pack type: tetra-pack
Pack size: 200
Product price: 150
Product code: 1001
Flavour: Orange
Pack type: tetra-pack
Pack size: 200
Product price: 140