Question

Problem: Complete Programming Project 1 (pg. 339, Savitch). The defined class will be HotDogStand.java and will also contain:

JAVA 1336

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Method implementation was not there in the question so I defined my own you can replace it with your implementation

HotDogStand .java

public class HotDogStand {
   // defining some private variables to generate getter and setters
   private int orderId;
   private String item;

   // default constructor
   public HotDogStand() {
       System.out.println("Defautl Constructor");
   }

   // constructor overloading
   public HotDogStand(int orderId, String item) {
       System.out.println("Overloaded constructor:");
       this.orderId = orderId;
       this.item = item;
   }

   // copy construtor
   public HotDogStand(HotDogStand obj) {
       System.out.println("copy constructor Invoked");
       System.out.println(obj.orderId + "\t" + obj.item);
   }

   // to string method
   public String toString() {
       System.out.println("to string method invoked");
       return "orderId: " + orderId + " Item: " + item;

   }

   // equals method
   public void equals() {
       System.out.println("Equals method invoked");

   }

   // finalize method
   @Override
   protected void finalize() {
       System.out.println("finalize method called");
   }

   // getter and setters for private variables
   public int getOrderId() {
       return orderId;
   }

   public void setOrderId(int orderId) {
       this.orderId = orderId;
   }

   public String getItem() {
       return item;
   }

   public void setItem(String item) {
       this.item = item;
   }

}

HotDogStandTest .java

public class HotDogStandTest {

   public static void main(String[] args) {
       HotDogStand obj = new HotDogStand();// This will call default
                                           // constructor
       System.out.println("---------------------------------");
       HotDogStand obj1 = new HotDogStand(1, "Pizza");// THis will call
                                                       // overloaded
                                                       // constructor
       System.out.println("---------------------------------");
       HotDogStand obj2 = new HotDogStand(obj1);// This will call copy
                                                   // constructor
       System.out.println("---------------------------------");
       obj.equals();// calling equals method
       System.out.println("---------------------------------");
       System.out.println(obj1.toString());// calling to string method
       System.out.println("---------------------------------");
       System.out.println("calling getters and setters");
       System.out.println(obj1.getItem() + "\t" + obj1.getOrderId());
       System.out.println("---------------------------------");
       obj.finalize();

   }

}

Add a comment
Know the answer?
Add Answer to:
JAVA 1336 Problem: Complete Programming Project 1 (pg. 339, Savitch). The defined class will be HotDogStand.java...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • In this assignment, you will implement Address and Residence classes. Create a new java project. Part...

    In this assignment, you will implement Address and Residence classes. Create a new java project. Part A Implementation details of Address class: Add and implement a class named Address according to specifications in the UML class diagram. Data fields: street, city, province and zipCode. Constructors: A no-arg constructor that creates a default Address. A constructor that creates an address with the specified street, city, state, and zipCode Getters and setters for all the class fields. toString() to print out all...

  • Hello. I need help writing the following Java Program. Thank you Develop a class encapsulating the...

    Hello. I need help writing the following Java Program. Thank you Develop a class encapsulating the concept of a college course, assuming that a course has following attributers: code (for instance COSC1337), a description, and a number of credits (for instance 3). Include a constructor, the accessors, mutators and methods ‘toString’, ‘equals’, and ‘finalize’. Write a client class to test the behavior of the class and its methods. The outline of the class is given as follows: public class Course...

  • [CODE] Write a class encapsulating the concept of a house, assuming a house has the following...

    [CODE] Write a class encapsulating the concept of a house, assuming a house has the following attributes: value (in dollars), a city location, and number of bedrooms. Your class name should be “House” and your code should be in a file called “House.java”. You will need to create this file. In this class, include: Private instance variables for the previously-mentioned attributes A default constructor An overloaded constructor Accessor and mutator methods (i.e., get and set methods) The toString method The...

  • no buffered reader. no try catch statements. java code please. And using this super class: Medialtemjava...

    no buffered reader. no try catch statements. java code please. And using this super class: Medialtemjava a Create the "middle" of the diagram, the DVD and ForeignDVD classes as below: The DVD class will have the following attributes and behaviors: Attributes (in addition to those inherited from Medialtem): • director:String • rating: String • runtime: int (this will represent the number of minutes) Behaviors (methods) • constructors (at least 3): the default, the "overloaded" as we know it, passing in...

  • Create a NetBeans project called "Question 1". Then create a public class inside question1 package called Author according to the following information (Make sure to check the UML diagram)

    Create a NetBeans project called "Question 1". Then create a public class inside question1 package called Author according to the following information (Make sure to check the UML diagram) Author -name:String -email:String -gender:char +Author(name:String, email:String, gender:char) +getName():String +getEmail):String +setEmail (email:String):void +getGender():char +tostring ):String . Three private instance variables: name (String), email (String), and gender (char of either 'm' or 'f'): One constructor to initialize the name, email and gender with the given values . Getters and setters: get Name (), getEmail() and getGender (). There are no setters for name and...

  • 1) (10 points) Create a new Java project, name it "Quiz02". Create a java class Traveler...

    1) (10 points) Create a new Java project, name it "Quiz02". Create a java class Traveler that has four data members, String name, Date bDate, int id and int noOfDependens. Generate the following: 1- Getters and Setters. 2- Four parametrize constructor to initialize the four data members above. 3- toString() method. Create a java class Flight that has four data members, String number, String destination, int capacity, and ArrayList<Traveler> travelers. • Notel - travelers will be used to track the...

  • (JAVA) 1) Write a blueprint class that tracks the orders made to vendors in a company's...

    (JAVA) 1) Write a blueprint class that tracks the orders made to vendors in a company's product purchasing system. We will create a class called ProductOrder. The requirements are as follows: a) The class ProductOrder has the following private instance variables:productID orderld, quantityRequested quantity Fulfilled all of types integer. We will need separate variables for quantity requested and quantity fulfilled because the vendors may not be able to fulfill the requests completely b) The class/object model will provide the values...

  • // Client application class and service class Create a NetBeans project named StudentClient following the instructions...

    // Client application class and service class Create a NetBeans project named StudentClient following the instructions provided in the Starting a NetBeans Project instructions in the Programming Exercises/Projects Menu on Blackboard. Add a class named Student to the StudentClient project following the instructions provided in the Starting a NetBeans Project instructions in the Programming Exercises/Projects Menu on Blackboard. After you have created your NetBeans Project your application class StudentC lient should contain the following executable code: package studentclient; public class...

  • PART 1: GETTING STARTED 1. Create a new Java Project. 2. Create a new Tree class...

    PART 1: GETTING STARTED 1. Create a new Java Project. 2. Create a new Tree class and enter this code. You do not have to type in the comments public class Tree { private String name; private int age; private bogJsAn evergreen; // true if evergreen // false if deciduous //CONSTRUCTORS public Tree( { name 0; evergreen = true; age } // you fill this one public Tree (String n, jnt a, bgalean e) //PUT YOUR CODE HERE } //...

  • USING BLUEJ: You will write from scratch a class called Heater that represents an adjustable thermostat....

    USING BLUEJ: You will write from scratch a class called Heater that represents an adjustable thermostat. Follow the detailed steps below. This is based on Exercises 2.93 - 2.94 (6e) / 2.92 - 2.93 (5e) in the book, but with slight modifications, so be sure to follow the instructions below. Create a new BlueJ project named LastName-heater using your last name. Create a class named Heater At the top of the source code for Heater, add documentation like this: /**...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT