Lab 5 (JAVA) : Name-Chandan Kumar Reg no-18BCE1020 Fac-Prof. Sridevi
Lab 5 (JAVA) : Name-Chandan Kumar Reg no-18BCE1020 Fac-Prof. Sridevi
Name-Chandan Kumar
Reg no-18BCE1020
Fac- Prof. Sridevi
1. CODE:
→ Book.java
package java_lab_exercise;
String title;
double price;
→ Fiction.java
package java_lab_exercise;
@Override
void setPrice() {
this.price=24.99;
Fiction(String s){
this.title=s;
//setPrice();
}
→ NonFiction.java
package java_lab_exercise;
@Override
void setPrice(){
this.price=37.99;
NonFiction(String s){
this.title=s;
→ UseBook.java
package java_lab_exercise;
f1.setPrice();
nf1.setPrice();
}
OUTPUT:
2. CODE:
package java_lab_exercise;
import java.util.Scanner;
abstract class Themepark{
int n_adult,n_children;
int ticket_cost(){
int x=this.n_adult;
x=x*500;
int y=this.n_children;
y=y*300;
return x+y;
}
abstract void playGame();
}
}
else{
System.out.println("Thank You for playing!");
System.out.println("Stats for number of games not played");
for(int i=0;i<30;i++){
if(cnt[i]==0){
System.out.print(""+i+" ");
}
}
System.out.println("\nGames selected for more than one time:");
for(int i=0;i<30;i++){
if(cnt[i]>1){
System.out.print(""+i+" ");
}
}
System.out.print("\n");
temp=false;
}
}
}
}
@Override
void playGame(){
int[] cnt=new int[40];
for(int i=0;i<40;i++){
cnt[i]=0;
}
int k;
boolean temp=true;
while(temp){
System.out.println("Enter game number (0-39) press other to exit:");
k=scan.nextInt();
if(k>=0 && k<40){
if(Games[k]==false){
Games[k]=true;
cnt[k]=1;
}
else{
System.out.println("Already played this game!");
cnt[k]++;
}
}
else{
System.out.println("Thank You for playing!");
System.out.println("Stats for number of games not played");
for(int i=0;i<40;i++){
if(cnt[i]==0){
System.out.print(""+i+" ");
}
}
System.out.println("\nGames selected for more than one time:");
for(int i=0;i<40;i++){
if(cnt[i]>1){
System.out.print(""+i+" ");
}
}
System.out.print("\n");
temp=false;
}
}
}
}
public class Lab4_q2 {
public static void main(String[] args){
System.out.println("Queensland");
Queensland q1=new Queensland(10,10);
q1.ticket_cost();
q1.playGame();
System.out.println("Wonderla");
Wonderla w1=new Wonderla(5,5);
w1.ticket_cost();
w1.playGame();
}
}
OUTPUT:
3. CODE
package java_lab_exercise;
interface Shape3D{
double getVolume();
}
interface Solid3D{
double getDensity();
double getMass();
}
@Override
public double getMass() {
return(this.getVolume()*this.density);
}
}
OUTPUT: