CST8116-Exercise 3( yuvraj singh )

docx

School

Algonquin College *

*We aren’t endorsed by this school

Course

8116

Subject

Computer Science

Date

Feb 20, 2024

Type

docx

Pages

6

Uploaded by ColonelYakMaster1015

Report
CST8116 Introduction to Computer Programming Lab Exercise 03 Sample Solution (21S) Assessment: Exercise 03 Student Name: Yuvraj singh Lab Professor Name: Jinal Jadav Lab Section Number: 3 Due Date: Part 1 Understand the problem: 1) I need to create a program for a startup company that be used to compare the Price of grocery items across the different grocery Stores, and they want to track grocery items, Stores and Price of the items. 2) For this program, I would need to use Constructors, Accessors(getter) and Mutators(setter). 3) I would need to generate a report showing the grocery item, Store and Price separated by commas. 4) UML class diagram :-
LAB3 - Name: String -Store: String -Price: double + Lab3(Name: String, Store: String, Price: double) + getName( ): String + getStore( ): String + getPrice( ): double + setName( Name: String): void + setStore( Store: String): void + setPrice( Price: double): void + generateReport(): String + main(args: String[]): void
Part 2 • A) Pseudocode. class Lab3 //Declaring variables string Name; String Store; double Price; //Constructor Function lab3 (Name,Store,price): This.Name = Name This.Store = Store This.Price = Price // Accessors function getName(): return Name function getStore(): return Store function getPrice(): return Price //Mutators function setName(Name): this.Name = Name function setStore(Store): this.Store= Store function setPrice(Price): this.Price=Price // Method to generate report
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
function generateReport(): return Name +”,” + Store + “,” + “$” + Price // main function Function main(): // Testing the lab3 class Start Fooditem food1 = new Lab3("fanta", "Shoppers", 3.99) Fooditem food2 = new Lab3("cheese", "Walmart ", 3.49) print("Item Name:" + item1 getName()) print("Store Name:" + item1.getStore()) print("Price:" + item1.getPrice() + "\n") print("Item 2 Report: " + item2.generateReport()) stop Flowcharts for requested items
Flowcharts for use of methods within class FoodItem, see UML Class diagram for field names Flowchart for method main, instantiates two instances of FoodItem and tests the methods and constructors.
Instance and test Test Values Expected Output Actual Output Description instance1, gets/sets “cheese” “Walmart” 3.49 Cheese Walmart 3.49 Cheese Walmart 3.49 First instance of the class was created with no- argument constructor, then each field was set with a value and these were output by using the get methods. Instance2, overloaded constructor, createRepor t() “fanta” “Shoppers” 3.99 fanta, Shoppers, $3.99 fanta, Shoppers, $3.99 Second instance of the class was created using overloaded constructor, output shown resulted from createReport() Instance1, overloaded constructor, createRepor t() “Cheese” “Walmart” 3.49 Cheese, Walmart, $3.49 Cheese, Walmart, $3.49 First instance of the class was created with no- argument constructor, then each field was set with a value and output shown resulted from createReport()
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help