OOP Assignment 1 (Omer Ishaq)
OOP Assignment 1 (Omer Ishaq)
ASSIGNMENT NO: 1
CLASS: BSCS-1(Bridging)
Input:
Output:
PROGRAM#2: TAKE THREE INTEGER VALUES FROM THE USER AND
CALCULATE THE AVERAGE. THEN DISPLAY THE OUTPUT.
Input:
Output:
PROGRAM#3: TAKE TEMPERATURE IN FAHRENHEIT AND CONVERT INTO
CELSIUS AND DISPLAY THE OUTPUT.
Input:
Output:
PROGRAM#4: CALCULATE AVERAGE MARKS FOR QUIZZZES IN
THE SELECTED SUBJECT.
Input:
Input (Continuation):
Output:
PROGRAM#5: GENERATE GROCERY BILL CONTAINING TYPES OF ITEMS
PURCHASED, QUANTITY OF EACH ITEM, PRICE PER ITEM BY TAKING
INPUT FROM USER AND THEN OUTPUT THE TOTAL AMOUNT.
Input:
import java.util.Scanner; // importing scanner class from java.util package
public class GroceryBill {
public static void main (String[] args) {
Scanner scan=new Scanner (System.in); // creating scanner class object
System.out.println ("How many types of items purchased?");
int type=scan.nextInt();
String item_name[]={"Egg ","Tissue Box","Soap 5","Mushrooms ","Olives
","Detergent 5" }; // static initializing a string type array
int quantity[]=new int[6]; // declaring a 1-D array with 6 elements
double priceperitem[]=new double[6]; // declaring an array
for (int i=0; i<6; i++){ // for loop for taking input from user
System.out.println ("Enter quantity of "+item_name[i]);
quantity[i]=scan.nextInt(); // assigning values to elements of array quantity
} // for closing
for (int i=0; i<6; i++){ // loop for storing price per item
System.out.println ("Enter price per item of "+item_name[i]);
priceperitem[i]=scan.nextDouble(); // storing price per item in array elements
} // for closing
System.out.println ("Name\t\t Quantity\t\tPrice per item"); // main heading output
for (int i=0; i<6; i++){ // loop for displaying quantity and price of particular item
System.out.println (item_name[i]+"\t\t"+quantity[i]+"\t\t\t"+priceperitem[i]);
}
Input (Continuation):
double total=0; //total is initialized here because of scope restrictions
for (int i=0; i<6; i++){ // loop for calculating total amount of grocery bill
total=total+(quantity[i]*priceperitem[i]);
} // for loop closing
System.out.println ("Total Amount = "+total+" Rs"); // output for total input
}} // main and class closing respectively
Output: