Question

In: Computer Science

Java Part 2 of 4 - Amusement Park Programming Project MUST BE COMPATIBLE WITH PART 1...

Java

Part 2 of 4 - Amusement Park Programming Project

MUST BE COMPATIBLE WITH PART 1

https://www.chegg.com/homework-help/questions-and-answers/java-part-1-4-amusement-park-programming-project-requirements-use-java-selection-construct-q40170145?trackid=ERIFssNL

Requirements:

  1. Use the Java selection constructs (if and if else).
  2. Use the Java iteration constructs (while, do, for).
  3. Use Boolean variables and expressions to control iterations.
  4. Proper error handling.

Class:

Merchandise – models merchandise available in the gift shop such as t-shirts, sweatshirts, and stuffed animals.

Instance Fields:

  1. id : long – to identify the specific merchandise item.
  2. category : String – to store the specific type of merchandise.
  3. description : String – to store the description of the merchandise.
  4. price : double – to store the price of the merchandise.
  5. inStock : boolean – to indicate if the merchandise is instock or on-order.

Constructors and Methods:

  1. Merchandise(String, String, String, double, boolean) – parameterized constructor that initializes the attributes of a merchandise item.
  2. setPrice(double) – to change the price of the merchandise.
  3. getInstock() : boolean – to change the status of the merchandise item.
  4. getId() : String – Accessor method for instance field.
  5. getCategory() : String – Accessor method for instance field.
  6. getDescription() : String – Accessor method for instance field.
  7. getPrice() : double – Accessor method for instance field.
  8. toString() : String – to return a neatly formatted string that contains all the information stored in the instance fields.

Solutions

Expert Solution

If you have any problem with the code feel free to comment.

Program

class Merchandise {
   //instance variables of the class
   private long id;
   private String category, description;
   private double price;
   private boolean inStock;
  
   //parameterzied constructor
   public Merchandise(long id, String category, String description, double price, boolean inStock) {
       this.id = id;
       this.category = category;
       this.description = description;
       this.inStock = inStock;
       //error checking
       //price cannot be a negetive number
       if(price <0) {
           System.err.println("Price cannot be a negetive, default set it to zero");
           this.price = 0;
       }
       else
           this.price = price;
   }
   //setting price
   public void setPrice(double price) {
       if(price <0) {
           System.err.println("Price cannot be a negetive, default set it to zero");
           this.price = 0;
       }
       else
           this.price = price;
   }
  
   //all the getters
   public long getId() {
       return id;
   }

   public String getCategory() {
       return category;
   }

   public String getDescription() {
       return description;
   }

   public double getPrice() {
       return price;
   }

   public boolean isInStock() {
       return inStock;
   }
  
   @Override//detailed description of the object
   public String toString() {
       String str1, str2, str3, str4, str5;
       str1 = "\nID: "+id+"\n";
       str2 = "Category: "+category+"\n";
       str3 = "Description: "+description+"\n";
       str4 = "Price: $"+price+"\n";
       str5 = "Is in Stock? "+inStock+"\n";
       return str1+str2+str3+str4+str5;
   }
  
}

public class Test {//driver class for testing
   public static void main(String[] args) {
       Merchandise obj = new Merchandise(12145741, "Toys", "Its the Hotwheels Batmobile", 50.23, true);
       System.out.println(obj);
   }
}

Output


Related Solutions

Java. Part 1 of 4 - Amusement Park Programming Project Requirements: Use the Java selection constructs...
Java. Part 1 of 4 - Amusement Park Programming Project Requirements: Use the Java selection constructs (if and if else). Use the Java iteration constructs (while, do, for). Use Boolean variables and expressions to control iterations. Proper error handling. Class: Ticket – models admission tickets. Instance Fields: number : long – identify the unique ticket. category : String – store the category of the ticket. holder : String – store the name of the person who purchased the ticket. date...
There is a new amusement park under construction in town and the manager of the project...
There is a new amusement park under construction in town and the manager of the project has hired you to design a "Zero-Gravity" room. (a) Based on your knowledge of nature of electric charge and electric forces, how will you design such a facility? Comment on components of the room, and explain how it will work for walk in customers? What would be the safety concerns and measures? (b) Assume that your design has been approved and facility has been...
Consider a project to build an amusement park. What are some of theresource constraints that...
Consider a project to build an amusement park. What are some of the resource constraints that would make this project challenging? What could you do, as a project manager, to help manage the constraints and project scheduling?
A new roller coaster at an amusement park requires individuals to be at least​ 4' 8"...
A new roller coaster at an amusement park requires individuals to be at least​ 4' 8" ​(56 inches) tall to ride. It is estimated that the heights of​ 10-year-old boys are normally distributed with mu equals μ=55.0 inches and sigma equals σ=4 inches. a. What proportion of​ 10-year-old boys is tall enough to ride the​ coaster? b. A smaller coaster has a height requirement of 50 inches to ride. What proportion of​ 10-year-old boys is tall enough to ride this​...
JAVA programming - please answer all prompts as apart of 1 java assignment. Part A Create...
JAVA programming - please answer all prompts as apart of 1 java assignment. Part A Create a java class InventoryItem which has a String description a double price an int howMany Provide a copy constructor in addition to other constructors. The copy constructor should copy description and price but not howMany, which defaults to 1 instead. In all inheriting classes, also provide copy constructors which chain to this one. Write a clone method that uses the copy constructor to create...
Write any java programming to meet the following requirements. Your project must meet the following requirements:...
Write any java programming to meet the following requirements. Your project must meet the following requirements: 1. Specify input specification      Design input 2. Specify Output Specification     Design Output 3. The class must include set methods and get methods ( with or without parameters both) 4. Must include Array structure 5. Must include Input or Output Files or both 6. Demonstrate your knowledge of an Applet
Comprehensive Problem 4 Part 2: Note: You must complete part 1 before part 2. After all...
Comprehensive Problem 4 Part 2: Note: You must complete part 1 before part 2. After all of the transactions for the year ended December 31, Year 1, had been posted [including the transactions recorded in part (1) and all adjusting entries], the data that follows were taken from the records of Equinox Products Inc. Income statement data: Advertising expense $150,000 Cost of merchandise sold 3,700,000 Delivery expense 30,000 Depreciation expense—office buildings and equipment 30,000 Depreciation expense—store buildings and equipment 100,000...
Comprehensive Problem 4 Part 2: Note: You must complete part 1 before part 2. After all...
Comprehensive Problem 4 Part 2: Note: You must complete part 1 before part 2. After all of the transactions for the year ended December 31, 2016, had been posted [including the transactions recorded in part (1) and all adjusting entries], the data that follows were taken from the records of Equinox Products Inc. Income statement data: Advertising expense $150,000 Cost of merchandise sold 3,700,000 Delivery expense 30,000 Depreciation expense—office buildings and equipment 30,000 Depreciation expense—store buildings and equipment 100,000 Dividend...
Part A) Java Programming Exercise #2: Write a method, remove, that takes three parameters: an array...
Part A) Java Programming Exercise #2: Write a method, remove, that takes three parameters: an array of integers, the length of the array, and an integer, say, removeItem. The method should find and delete the first occurrence of removeItem in the array. If the value does not exist or the array is empty, output an appropriate message. (Note that after deleting the element, the array size is reduced by 1.) Here you assume the array is not sorted. Do not...
Java Programming Part 1 (20%) Implement a class with a main method. Using an enhanced for...
Java Programming Part 1 (20%) Implement a class with a main method. Using an enhanced for loop, display each element of this array: String[] names = {"alice", "bob", "carla", "dennis", "earl", "felicia"}; Part 2 (30%) In a new class, implement two methods that will each calculate and return the average of an array of numeric values passed into it. Constraints: your two methods must have the same name one method should accept an array of ints; the other should accept...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT