Answer to Question #238883 in Java | JSP | JSF for Princess

Question #238883
Q.1.5
If the user makes an incorrect product category selection, prompt the user to re-enter a valid product category

Q.1.6
Provide the user with the option to select between the following product warranty options:

1-Applies a six-month product warranty.

Any other key applies a two-year warranty.

Q.1.7
Once the entire submission has been completed, the user must be informed that the product details have been successfully saved.
1
Expert's answer
2021-09-18T14:33:23-0400
public class Product {

    private boolean isShortWarranty;
    private String category;

    public Product(boolean isShortWarranty,String category) {
        this.isShortWarranty = isShortWarranty;
        this.category = category;
    }
}


import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String category = "";
        while (category.length() == 0) {
            System.out.println("Chose the category:\nTV\nPhones\nGames");
            category = in.nextLine();
            switch (category) {
                case "TV":
                case "Phones":
                case "Games":
                    System.out.println("Category accepted.");
                    break;
                default:
                    category = "";
                    System.out.println("Invalid category. Try again.");
            }
        }
        System.out.println("1-Applies a six-month product warranty.\n" +
                "Any other key applies a two-year warranty: ");
        String warranty = in.nextLine();

        Product product = new Product(warranty.equals("1"), category);
        System.out.println("The product details have been successfully saved");
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS