Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Lab Assignment 1 0 2 0 2 3 2 0 2 4 Fall, CMPE 1 1 3 Fundamentals of Programming I Question 1 Write a

Lab Assignment 10
20232024 Fall, CMPE 113 Fundamentals of Programming I
Question 1
Write a class called Product with the following variables and methods.
Variables (5 points)
(All variables should be declared as private.)
name ->String
price -> double
quantity -> int
Methods (20 points)
get and set methods for all variables.
setProductInformation method gets name and quantity as parameter and sets related
variables.
printInfo method prints the product information as given in the sample output.
Question 2
Write a class called Storage which has a main method. First create an array of products with an
initial size of 0.( Product[] products = new Product[0]; )
Your program should perform four different operations and it should ask for an operation until user
enters 5.
1-Add product (20 points)
Ask for product name and quantity.
Create a new Product object and set related information by using setProductInformation
method.
Increase the size of products array and add the new product to the array.
Lets remember how to increase size of an array:
o create a new temporary array of size+1
o copy all items of the original array to temporary array and add the new item to the
last slot of temporary array
o assign temporary array to the original array
2-Enter price (15 points)
Ask for name of the product. (You may assume that an existing product name will be
entered.)
Computer Engineering Department
2
Ask for price of the product.
Find the related product in products array by using a loop, and set price of the student by
using setPrice method.
3-Print products (10 points)
Print information of all products by using printInfo method in a loop.
4-Calculate total cost (30 points)
First, check whether all products have prices.
o If there is at least one product without price, print an error message and list product
names which do not have price values. (see sample output)
o Otherwise, calculate cost of each product by multiplying quantity with price.
o You can calculate total cost by summing the costs.
5-Exit
Print Bye! and terminate the program.
Analyze sample output given below and write your codes accordingly.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

How does the concept of hegemony relate to culture?

Answered: 1 week ago