I am struggling with this assignment. My professor is out of town until next week.
ASSIGNMENT:
The Product Class
Create a file named Product.rb that contains a Product class. The class should have the
following attributes:
ProductNumber A string used to hold a product number. Each product in the inventory
should have a unique product number.
Description A string that holds a brief description of the item.
Cost A decimal value that holds the amount the retail store paid for the item.
Retail A decimal value that holds the retail price for the item.
QuantityOnHand An integer value that holds the number of units in stock for the product.
This value cannot be less than zero.
Your Product class also needs a method to display all of the aforementioned attributes. Create
a method named display() that prints out the values in an attractive way. One approach
you could take is to display the data in two columns — the first to display the name of the
attribute, and the second to display the corresponding value.
Make sure you have a comment block at the top of the Product.rb file that describes the class
and provides a description of each attribute and method.
The Program
Create a file named Ch9Asg.rb and put it in the same folder. Put a comment block at the top
that lists the appropriate information. Since we will be creating Product objects in the
program, you need to make this file aware of the Product.rb file. To do that, place the
following line of code directly underneath the comment block:
require_relative ‘Product’
Summer 2017 CIS 116 Computer Programming I
Your program should consist of a central loop that displays a menu, gets the user’s selection,
carries out the selection, and returns back to the menu. The menu should list the following
options:
- Create a new product
- Look up a product
- Process a product purchase
- Exit
Your program needs an array to hold the Product objects the user will create with menu
option 1 in order to access those objects in menu options 2 and 3. Here’s an overview of how
each menu item should work:
Create a New Product
The user should be prompted for all values that make up a product. All appropriate values
should be validated as they are entered. Make sure the product number the user supplies
does not already exist in the list of existing products. Once all of the data are supplied and are
valid, create a new Product object, passing the data to it when created. Then, add the
Product object the array that holds them.
Look Up a Product
The user should be prompted for a product number. The program will then attempt to locate
the product in the array. If it finds a Product with a matching number, the product will be
described. Call the display() method of the appropriate Product object to do so. If a
product with the number the user entered cannot be found, inform the user and return back
to the menu.
Process a Product Purchase
Display the product number, description, retail price, and number of units on hand for all
products whose QuantityOnHand is greater than zero. The user should then be prompted for
a product number from that list. If the user enters a valid product number, the user should be
asked how many to purchase. The quantity to be purchased cannot exceed the number of
units on hand. If the quantity is valid, the application should display the subtotal, sales tax
amount (6%), and the grand total for the sale. Don’t forget to update the product’s
QuantityOnHand by subtracting the number purchased.
WHAT I HAVE SO FAR:
selection = ‘’
until selection == 4
puts “1. Create a new product”
puts “2. Look up a product”
puts “3. Process a product purchase”
puts “4. Exit”
selection = gets.chomp.to_i
if selection == 1
puts “a. Google Pixel”
puts “b. Galaxy Note 6”
puts “c. Apple IPhone 6X”
puts “d. Nokia Flip”
puts “e. Motorola Razor”
productselection = gets.chomp.to_s
if productselection == a
puts “”
end
elsif selection == 2
puts “Enter product number”
productnumber = gets.chomp.to_i
end
end
class Product
def initialize (product_number, description, cost, retail, quantity_on_hand)
@product_number = product_number
@description = description
@cost = cost
@retail = retail
@quantity_on_hand = quantity_on_hand
end
def display (name, value)
end
end
I don’t know what to do