Question

In: Computer Science

Please implement Sample string toString()method for each class and return itself a string, not the output....

 Please implement Sample string toString()method for each class and return itself a string, not the output. 
import java.util.ArrayList;

public class Customer extends User{
    private ArrayList orders;

    public Customer(String display_name, String password, String email) {
        super(display_name, password, email);
    }

    @Override
    public String getPermissionLevel() {
        return "CUSTOMER";
    }

    public void addOrder(Order order){
        this.orders.add(order);
    }

    public ArrayList listOrders(){
        return this.orders;
    };
}

----------------

public class ElectronicProduct extends Product{
    private long SNo;
    private String warranty_period;

    public ElectronicProduct(long SNo, String warranty_period, String productId, String productName, String brandName, String Description) {
        super(productId, productName, brandName, Description);
        this.SNo = SNo;
        this.warranty_period = warranty_period;
    }

}

--------------

public class HomeProduct extends Product{

    String location;
    public HomeProduct(String location, String productId, String productName, String brandName, String Description) {
        super(productId, productName, brandName, Description);
        this.location = location;
    }
}

----------------------

import java.util.ArrayList;
import java.util.Date;
public class Order {
    private int order_no;
    private ArrayList products;
    private String order_Status;
    private Date final_date;

    public Order(int order_no, String order_Status, Date final_date) {
        this.order_no = order_no;
        this.order_Status = order_Status;
        this.final_date = final_date;
        this.products = new ArrayList<>();
    }

    public Date getFinal_date() {
        return final_date;
    }

    public String getOrder_Status() {
        return order_Status;
    }

    public int getOrder_no() {
        return order_no;
    }

    public void setFinal_date(Date final_date) {
        this.final_date = final_date;
    }

    public void setOrder_Status(String order_Status) {
        this.order_Status = order_Status;
    }

    public void setOrder_no(int order_no) {
        this.order_no = order_no;
    }

    public ArrayList getProducts(){
        return this.products;
    }

    public void addProduct(Product product){
        this.products.add(product);
    }

}

------------------------------------------------

import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Date;

public class Product {

    private String productId;
    private String productName;
    private String brandName;
    private String description;
    private ArrayList categories;
    private LocalDate dateCatalog;

    public Product(String productId, String productName, String brandName, String description) {
        this.productId = productId;
        this.productName = productName;
        this.brandName = brandName;
        this.description = description;
        this.dateCatalog = LocalDate.now();
        this.categories = new ArrayList<>();
    }

    public String getProductId() {
        return productId;
    }

    public String getDescription() {
        return description;
    }

    public String getProductName() {
        return productName;
    }

    public void addCategory(Category category){
        this.categories.add(category);
    }

    public ArrayList listCategories(){
        return this.categories;
    }
}

--------

 

-----------------------------------------

 

Solutions

Expert Solution

I have added toString method for each class.

Full Java Code :

import java.util.ArrayList;

public class Customer extends User{

    private ArrayList orders;

    public Customer(String display_name, String password, String email) {

        super(display_name, password, email);

    }

//sample toString method for Customer class

public String toString()

    {

        return "this is toString method of Customer class & " +display_name + " " + password + " " + email;

    }  

    @Override

    public String getPermissionLevel() {

        return "CUSTOMER";

    }

    public void addOrder(Order order){

        this.orders.add(order);

    }

    public ArrayList listOrders(){

        return this.orders;

    };

}




public class ElectronicProduct extends Product{

    private long SNo;

    private String warranty_period;

    public ElectronicProduct(long SNo, String warranty_period, String productId, String productName, String brandName, String Description) {

        super(productId, productName, brandName, Description);

        this.SNo = SNo;

        this.warranty_period = warranty_period;

    }





//tostring method for ElectronicProduct Class

public String toString()

    {

        return productId + " " + productName + " "+ brandName + " " + description + " " +SNo + " " +warranty_period;

    }

}

--------------

public class HomeProduct extends Product{

    String location;

    public HomeProduct(String location, String productId, String productName, String brandName, String Description) {

        super(productId, productName, brandName, Description);

        this.location = location;

    }

//tostring method for HomeProduct Class

public String toString()

    {

        return productId + " " + productName + " "+ brandName + " " + description + " " +location;

    }


}

----------------------

import java.util.ArrayList;

import java.util.Date;

public class Order {

    private int order_no;

    private ArrayList products;

    private String order_Status;

    private Date final_date;

    public Order(int order_no, String order_Status, Date final_date) {

        this.order_no = order_no;

        this.order_Status = order_Status;

        this.final_date = final_date;

        this.products = new ArrayList<>();

    }

//sample toString method for Oder class

public String toString()

    {

        return order_no + " " + products + " " + order_Status + " " + final_date ;

    }

    public Date getFinal_date() {

        return final_date;

    }

    public String getOrder_Status() {

        return order_Status;

    }

    public int getOrder_no() {

        return order_no;

    }

    public void setFinal_date(Date final_date) {

        this.final_date = final_date;

    }

    public void setOrder_Status(String order_Status) {

        this.order_Status = order_Status;

    }

    public void setOrder_no(int order_no) {

        this.order_no = order_no;

    }

    public ArrayList getProducts(){

        return this.products;

    }

    public void addProduct(Product product){

        this.products.add(product);

    }

}

------------------------------------------------

import java.time.LocalDate;

import java.util.ArrayList;

import java.util.Date;

public class Product {

    private String productId;

    private String productName;

    private String brandName;

    private String description;

    private ArrayList categories;

    private LocalDate dateCatalog;

    public Product(String productId, String productName, String brandName, String description) {

        this.productId = productId;

        this.productName = productName;

        this.brandName = brandName;

        this.description = description;

        this.dateCatalog = LocalDate.now();

        this.categories = new ArrayList<>();

    }

//tostring method for Product Class

public String toString()

    {

        return productId + " " + productName + " "+ brandName + " " + description + " " + dateCatalog + " " +categories;

    }


    public String getProductId() {

        return productId;

    }

    public String getDescription() {

        return description;

    }

    public String getProductName() {

        return productName;

    }

    public void addCategory(Category category){

        this.categories.add(category);

    }

    public ArrayList listCategories(){

        return this.categories;

    }

}

--------


Related Solutions

Suppose that Account class has a method called toString, which will be inherited by Checking and...
Suppose that Account class has a method called toString, which will be inherited by Checking and Savings class. The toString method will perform according to account type. It will return a string that describes the account information. So, the late bind is needed. Declare the toString method in Account class. The method should take no argument and return a string that describes the account information. IT IS C++
Suppose that Account class has a method called toString, which will be inherited by Checking and...
Suppose that Account class has a method called toString, which will be inherited by Checking and Savings class. The toString method will perform according to account type. It will return a string that describes the account information. So, the late bind is needed. Declare the toString method in Account class. The method should take no argument and return a string that describes the account information. c++
import java.util.Scanner; public class LetterGrade { // The method you write will return a String representing...
import java.util.Scanner; public class LetterGrade { // The method you write will return a String representing a letter // grade (e.g., "A", "A-", "B+", etc.). // The letter grade is determined by the given percentage, according // to the scale specified on page 2 of the class syllabus (available // here: https://kyledewey.github.io/comp110-spring18/syllabus.pdf). // You may assume that the given percentage is between 0.0 and 100.0 // TODO - write your code below this comment.    public static String letterGrade(double percentage){...
Please write a main method that creates 2 pizzas and uses the toString() method to test...
Please write a main method that creates 2 pizzas and uses the toString() method to test this program. public class PizzaOrder { private Pizza[] order; private int numPizzas; public PizzaOrder() { order = new Pizza[1]; order[0] = new Pizza("Cheese", 0); numPizzas = 1; } public PizzaOrder(int count) { order = new Pizza[count]; this.numPizzas = 0; } public void addPizza(Pizza pizza) { for (int i = 0; i < order.length; i++) { if (order[i] == null) { order[i] = pizza; System.out.println("Pizza...
java please        * implement zip method in Q1 class to merge two linkedlists into...
java please        * implement zip method in Q1 class to merge two linkedlists into one.        * The elements in the result are made by concatenating elements in different        * linkedlists one after one. The order of the elements matters.        * For example, merge(list1, list2) should return [1,5,2,4,3,3,4,2,5,1].        * You can assume that arr1 and arr2 has the same size.        * HINT: You should use ListIterator to make it...
Which of this method of class String is used to obtain a length of String object?...
Which of this method of class String is used to obtain a length of String object? What is the output of the below Java program with WHILE, BREAK and CONTINUE? int cnt=0; while(true) { if(cnt > 4)    break;    if(cnt==0) {     cnt++; continue; }   System.out.print(cnt + ",");   cnt++; } 1,2,3,4 Compiler error 0,1,2,3,4, 1,2,3,4,
Programming Exercise Implement the following class design: class Tune { private:    string title; public:   ...
Programming Exercise Implement the following class design: class Tune { private:    string title; public:    Tune();    Tune( const string &n );      const string & get_title() const; }; class Music_collection { private: int number; // the number of tunes actually in the collection int max; // the number of tunes the collection will ever be able to hold Tune *collection; // a dynamic array of Tunes: "Music_collection has-many Tunes" public: // default value of max is a conservative...
Write a RECURSIVE method that receives a string as a parameter. The method will return true...
Write a RECURSIVE method that receives a string as a parameter. The method will return true if the string received as a parameter is a palindrome and false if it is not. The method must not have any loops! In JAVA
Design and implement a method that will take any value as String (even it's a number!)...
Design and implement a method that will take any value as String (even it's a number!) and convert that value to a number in any base. Use the method; private static ArrayList convertToBase(String value, int currentBase, int targetBase){ // your algorithm return result; //which is a String array } Examples: convertToBase("10011", 2, 10) should return [1, 9], meaning, (10011)base2 = (19)base10 convertToBase("100", 10, 8) should return [6, 4] convertToBase("E12B0", 16, 2) should return [1,1,1,0,0,0,0,1,0,0,1,0,1,0,1,1,0,0,0,0] convertToBase("1250", 10, 16) should return [4,...
Using STL stack class, implement in C++ the following pseudocodefunctioncheckBraces(aString: string) that checks for...
Using STL stack class, implement in C++ the following pseudocode functioncheckBraces(aString: string) that checks for balanced braces { } in a given string /arithmetic expressions. Write a main() program to test the function.// Checks the string aString to verify that braces match.// Returns true if aString contains matching braces, false otherwise.checkBraces(aString: string): boolean{aStack = a new empty stackbalancedSoFar = truei =0// Tracks character position in stringwhile (balancedSoFar and i < length of aString) {ch = character at position i in...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT