In: Computer Science
Write a pseudocode for the following code:
/*every item has a name and a cost */
public class Item {
private String name;
private double cost;
public Item(String name, double cost) {
this.name = name;
this.cost = cost;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public double getCost() {
return cost;
}
public void setCost(double cost) {
this.cost = cost;
}
}
public enum PaymentType {
CASH,
DEBIT_CARD,
CREDIT_CARD,
CHECK
}
/*every payment has a type and an amount*/
public class Payment {
private double amount;
private PaymentType paymentType;
public Payment(double amount, PaymentType paymentType)
{
this.amount = amount;
this.paymentType =
paymentType;
}
public double getAmount() {
return amount;
}
public void setAmount(double amount) {
this.amount = amount;
}
public PaymentType getPaymentType() {
return paymentType;
}
public void setPaymentType(PaymentType paymentType)
{
this.paymentType =
paymentType;
}
pseudocode for the following code:
( A) For Class "Item"
1. Here, *every item has a name and a cost
2. We have set variables like "name" and "cost" as private so that they are not accessible from outside this class, and can be only accessible through build getters.
3. Then , we have made the constructor of class "item" that takes two parameters and set the values of "name" and "cost".
4. Then we have made getters and setters for the varibales "name" . That means , we have made a function " getName() " which returns the name and a function "setName(String name)" which takes a name as input and set the name to current object.
5. We have also created getters and setters for variable "cost" , Means, we have made a function " getCost() " which returns the cost value and a function "setCost(double cost)" which takes cost as input and set the cost to current object.
( B ) enum PaymentType
enum
is a special "class" that represents a group
of constants .
Here, it will declare a group of constants as CASH, DEBIT_CARD, CREDIT_CARD, CHECK.
( C ) For class Payment
1. every payment has a type and an amount.
2. We have set "amount" and "payementType" as private so that they are not accessible from outside this class, and can be only accessible through build getters.
3. Then , we have made the constructor of class "Payment" that takes two parameters and set the values of "amount" and "paymentType".
4. Then we have made getters and setters for the varibales "amount" . That means , we have made a function " getAmount() " which returns the amount and a function "setAmount(double amount)" which takes a amount as input and set the amount to current object.
5. Then we make, getters and setters as "getPaymentType()" of type PaymentType, which returns the type of the payment. And function "setPaymentType(PaymentType paymentType" which takes "paymentType" as an input and set this to paymentType of current object,