Answered step by step
Verified Expert Solution
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 Fall, CMPE Fundamentals of Programming I Question Write a class called Product with the following variables and methods. Variables points All variables should be declared as private. name String price double quantity int Methods 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 Write a class called Storage which has a main method. First create an array of products with an initial size of Product products new Product; Your program should perform four different operations and it should ask for an operation until user enters Add product 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 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 Enter price points Ask for name of the product. You may assume that an existing product name will be entered. Computer Engineering Department 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. Print products points Print information of all products by using printInfo method in a loop. Calculate total cost 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. Exit Print Bye and terminate the program. Analyze sample output given below and write your codes accordingly.
Lab Assignment
Fall, CMPE Fundamentals of Programming I
Question
Write a class called Product with the following variables and methods.
Variables points
All variables should be declared as private.
name String
price double
quantity int
Methods 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
Write a class called Storage which has a main method. First create an array of products with an
initial size of Product products new Product;
Your program should perform four different operations and it should ask for an operation until user
enters
Add product 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
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
Enter price points
Ask for name of the product. You may assume that an existing product name will be
entered.
Computer Engineering Department
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.
Print products points
Print information of all products by using printInfo method in a loop.
Calculate total cost 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.
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
Get Instant Access with AI-Powered Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started