0% found this document useful (0 votes)
2 views

Assignment- familiar questions in java

The document contains a series of exercises and assignments written in Dart programming language, demonstrating various programming concepts such as conditional statements, loops, classes, and object-oriented programming. Each exercise showcases different functionalities, including calculating shipping costs, generating random passwords, and managing a todo list. The assignments also illustrate the use of inheritance, method overriding, and data structures like lists and maps.

Uploaded by

kavana944922
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Assignment- familiar questions in java

The document contains a series of exercises and assignments written in Dart programming language, demonstrating various programming concepts such as conditional statements, loops, classes, and object-oriented programming. Each exercise showcases different functionalities, including calculating shipping costs, generating random passwords, and managing a todo list. The assignments also illustrate the use of inheritance, method overriding, and data structures like lists and maps.

Uploaded by

kavana944922
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

Name: Kavana N

USN: 1MS23CS086 (Section B)


Department: CSE

Exercise-01
void main() {
String dez = 'PQR';
List<int> cost = [5, 7, 10];
if (dez == 'XYZ') {
print('Shipping cost for $dez is ${cost[0]} per kilogram');
} else if (dez == 'ABC') {
print('Shipping cost for $dez is ${cost[1]} per kilogram');
} else if (dez == 'PQR') {
print('Shipping cost for $dez is ${cost[2]} per kilogram');
} else {
print('Error in destination zone');
}
}

Exercise-02
void main() {
int cost = 850;
int num = 0;
if (num != 0) {
double cost_of_each_person = cost / num;
print('Bill of each person = $cost_of_each_person');
} else {
print('Number of people cannot be zero');
}
}

Exercise-03
void main() {
List a = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89];
for (int i = 0; i < a.length; i++) {
if (a[i] < 5) {
print(a[i]);
}
}
}

Exercise-04
import 'dart:io';
void main() {
var nums = stdin.readLineSync();
var numList = elements.split(',');
print('List: $numList');
var numSet = <String> {};
for (var x in numList) {
numSet.add(x);
}
print('Set: $numSet');
}

Assignment-01
import 'dart:math';
void main() {
var random = new Random();
int num = random.nextInt(1000);
var var1 = random.hashCode;
var str1,str2,str3,str4,str5;
List<String> srt1=
['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'];
List<String> srt2= ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'];
str1=srt1[random.nextInt(24)];
str2=srt1[random.nextInt(24)];
str3=srt2[random.nextInt(24)];
str4=srt2[random.nextInt(24)];
str5=srt1[random.nextInt(24)];
print('Random Generated Password : $num$str1$str2$str3$str5$str4$var1');
}

Assignment-02
void main() {
var are = (List<int> num) {
int sum = 0;
for (int i = 0; i < num.length; i++) {
if (num[i] % 2 == 0) {
sum += num[i];
}
}
return sum;
};
List<int> numbers = [1, 2, 3, 4, 5, 6, 7, 8, 90, 2];
var result = are(numbers);
print(result);
}

Assignment-03
class Book {
String? name;
String? author;
int? price;

void display() {
print('Name: $name');
print('Author: $author');
print('Price: $price');
}
}

void main() {
Book B1 = Book();
B1.name = 'My Feelings';
B1.author = 'Kavana Nagraj';
B1.price = 150;
B1.display();
}

Assignment-04
class Vehicle{
String? make;
int? model;
void displayinfo(){
print('Make: $make');
print('Model: $model');
}
}
class Car extends Vehicle{
int? number_of_doors;
}
class Motorcycle extends Vehicle{
String? type_of_engine;
}
void main(){
var obj1=new Car();
obj1.make='Normal';
obj1.model=20234;
obj1.number_of_doors=5;
obj1.displayinfo();
var obj2=new Motorcycle();
obj2.make='Normal';
obj2.model=20234;
obj2.type_of_engine='A';
obj2.displayinfo();
}

Assignment-05
class Shape {
void draw() {
print('Drawing a Shape');
}
}

class Circle extends Shape {


void draw() {
print('Drawing a Circle');
}
}

class Rectangle extends Shape {


void draw() {
print('Drawing a Rectangle');
}
}

void main() {
List Shapes = ['obj1', 'obj2'];
Shapes[0] = new Circle();
Shapes[1] = new Rectangle();
for (int i = 0; i < Shapes.length; i++) {
print(Shapes[i]);
Shapes[i].draw();
}
}

Assignment-06
import 'dart:math';
class PasswordGenerator {
int? nod;
bool? spc;
String? sum;

PasswordGenerator(int nod, bool spc) {


this.nod = nod;
this.spc = spc;
}
void generatePassword() {
if (nod! >= 4) {
String? sum;
var random = new Random();
List<String> srt1 = ['A','B','C','D', 'E',
'F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'];
List<String> srt2 = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'];
List srt3 = ['!', '@', '#', '&'];
var str1 = srt1[random.nextInt(24)];
var str2 = srt1[random.nextInt(24)];
var str3 = srt2[random.nextInt(24)];
var str4 = srt3[random.nextInt(4)];
if (spc == true) {
sum = str1 + str2 + str3 + str4;
for (int i = 0; i < (nod! - 4); i++) {
var num = '${random.nextInt(10)}';
sum = sum! + num;
}
} else {
sum = str1 + str2 + str3;
for (int i = 0; i < (nod! - 3); i++) {
var num = '${random.nextInt(10)}';
sum = sum! + num;
}
}
this.sum = sum;
}
}

void displayPassword() {
generatePassword();
print('The password generated is $sum');
}
}

void main() {
//the password must contain a minimum of 4 charectors
var password = new PasswordGenerator(6, false);
password.displayPassword();
}

Assignment-07
void main() {
List<int> num1 = [1,2,3,4,5,6,7,8,9,10];
Map calculateSumAndProduct(List<int>? num) {
Map<String, int> sp = {'Sum': 0, 'Product': 1};
for (int i = 0; i < num!.length; i++) {
sp['Sum'] = num[i] + sp['Sum']!;
}
for (int i = 0; i < num!.length; i++) {
sp['Product'] = num[i] * sp['Product']!;
}
return sp;
}

print(calculateSumAndProduct(num1));
}

Assignment-08
class TodoList {
List? todo;
TodoList(List<String> todo) {
this.todo = todo;
}
void addTodo(String newTodo) {
todo!.add(newTodo);
}

void markCpt(String exitTodo) {


for (int i = 0; i < todo!.length; i++) {
if (exitTodo == todo![i]) {
todo![i] = todo![i] + '--Completed';
break;
}
}
}

void displaylist() {
print(todo);
}
}

class TodoItem {
String? title;
String? description;
String? status;
void displayitem() {
print('Title: $title');
print('description: $description');
print('Status: $status');
}
}

void main() {
List<String> todo = [
'Have Breakfast',
'Drink Water',
'Wash Clothes',
'H C Verma'
];
var obj = new TodoList(todo);
obj.addTodo('Swim');
obj.markCpt('Drink Water');
obj.displaylist();

var obj1 = new TodoItem();


obj1.title = 'H C Verma';
obj1.description =
'Read Chapter 1, revise Mechanical physics, make notes of Quantum physics';
obj1.status = 'Not Completed';
obj1.displayitem();
}

You might also like