Class Read
- java.lang.Object
-
- Read
-
public class Read extends java.lang.ObjectThe Read class is used for reading user input from the console and interacting with a Controller object. It has a Controller object and a Scanner object as instance variables, and provides methods for reading different types of user input and passing them to the Controller. All methods in this class must return something
-
-
Constructor Summary
Constructors Constructor Description Read()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanchangeActive()Prompts the user to set a new value for the "active" attribute.ClientchangeClient()Prompts the user to enter a client ID and searches for a matching client instance in the controller's list of client instances.java.lang.StringchangeName()Prompts the user to enter a new name and validates the input.charchangeNutriScore()Prompts the user to enter a new value for the "nutri score" attribute and validates the input.floatchangePrice()Prompts the user to enter a new value for the "price" attribute and validates the input.VendorchangeVendor()Prompts the user to enter a new vendor ID and searches for the corresponding vendor object.floatreadFloat()Reads a string from standard input and attempts to parse it as a float.intreadInt()Reads a string from standard input and attempts to parse it as an integer.java.lang.StringreadMenuOpt()Reads a string from standard input and returns it in uppercase.intreadProductQTY(int id)Reads the quantity of a given product ID from the user input.
-
-
-
Method Detail
-
readMenuOpt
public java.lang.String readMenuOpt()
Reads a string from standard input and returns it in uppercase. This method is commonly used to read user input for menu options.- Returns:
- the user input string in uppercase
-
readInt
public int readInt()
Reads a string from standard input and attempts to parse it as an integer. If the input is not a valid integer, an error message is printed and 0 is returned.- Returns:
- the integer parsed from the user input, or 0 if the input is not a valid integer
-
readFloat
public float readFloat()
Reads a string from standard input and attempts to parse it as a float. If the input is not a valid float, an error message is printed and 0 is returned.- Returns:
- the float parsed from the user input, or 0 if the input is not a valid float
-
changeName
public java.lang.String changeName()
Prompts the user to enter a new name and validates the input. If the name is less than 3 characters long, an error message is printed and an empty string is returned. Otherwise, the input is returned as a string and a success message is printed.- Returns:
- the new name entered by the user as a string, or an empty string if the input is invalid
-
changeActive
public boolean changeActive()
Prompts the user to set a new value for the "active" attribute. If the user enters "Y", true is returned and a success message is printed. If the user enters anything else, false is returned and a default message is printed.- Returns:
- true if the user entered "Y", false otherwise
-
changeNutriScore
public char changeNutriScore()
Prompts the user to enter a new value for the "nutri score" attribute and validates the input. If the input is not a single uppercase letter between A and Z, an error message is printed and 0 is returned. Otherwise, the input is returned as a char and a success message is printed.- Returns:
- the new nutri score entered by the user as a char, or 0 if the input is invalid
-
changePrice
public float changePrice()
Prompts the user to enter a new value for the "price" attribute and validates the input. If the input is negative, an error message is printed and 0 is returned. Otherwise, the input is returned as a float and a success message is printed.- Returns:
- the new price entered by the user as a float, or 0 if the input is invalid
-
changeVendor
public Vendor changeVendor()
Prompts the user to enter a new vendor ID and searches for the corresponding vendor object. If a vendor with the specified ID is found, it is returned and a success message is printed. If no vendor with the specified ID is found, null is returned and an error message is printed.- Returns:
- the updated vendor object with the specified ID, or null if no vendor is found
-
changeClient
public Client changeClient()
Prompts the user to enter a client ID and searches for a matching client instance in the controller's list of client instances. If a matching client instance is found, the method returns the client instance and prints "Client updated." If a matching client instance is not found, the method returns null.- Returns:
- the updated client instance if a matching client is found, or null if no matching client is found
-
readProductQTY
public int readProductQTY(int id)
Reads the quantity of a given product ID from the user input.- Parameters:
id- The ID of the product to read the quantity for.- Returns:
- The quantity of the given product ID read from user input. csharp Copy code Returns 0 if the product ID is not found.
-
-