Department of Computer Sciences: Subject Submitted To Submitted by Date of Submission
Department of Computer Sciences: Subject Submitted To Submitted by Date of Submission
Department of Computer Sciences: Subject Submitted To Submitted by Date of Submission
Sciences
Assignment No.01
package program1;
import java.util.Scanner;
public class Totalcost {
}
}
OUTPUT SCREEN SHOT::
question 1 .mp4
VIDEO:
Q.2. Program to take three integer values from user and calculate the
average and display the output.
Source Code:
import java.util.Scanner;
import java.util.Scanner;
/**
*/
double ftemp;
double Celsius;
//creating object
ftemp=scan.nextDouble();
Celsius =((5.0*(ftemp-32.0))/9.0);
}
OUTPUT SCREEN SHOT::
question 3.mp4
VIDEO:
Q.4. Write a program that will first print a menu as (Marks: 10) To enter marks of
ITCP press 1 To enter marks of OOP press 2 To enter marks for TBW press 3 To
enter marks for DBMS press 4 To exit press 52 After displaying this menu,
program should take input (1, 2, 3, 4 or 5) from user. After that display message
according to selected subject choice e.g. if user presses 1 then next message
should be How many quizzes of ITCP? Or if user presses 2 then message should be
as follow How many quizzes in OOP? and so on. After that receive total number
of quizzes in a specific subject from user and then ask user to enter marks of each
quiz (if quizzes are 5 you need to take 5 inputs: marks of 5 quizzes). After taking
marks print the average score in that subject and print the menu again. Program
should repeat this entire process (from displaying menu to average calculation)
again and again till user enters 5.
SOURCE CODE:
//import Scanner as we require it.
import java.util.Scanner;
//Take inputs
System.out.println("1\t To enter marks of ITCP press.");
System.out.println("2\t To enter marks of OOP press.");
System.out.println("3\t To enter marks for TBW press.");
System.out.println("4\t To enter marks for DBMS press.");
System.out.println("5\t To exit press ");
String s = input.next();
choice = s.charAt(0);
System.out.println("ist quiz:");
a = input.nextFloat();
System.out.println("2nd quiz:");
a = input.nextFloat();
System.out.println("3rd quiz:");
a = input.nextFloat();
System.out.println("4rd quiz:");
a = input.nextFloat();
System.out.println("5rd quiz:");
a = input.nextFloat();
sum = a+a+a+a+a;
break;
case '2':
System.out.println("How many quizzes of OOP?:");
a = input.nextFloat();
System.out.println("ist quiz:");
a = input.nextFloat();
System.out.println("2nd quiz:");
a = input.nextFloat();
System.out.println("3rd quiz:");
a = input.nextFloat();
System.out.println("4rd quiz:");
a = input.nextFloat();
System.out.println("5rd quiz:");
a = input.nextFloat();
sum = a+a+a+a+a;
break;
case '3':
System.out.println("How many quizzes of TBM?:");
a = input.nextFloat();
System.out.println("ist quiz:");
a = input.nextFloat();
System.out.println("2nd quiz:");
a = input.nextFloat();
System.out.println("3rd quiz:");
a = input.nextFloat();
System.out.println("4rd quiz:");
a = input.nextFloat();
System.out.println("5rd quiz:");
a = input.nextFloat();
sum = a+a+a+a+a;
break;
case '4':
System.out.println("How many quizzes of DBMS?:");
a =input.nextFloat();
System.out.println("ist quiz:");
a = input.nextFloat();
System.out.println("2nd quiz:");
a = input.nextFloat();
System.out.println("3rd quiz:");
a = input.nextFloat();
System.out.println("4rd quiz:");
a = input.nextFloat();
System.out.println("5rd quiz:");
sum = a+a+a+a+a;
break;
default:
System.out.println("Invalid choiceS");
}
System.out.println("Score = "+sum);
}
}
SCREEN SHOT::
question 4.mp4
VIDEO::
Q.5. Write a program in java to generate grocery bill (containing items purchased, quantity of each item, price per item
and total amount). For this purpose, program should ask user how many types of items purchased. Then it should ask for
name, quantity and price per item for each item. If there are total 5 different types of items then program should ask for
name, quantity and price per item five times and all should be saved appropriately. (Marks: 10) Hint: Use three arrays one
for item names, one for quantity and one for price per item as: Item Name 0 1 2 3 4 5 Egg Tissue Box Soap Mushrooms
Olives Detergent Quantity 0 1 2 3 4 5 12 5 4 2 1 1 Price Per Item 0 1 2 3 4 5 5 40 30 120 150 230 After taking this input,
program should calculate total amount and should display output as: Name Quantity Price per Item Egg 12 5 Tissue Box 5
40 Soap 4 30 Mushrooms 2 120 Olives 1 150 Detergent 1 230 Total Amount 575
SOURCE CODE::
package program5;
// FOR GETTING USER INPUT WE NEED TO IMPORT JAVA METHOD LIKE SCANNER
import java.util.Scanner;
public class bill {
// MAIN FUNCTION
public static void main(String[] args) {
//creatng string arrays objects for names
String Name[]=new String[40];
//creating arrays objects for quantities and prices
int quan[]=new int[10];
int price[]=new int[10];
int total[]=new int[20];
//intiallizing
int types_q;
int total_price=0;
Scanner sc=new Scanner(System.in);
System.out.println("\tHOW MANY ITEMS DO YOU WANT TO PURCHASE? : ");
System.out.println("**..............................................** : ");
//to getting the number of items from user
types_q=sc.nextInt();
System.out.println("ENTER THE Name OF ITEMS : ");
//for loop is used for taking the names of items
for(int i=0;i<=types_q; i++){
Name[i]=sc.nextLine();
}
System.out.println("ENTER PRICE Of Each ITEM : ");
//for loop is used for taking the prices of items
for(int i=1;i<=types_q; i++){
price[i]=sc.nextInt();
}
System.out.println("Enter The Quantity Of Each ITEM: ");
//for loop is used for taking the quantities of items from the user
for(int i=1;i<=types_q; i++){
quan[i]=sc.nextInt();
}
for(int i=1;i<=types_q;i++){
total[i]=quan[i]* price[i];
//calculating and displaying the total cost
System.out.println("\tName OF items : " + Name[i] + "\t\t Quantity of ITEM : " + quan[i]+
"\t\tprice of items : " + price[i] +"\tTotal price is : " + total[i]);
total_price+=total[i];
}
System.out.println("\nTotal price is : \t\t\t\t\t\t\t\t \t\t\t\t" + total_price);
}
}
SCREEN SHOT::
question 5.mp4
VIDEO::
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
class Product {
// properties
private final String pname;
private final int qty;
private final double price;
private final double totalPrice;
// constructor
Product(String pname, int qty,
double price, double totalPrice) {
this.pname = pname;
this.qty = qty;
this.price = price;
this.totalPrice = totalPrice;
}
// display
public void display() {
System.out.format("%-9s %8d %10.2f %10.2f\n",
pname, qty, price, totalPrice);
}
}
// variables
String productName = null;
int quantity = 0;
double price = 0.0;
double totalPrice = 0.0;
double overAllPrice = 0.0;
char choice = '\0';
do {
// read input values
System.out.println("Enter product details,");
System.out.print("Name: ");
productName = scan.nextLine();
System.out.print("Quantity: ");
quantity = scan.nextInt();
System.out.print("Price (per item): ");
price = scan.nextDouble();
// close Scanner
scan.close();
}
SCREEN SHOT:
question 5 part
b.mp4
VIDEO ::