0% found this document useful (0 votes)
16 views6 pages

Mid Lab

The document outlines a programming assignment for a Mobile Application course, requiring the implementation of various classes in Dart, including Person, Student, StoreItem, and Electronics, with specific attributes and functionalities. It includes tasks such as filtering students based on CGPA, calculating total marks, and categorizing electronic items based on price and warranty period. Additionally, it discusses the design of a financial tracking application using Dart's data types and handling variable data efficiently.

Uploaded by

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

Mid Lab

The document outlines a programming assignment for a Mobile Application course, requiring the implementation of various classes in Dart, including Person, Student, StoreItem, and Electronics, with specific attributes and functionalities. It includes tasks such as filtering students based on CGPA, calculating total marks, and categorizing electronic items based on price and warranty period. Additionally, it discusses the design of a financial tracking application using Dart's data types and handling variable data efficiently.

Uploaded by

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

Name: Nouman

Reg No: FA21-BCS-233


Subject: Mobile Application.
Titile: Mid lab.
Teacher : Yasar Khan.
Date: 11/18/2024

Apply the following concept using Dart programming language. [CLO-2, C3, Marks: 10] a. A class Person
with attributes: ID, name, age. Derive a class from a person named Student. The extra attributes of
Student are CGPA, currently enrolled semester (e.g., FA22 or SP22, etc.), list of maps having Subject
name as Key and Marks as Value. Populate a list with at least 3 records of Student class. Print list of
students whose CGPA is greater than 3.7. Implement a function that calculates the total marks of a
specific student.

void main() {
// Create a list of students
List<Student> students = [
Student(1, "Alice", 21, 3.9, "FA22", {"Math": 85, "CS": 95}),
Student(2, "Bob", 22, 3.5, "SP23", {"Math": 75, "CS": 85}),
Student(3, "Charlie", 20, 3.8, "FA23", {"Math": 88, "CS": 92}),
];

// Print students with CGPA > 3.7


print("Students with CGPA > 3.7:");
for (var student in students) {
if (student.cgpa > 3.7) {
print(student.name);
}
}

// Calculate and print total marks for Charlie


print("\nTotal Marks for Charlie: $
{students[2].calculateTotalMarks()}");
}

// Student class
class Student {
int id;
String name;
int age;
double cgpa;
String semester;
Map<String, int> subjects;

Student(
this.id, this.name, this.age, this.cgpa, this.semester,
this.subjects);

int calculateTotalMarks() {
return subjects.values.reduce((sum, marks) => sum + marks);
}
}

2. Create a StoreItem class with itemID, name, and price attributes. Define a derived Electronics class
with additional warrantyPeriod and category attributes, and populate a list with at least 4 electronics
records using generative constructors. In the main() function, write a function that filters and returns
only items priced above $1000 using an anonymous function. Use spread operators to add more items
to the electronics list, including items from a list of map objects. Implement a switch statement to
categorize items by warranty period, printing "Short Warranty" for items under 12 months and "Long
Warranty" for items with 12 months or more.

class Vehicle {
int id;
String type;
String brand;

// Constructor
Vehicle(this.id, this.type, this.brand);
}

class Car extends Vehicle {


String? model;
int? year;
double? price;

// Constructor
Car(int id, String type, String brand, {this.model, this.year,
this.price})
: super(id, type, brand);
}

void main() {
// Initializing a list of Car objects using positional and optional
named parameters
List<Car> cars = [
Car(1, 'Sedan', 'Toyota', model: 'Camry', year: 2019, price: 25000),
Car(2, 'SUV', 'Honda', model: 'CR-V', year: 2021, price: 30000),
Car(3, 'Hatchback', 'Ford', model: 'Focus', year: 2017, price:
18000),
Car(4, 'Sedan', 'BMW', model: '3 Series', year: 2020, price: 35000),
Car(5, 'Truck', 'Ford', model: 'F-150', year: 2015, price: 40000),
];

print('Cars manufactured after 2018 and priced above \$20,000:');


for (var car in cars) {
if ((car.year ?? 0) > 2018 && (car.price ?? 0) > 20000) {
print(
'Brand: ${car.brand}, Model: ${car.model}, Year: ${car.year},
Price: \$${car.price}');
// Conditional expression to determine if the car is "New" or
"Used"
String status = (car.year ?? 0) >= 2020 ? 'New Car' : 'Used Car';
print('Status: $status');
}
}
}

3. A software development company is creating a financial tracking application using Dart to help small
business owners manage their expenses, income, and budget. The application needs to be efficient in
handling variable data, such as daily income, different categories of expenses, and monthly budgets. The
data can change frequently, and there may be instances where some information (like future budget
predictions) is not yet available. Question: 1) Explain how you would design the application using Dart's
data types, especially focusing on when to use final, const, late, and nullable types for handling financial
data. 2) Discuss how you would implement variables for handling different categories of expenses and
explain the scenarios in which you would use lists, sets, and maps in this application. 3) Describe how
using Dart’s ?? operator and late keyword can help manage situations where some data (like projected
income) might not be immediately available at runtime.

class StoreItem {
int itemID;
String name;
double price;

// Generative constructor for StoreItem


StoreItem(this.itemID, this.name, this.price);
}

class Electronics extends StoreItem {


int warrantyPeriod; // Warranty period in months
String category;

// Generative constructor for Electronics


Electronics(
int itemID, String name, double price, this.warrantyPeriod,
this.category)
: super(itemID, name, price);
}

void main() {
// List of Electronics items
List<Electronics> electronics = [
Electronics(101, 'Smartphone', 1200.0, 24, 'Mobile'),
Electronics(102, 'Laptop', 1500.0, 18, 'Computing'),
Electronics(103, 'Headphones', 200.0, 6, 'Audio'),
Electronics(104, 'Smartwatch', 250.0, 12, 'Wearable'),
];

// Adding more items using spread operator and a list of map objects
List<Map<String, dynamic>> moreItems = [
{
'itemID': 105,
'name': 'Tablet',
'price': 800.0,
'warrantyPeriod': 12,
'category': 'Mobile'
},
{
'itemID': 106,
'name': 'Camera',
'price': 1300.0,
'warrantyPeriod': 24,
'category': 'Photography'
},
];

// Convert maps to Electronics objects and add to the list


electronics = [
...electronics,
...moreItems.map((item) => Electronics(
item['itemID'],
item['name'],
item['price'],
item['warrantyPeriod'],
item['category'],
))
];

// Function to filter items priced above $1000 using an anonymous


function
List<Electronics> expensiveItems =
electronics.where((item) => item.price > 1000).toList();
print('Items priced above \$1000:');
for (var item in expensiveItems) {
print('${item.name}, Price: \$${item.price}');
}

// Categorize items by warranty period using a switch statement


print('\nWarranty Categorization:');
for (var item in electronics) {
switch (item.warrantyPeriod >= 12) {
case true:
print('${item.name}: Long Warranty');
break;
case false:
print('${item.name}: Short Warranty');
break;
}
}
}

You might also like