






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
INcluding complex programs,uml,and uml implemented codes.
Typology: Exams
1 / 12
This page cannot be seen from the preview
Don't miss anything!







University of Engineering& Technology
SUBMITTED BY: SHEIKH ABUZAR AMJAD REG NO: 19-CP- SUBMITTED TO: DR RIZWAN SB
Department of Computer Engineering
Q No 01:- Required is a program that reads in various record files with similar structure {name, roll, admission category, email, blood group, technology and domicile} and combines them into single file by removing duplicate entries (if there is any) and ensuring no data loss. Assuming the file type yourself, build appropriate classes in order to do the job. Present your design in class diagrams and do the coding, test and validate your results before dispatching solution. CODE package javaapplication4; /**
Q No 02:- The following is a short snippet of code that simulates rolling a 6-sided dice 100 times. There is an equal chance of rolling any digit from 1 to 6. public static void printDiceRolls(Random randGenerator) { for (int i = 0; i < 100; i++) { System.out.println(randGenerator.nextInt(6) + 1); } } public static void main(String[] args) { Random randGenerator = new Random(); printDiceRolls(randGenerator); } Create your own class, LoadedDice, that is derived from Random. The constructor for LoadedDice needs to only invoke Random’s constructor. Override the public int nextInt(int num) method so that with a 50% chance, your new method always returns the largest number possible (i.e., num – 1), and with a 50% chance, it returns what Random’s nextInt method would return. Test your class by replacing the main method with the following: LoadedDice myDice = new LoadedDice(); printDiceRolls(myDice); do you need to change the printDiceRolls method while takes a parameter of type Random. Does polymorphism tell Java to invoke LoadedDice’snextInt() method instead of Random’s nextInt() method.
Answer:
CODE- / package javaapplication2; /*
OUTPUT Q No 03:- Implement the animal class hierarchy given here
public boolean GetGender() { return(gender); } public boolean IsMale() { return(gender==false); } public boolean IsFemale() { return(gender==true); } public boolean IsMammal() { return(mammal==true); } } class Duck extends Animal { protected String beakColor; public Duck() { beakColor="yellow"; } public void SetBeakColor(String colorStr) { beakColor = new String(colorStr); } public void swim() { System.out.println("duck swimming... "); } public void Quack() { System.out.println("Quack"); } } class Fish extends Animal { protected int size; protected boolean canEat; public void SetSize(int n) { size=n; } public void SetCanEat() { canEat=true; } public void SetCannotEat() { canEat=false; } public int GetSize() { return(size); } public boolean CanEat() { return(canEat==true); } public void swim() { System.out.println(" fish is swimming ");
class Zebra extends Animal { protected boolean is_wild; public void SetWild() { is_wild=true; } public void SetTame() { is_wild=false; } public boolean IsWild() { return(is_wild==true); } public void run() { System.out.println(" zebra is running..."); } } class MyZoo { public static void main(String args[]) { Duck duck = new Duck(); Zebra zebra = new Zebra(); Fish fish = new Fish(); duck.swim(); zebra.run(); fish.swim(); duck.SetAge(1); fish.SetAge(2); zebra.SetAge(4); System.out.println(" duck age = " + duck.GetAge() + " : zebra age = " + zebra.GetAge()); } } OUTPUT