Question

In: Computer Science

Write a pseudocode for the following code: /*every item has a name and a cost */...

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;
   }   

Solutions

Expert Solution

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,


Related Solutions

write pseudocode for the following problems not c code Pseudocode only Write a C program to...
write pseudocode for the following problems not c code Pseudocode only Write a C program to print all natural numbers from 1 to n. - using while loop Write a C program to print all natural numbers in reverse (from n to 1). - using while loop Write a C program to print all alphabets from a to z. - using while loop Write a C program to print all even numbers between 1 to 100. - using while loop...
write the pseudocode and code to solve the following: you are given a list. determine the...
write the pseudocode and code to solve the following: you are given a list. determine the sum of all the elements in the list without using the built in puthon function sum(). Take your code and create your own function and name it my_sum_algo() which will return the sum of numbers PS please write comments in the code for my understanding, and please write jn jn PYTHON 3 languge. Thank you, have a great day !
write the code based on this pseudocode //Create Class any name (ex: aQ) //Declaring private integer...
write the code based on this pseudocode //Create Class any name (ex: aQ) //Declaring private integer array empty one ex: name arrQ[] //Declare private integers front, rear, size and len (example, but you call any other names) //Write constructors Called public and same name of the class (parameters integer n) Inside Declare where: size is equal to n len is equal to zero arrQ is equal to new integer[size] front is equal minus 1 rear is equal minus 1 //Declare...
write JAVA code with the following condition Write the pseudocode for a new data type MyStack...
write JAVA code with the following condition Write the pseudocode for a new data type MyStack that implements a stack using the fact that you have access to a queue data structure with operations enqueue(), dequeue(), isEmpty(). Remember that every stack should have the operations push() and pop(). Hint: use two queues, one of which is the main one and one is temporary. Please note that you won’t be able to implement both push() and pop() in constant time. One...
Using pseudocode or C++ code, write code to print “small” if the magnitude M of an...
Using pseudocode or C++ code, write code to print “small” if the magnitude M of an earthquake is in the range [0, 3), “medium” if M is in the range [3, 6), “large” if M is in the range [6, 9) and “epic” if M is greater than or equal to 9, where M is input by a user via the keyboard. (in c++)
write code with proper comments for ever step the code should be in form of pseudocode                            &
write code with proper comments for ever step the code should be in form of pseudocode                                    To Print Triangle of any size, by taking size as input. To Print Triangle of any size, by taking size as input. If size is 4 then triangle is: To calculate Factorial of any number. To calculate the power of any given number. To Print Table of Any Number up till 10: as shown in this figure. for a program which reads 10 integers...
Write the pseudocode that prompts the user for their first and last name. Display the first...
Write the pseudocode that prompts the user for their first and last name. Display the first initial of their first name and their last name to the user. Ask the user to input a phone number. The program checks which part of Colorado a phone number is from using the values below. If the second digit of the phone number is one of the below digits, print the phone number and which part of Colorado it is from. If none...
Design (pseudocode) and implement (source code) a program (name it DistinctValues) to display only district values...
Design (pseudocode) and implement (source code) a program (name it DistinctValues) to display only district values in an array. The program main method defines a single-dimensional array of size 10 elements and prompts the user to enter 10 integers to initialize the array. The main method then calls method getValues() that takes an integer array and returns another single-dimensional array containing only distinct values in the original (passed) array. Document your code and properly label the input prompts and the...
Using pseudocode or C++ code, write a function to compute and return the product of two...
Using pseudocode or C++ code, write a function to compute and return the product of two sums. The first is the sum of the elements of the first half of an array A. The second is the sum of the elements of the second half of A. The function receives A and N ≥ 2, the size of A, as parameters. (in c++)
Given the below pseudocode, write the proper code that implements it using MARIE's assembly language:               ...
Given the below pseudocode, write the proper code that implements it using MARIE's assembly language:                    Input a number and store it in X; if X > 1 then    Y := X + X;    X := 0; endif; Y := Y + 1; Output the value of Y; N.B: You should include the MARIE code in your Answer, with an explanation of each instruction in your code beside it. Example:              Subt One         /Subtract 1 from AC Add a...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT