Question

In: Computer Science

In Java An outlet store is having a sale in their Cabin brand sweaters. There are...

In Java

An outlet store is having a sale in their Cabin brand sweaters. There are two different pricing systems depending on if it is a Cabin brand or not. Tax must be added on after the sweater charge is computed.
You must have two classes using separate files.

Requirements for Sweater Class
Fields
1. sweater price (in dollars)
2. Boolean to indicate if it is a Cabin brand or not
3. number of sweaters purchased
Methods
1.   One 3 parameter constructor- the constructor uses three parameters representing the sweater price, whether it is a Cabin Brand or not, and the number of sweaters purchased.
2.   Getter and setter for each field
3.   getTotalPurchase method
This method must call the appropriate getter member methods where necessary. Do not access the fields directly.
This method calculates and returns the total amount of the sweater.
If the sweater is Cabin brand, calculate the discount as follows;
-If the customer purchases 1 sweater the discount is 20% of the sweaters price.
-if the customer purchases 2 or more sweaters the discount is 30%
-the customer cannot purchase less than 1 sweater.
-compute the purchase subtotal by subtracting the appropriate discount from the sweaters price.
Use a tax rate of 7% of the purchase subtotal to compute the sales tax in dollars. Add the sales tax amount to the purchase subtotal to determine the total purchase amount.
Return the total purchase amount to the calling code.

Requirements for the SweaterDriver Class
Main method
1.   customer must be prompted appropriately
2.   All values related to money may include values after the decimal point. All values displayed to the screen must display with 2 places after the decimal.
3.   The customer must indicate whether the sweater is Cabin brand or not by typing a single character (y for yes, n for no) program must accept Upper and lower case, Y,y,N,n.
4.   If the sweater is Cabin brand, prompt the customer to enter the number of Cabin sweaters being purchased.
5.   Instantiate a Sweater object using a three parameter constructor.
Note that the parameter that indicates if the sweater is a Cabin brand is a Boolean data type.
The customer must type a single character. You will have to use selection to instantiate a Sweater object with the correct data type foe this parameter.
6.   Display the values in the output by calling the appropriate method of the Sweater object. The output must line up at the decimal point as in the sample runs.
Sample runs
1
Enter the price of the sweater: $50.00
Is the swear a Cabin(Y/N)? N

Price of sweater $50.00
Total purchase $53.50

Run 2
Enter the price of the sweater: $60.00
Is the sweater a Cabin(Y/N)? Y
Enter the number of sweaters being purchased: 2
Price of sweater $60.00
Total Purchase $89.88

Run 3

Enter price of sweater: $40.00
Is the sweater a Cabin(Y/N)? Y
Enter the number of sweaters being purchased: 1
Price of sweater $40.00
Total purchase $34.24

Solutions

Expert Solution

Have a look at the below code. I have ran the code for the sample inputs, you can check the output also in the attached code snippet.

import java.util.*;

class Sweater{

  private double price;
  private boolean isCabin;
  private int noOfSweater;

  double totalPrice;

  public Sweater(double p, boolean flag, int n){
    this.price = p;
    this.isCabin  = flag;
    this.noOfSweater = n;
  }

  public void setPrice(int p){
    this.price = p;
  }

  public void setFlag(boolean flag){
    this.isCabin = flag;
  }

  public void setNumber(int n){
    this.noOfSweater = n;
  }

  public double getPrice(){
    return this.price;
  }

  public boolean getFlag(){
    return this.isCabin;
  }

  public int getNumber(){
    return this.noOfSweater;
  }

  public double getTotalPurchase(){

    

    if (this.isCabin){

      if (this.noOfSweater>=2){
        double discount = this.price*0.3;
        totalPrice+=this.noOfSweater*(this.price - discount);
      }
      else{
        double discount = this.price*0.2;
        totalPrice+=this.noOfSweater*(this.price - discount);
      }

      double tax = totalPrice*0.07;

      totalPrice+=tax;

    }
    else{

      totalPrice+=this.noOfSweater*this.price;

      double tax = totalPrice*0.07; 

      totalPrice+=tax;


    }

    return this.totalPrice;

  }



}


class Main {
  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);

    System.out.println("Enter the price of the sweater:");

    double price = sc.nextDouble();

    System.out.println("Is the swear a Cabin(Y/N)?:");

    char response = sc.next().charAt(0);

    boolean flag;

    int number = 1;

    if (response=='Y'){
      flag = true;
    }
    else{
      flag = false;
    }
    if (flag){

      System.out.println("Enter the number of sweaters being purchased: ");

      number = sc.nextInt();

      Sweater sw = new Sweater(price,flag,number);

      System.out.println("Price of sweater $"+sw.getPrice());

      System.out.println("Total Purchase: $" + sw.getTotalPurchase());


    }
    else{

       Sweater sw = new Sweater(price,flag,number);

       System.out.println("Price of sweater $"+sw.getPrice());

       System.out.println("Total Purchase: $" + sw.getTotalPurchase());

      
    }

    
  }
}

// Below is the output... 

//Enter the price of the sweater:60
//Is the swear a Cabin(Y/N)?:Y
//Enter the number of sweaters being purchased: 2
//Price of sweater $60.0
//Total Purchase: $89.88

Happy Learning!


Related Solutions

7. Consider a Mexican firm that knits sweaters for sale to a U.S. department store. The...
7. Consider a Mexican firm that knits sweaters for sale to a U.S. department store. The firm incurs total costs of 16 pesos/sweater and sells the sweaters to the department store for $5 per sweater. The exchange rate is 4 pesos/$. a) What is the firm’s markup per sweater as a percentage of revenues? b) If the peso is devalued 20%, what is the new value of the peso? c) If the firm keeps dollar prices constant and peso costs...
An office furniture store is having a sale on a certain type of office chair. The...
An office furniture store is having a sale on a certain type of office chair. The chairs are priced at GH¢800 per chair. The probability distribution for the number of chairs sold to an individual customer is Number of chairs 1 2 3 4 Probability 0.15 0.40 0.10 0.35 a) Find the probability that the number of chairs sold to an individual customer is odd. b) Find the expected number and standard deviation of chairs sold to an individual customer....
A retail store is having a sale. A shopper wanting two medium shirts heads for the...
A retail store is having a sale. A shopper wanting two medium shirts heads for the sales rack, which is a mess, with sizes jumbled together. Hanging on the rack are 4 medium, 11 large, and 5 extra-large shirts. Find the probability of each event described. (a) The first two shirts hehe grabs are the wrong size. (b) The first medium shirt hehe finds is the third one hehe checks. (c) The first four shirts hehe picks are all extra-large....
A discount store is having a sale where everything is 15% off. Write a program to...
A discount store is having a sale where everything is 15% off. Write a program to display a table showing the original price and the discounted price. This program requires no input and your table should include headings and the original prices should go from 99 cents to $9.99 in increments of 50 cents. Python
Ann is planning to purchase some items. The store is having a sale, where if you...
Ann is planning to purchase some items. The store is having a sale, where if you buy one item the 2nd item (of equal or lower value) is 50% off. The tax on each item is 7%.                                                                                                                     Item 1 costs $39.75 before taxes. Item 2 costs $65.50 before taxes. If Ann only buys Item 2, what is the total cost of her purchase after taxes? Display this value (rounded to the nearest cent) with a suitable message. If...
A corporation is trying to decide whether to open a new factory outlet store. The store...
A corporation is trying to decide whether to open a new factory outlet store. The store will have high, medium, or low demand. Before it decides whether to open the store, the corporation can pay $7,000 immediately for a market survey. The market survey can predict 'high,' 'medium,' or 'low' demand. If the actual demand of the store will be high, there is a 0.6 probability the survey will predict 'high' demand, a 0.06 probability the survey will predict 'medium'...
A local department store is having a BOGOHO (Buy One, Get One Half Off) sale. The...
A local department store is having a BOGOHO (Buy One, Get One Half Off) sale. The manager wants a program that allows salesclerks to enter the prices of two items. The program should calculate and display the total amount the customer owes. The half-off should always be taken on the item having the lowest price. If the items cost $24.99 and $10, the half-off would be taken off the $10 item. If both prices are equal, take the half-off on...
The Bike and Hike Outlet is a retail store. Transactions involving purchases and cash payments for...
The Bike and Hike Outlet is a retail store. Transactions involving purchases and cash payments for the firm during June 2019 are listed below, as are the general ledger accounts used to record these transactions. GENERAL LEDGER ACCOUNTS 101 Cash $ 21,900 Dr. 131 Equipment 66,000 Dr. 201 Notes Payable 205 Accounts Payable 4,980 Cr. 501 Purchases 503 Purchases Ret. and Allow. 504 Purchases Discounts 611 Rent Expense 614 Salaries Expense 617 Telephone Expense DATE TRANSACTIONS June 1 Issued Check...
Jewel, the branch manager of an outlet store of a nationwide chain of pet supply stores,...
Jewel, the branch manager of an outlet store of a nationwide chain of pet supply stores, wants to study characteristics of her customers. In particular, she decides to focus on the amount of money spent by her customers. A sample of 50 customers spent an average of $21.34 with a standard deviation of $9.25 on pet supplies. a. What is the sampling distribution of the point estimate? b. Calculate the margin of error for a 99% confidence interval estimating the...
Scenario You are a manager at a retail pharmacy outlet called One Pharmacy. Your store is...
Scenario You are a manager at a retail pharmacy outlet called One Pharmacy. Your store is in a very socially and culturally diverse suburb. Sometimes your staff members complain that the customers they serve are rude, unreasonable or difficult to understand. You realise your customer service systems may need to be reviewed and updated to best support your staff in serving the needs of your customers 1.1)   Customer service standards should ensure all customers are treated with respect, and staff members...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT