Lab Report-1
Lab Report-1
Lab Report # 1
User Number:202100060
Lab01_Java_Basics (5 points)
Write a function in Java that takes in two integers as parameters and returns the power.
Write a function in Java that takes as parameters the number of hours a student registered, the
price of an hour, additional fees and then calculates the total amount that that student needs to
pay for that p articular semester.
Write a Java program that calculates the total amount of money you will have in your account
after 5 years if the original amount of money is 3000 and the interest rate is 3% per year.
import java.util.Scanner;
first = p.nextLine();
last = p.nextLine();
1
System.out.println("Enter your year of birth");
class Username {
2
Lab02_Classes_And_Objects (15 points)
Task# 1
import java.util.Scanner;
3
double size = checker.check(height, base);
class Username {
double size;
return size;
4
Task2#
/*
5
*/
package javaapplication89;
import java.util.Scanner;
tool.setRadius(p.nextDouble());
tool.display();
class Circle {
return radius;
6
area = Math.PI * Math.pow(radius, 2);
return area;
volume = 4.0/3*Math.PI*Math.pow(radius,3);
return volume;
public Circle() {
radius = 0.0;
radius = y;
this.radius = radius;
7
}
Task# 3
/*
*/
package javaapplication606;
8
public static void main (String [] args){
tool.setpartnum(p.nextLine());
tool.setpartdesc(p.nextLine());
tool.setquantity(p.nextInt());
tool.setPrice(p.nextInt());
System.out.println("Details: "+tool.getpartdesc());
class Invoice {
9
public void setpartnum(String x) {
pnum = x;
return pnum;
pdesc = y;
return pdesc;
num = n;
return num;
10
}
price = p;
return price;
return Value;
else return 0;
Task# 4
11
/*
*/
package javaapplication89;
System.out.println("Quantity: "+tool.getQuantity());
12
System.out.println("Price: "+tool.getPrice());
System.out.println();
System.out.println();
tool.setStationLocation("Khobar");
tool.setPetrolType("Super Premium");
tool.setQuantity(10);
tool.setPrice(3.15);
tool.setDiscount(0.05);
System.out.println("Quantity: "+tool.getQuantity());
System.out.println("Price: "+tool.getPrice());
class Petrolpurchase {
13
private double price=2.03, discount=0.10;
StationLocation = x;
return StationLocation;
PetrolType = y;
return PetrolType;
Quantity = n;
14
return Quantity;
price = p;
return price;
discount = d;
return discount;
15
}
Task# 1
/*
*/
package javaapplication89;
16
System.out.println("The initial date is: "+tool.getDay()+"/"+tool.getMonth()
+"/"+tool.getYear());
tool.setDay(11);
tool.setMonth(1);
tool.setYear(2003);
class Date {
return month;
this.month = month;
return day;
17
}
this.day = day;
return Year;
Year = year;
18
Task# 2
/*
*/
package javaapplication89;
import java.util.Scanner;
tool.setRadius(p.nextDouble());
19
tool.display();
class Circle {
return radius;
return area;
volume = 4.0/3*Math.PI*Math.pow(radius,3);
return volume;
public Circle() {
radius = 0.0;
20
}
radius = y;
this.radius = radius;
21
Task# 3
/*
*/
package javaapplication89;
tool1.setModel("Mazda");
22
tool1.setYear("2001");
tool1.setPrice(25000.0);
tool2.setModel("Toyota");
tool2.setYear("2005");
tool2.setPrice(50000.0);
tool1.display();
System.out.println();
tool2.display();
System.out.println();
tool1.display(0.05);
System.out.println();
tool2.display(0.07);
class Car {
return model;
23
this.model = model;
return year;
this.year = year;
return price;
if (price > 0) {
this.price = price;
24
private double price;
public Car(){
model = "Toyota";
year = "2005";
price = 25000.0;
System.out.println("Model: "+getModel());
System.out.println("Year: "+getYear());
System.out.println("Price "+getPrice());
System.out.println("Model: "+getModel());
System.out.println("Year: "+getYear());
System.out.println("Price "+afterdis);
25
Lab04_Inheritance (15 points)
Exercise 1:
/*
*/
package javaapplication606;
26
tool1.printmethod();
tool2.printmethod();
class PurchaseItem {
this.name = name;
this.unitPrice = unitPrice;
PurchaseItem(){
unitPrice = 0;
this.name = name;
27
}
this.unitPrice = unitPrice;
return name;
return unitPrice;
System.out.print(getName()+" @ "+getUnitPrice());
28
public weighedItem(String name, double unitPrice, double weight){
super(name, unitPrice);
this.weight = weight;
@Override
@Override
super.printmethod();
super(name, unitPrice);
this.quantity = quantity;
29
@Override
@Override
super.printmethod();
Exercise 2:
30
/*
*/
package javaapplication89;
System.out.println();
31
System.out.println(tool.toString());
System.out.println();
System.out.println();
System.out.println();
System.out.println(tool2.toString());
System.out.println();
class Book{
32
this.name = name;
this.author = author;
this.publish = publish;
@Override
public AudioBook(String name, String author, int publish, int size, int length, String
artistName) {
super(name,author,publish);
this.artistName = artistName;
this.length = length;
this.size = size;
@Override
33
}
public PaperBook(String name, String author, int publish, String publisher, String isbn){
this.publisher = publisher;
this.isbn = isbn;
@Override
34