Waiting for answer This question has not been answered yet. You can hire a professional tutor to get the answer.

QUESTION

Use the Java code that appears below to answer the following questions.

need help with answering few qs based on the java code given at the end of the file.

Use the Java code that appears below to answer the following questions.

1.    List one variable declaration in the code, along with the line number where you found the declaration. Why did the programmer declare it as a variable (vs. as a constant)?

2.    List one constant declared in the code, along with the line number where you found the declaration. Why did the programmer declare it as a constant (vs. as a variable)? 

3.    What data types are referenced in the code? For each data type, provide the line number of a declaration using that data type as well as the declaration itself.

4.     Does the code reference all of the Java primitive data types? (Yes or No)  If your answer is "No," list the primitive data types available in Java that are not referenced in the code. 

5.    Identify all of the operators in the code, along with the line number where you found it and the type of each (arithmetic, logical, relational, empty, or conditional).

6.    Identify the control flow statements in the code. For each control flow statement, give the line number where you found the statement and tell whether that statement is a decision-making, looping, or branching statement.

7.    Identify the class definitions, object instantiations, and method calls in the code. Give the line number where you found each.

Example:

Class definitions

·        Patient, line 22

·        InsuranceCompany, line 49

·        Physician, line 77

Object instantiations

·        Alfred Smith, line 89

·        Southwest HMO, line 95

·        Dr. Smiley Jones, line 98

Method calls

·        scheduleFollowUp("Anne White", "02/08/19", "12:45"), line 124

·        remitBill("George Torres", 33535), line 155

·        referPatient("Bob Allen"), line 189

 Java code

1.    package Week_5;

2.    import java.util.InputMismatchException;

3.    import java.util.Scanner;

4.    public class Customer {

5.       public String firstName;

6.       public String lastName;

7.       public String FullName()

8.       {

9.       return this.firstName+" "+this.lastName;

10.    }

11. }

12. public class ItemsForSale {

13.      public String itemName;

14.      public double itemCost;

15.      public boolean taxable;

16.      public void PopulateItem(String iName, double iCost, boolean canTax)

17.      {

18.      this.itemName = iName;

19.      this.itemCost = iCost;

20.      this.taxable = canTax;

21.      }

22. }

23. class PRG215_Week_5 {

24.     public static void main(String[] args) {

25.          final int TOTAL_ITEMS = 6;

26.                 ItemsForSale[] items = new ItemsForSale[TOTAL_ITEMS];

27.         for(int i = 0; i < TOTAL_ITEMS; i++)

28.         {

29.             items[i] = new ItemsForSale();

30.         } 

31.         items[0].PopulateItem("Tennis Shoes",45.89,true);

32.         items[1].PopulateItem("Shirts", 25.55, true);

33.         items[2].PopulateItem("Coats", 89.99, true);

34.         items[3].PopulateItem("Belts", 15, true);

35.         items[4].PopulateItem("Pants", 25.99, true);

36.         items[5].PopulateItem("Donation", 10, false);

37.         double totalAmount = 0.0;

38.         double totalTax = 0.0;

39.         double taxRate = 0.081;

40.         final double DISCOUNT_RATE = 0.025;

41.         final double AMOUNT_TO_QUALIFY_FOR_DISCOUNT = 100;

42.         double discountAmount = 0;

43.         System.out.println("The following clothing items are available for purchase:");

44.         for(int i=0; i < items.length; i++)

45.         {       

46.             //Display each item in the array

47.             System.out.println("    "+(i + 1)+". "+items[i].itemName+ " for $"+items[i].itemCost+" each");

48.         }       

49.         System.out.println("");

50.         Scanner keyboard = new Scanner(System.in);

51.         Customer newCust = new Customer();

52.         System.out.print("Please enter your first name: ");

53.         newCust.firstName = keyboard.next();

54.         System.out.print("Please enter your last name: ");

55.         newCust.lastName = keyboard.next();

56.         System.out.println("");

57.         System.out.println("Ok, " + newCust.FullName()+", please enter the product ID (the number to the left of the item name) that you wish to purchase. Enter 0 when you are finished.");

58.         int itemID = 0;

59.         int itemCounter = 1;

60.         do

61.         {

62.             System.out.print("Please enter item ID number "+(itemCounter)+": ");

63.             try

64.             {

65.                 itemID = keyboard.nextInt();          

66.                 if(itemID > 0)

67.                 {

68.                     totalAmount = totalAmount + items[itemID - 1].itemCost;

69.                     if(items[itemID - 1].taxable == true)

70.                     {

71.                         totalTax = totalTax + (items[itemID - 1].itemCost * taxRate);

72.                     }

73.                     itemCounter++;

74.                 }

75.             }           

76.             catch (ArrayIndexOutOfBoundsException e1)

77.             {

78.                 System.out.println("The item ID you entered is outside the range of possible items. This must be a number between 1 and "+ TOTAL_ITEMS+". Please re-enter your item ID. ");

79.                 itemID = -1;

80.             }

81.             catch (InputMismatchException e2)  

82.             {

83.                 //Display the error message

84.                 System.out.println("The item ID you entered does not appear to be an ingeger number. The item ID must be a number between 1 and "+ TOTAL_ITEMS+". Please re-enter your item ID. ");

85.                 keyboard.nextLine();

86.                 itemID = -1;   

87.             }

88.             

89.         } while (itemID != 0); //Check if exit condition has been met

90.         if(totalAmount >= AMOUNT_TO_QUALIFY_FOR_DISCOUNT)

91.         {

92.             discountAmount = totalAmount * DISCOUNT_RATE;

93.         }

94.         else

95.         {

96.             discountAmount = 0;

97.         }

98.         System.out.println("");

99.         System.out.println("You selected "+itemCounter+" items to purchase.");

100.                       System.out.println("Your sales total $"+totalAmount);

101.                       System.out.println("Your discount amount is $"+discountAmount);

102.                       System.out.println("Your sales tax is $"+totalTax);

103.                       System.out.println("The total amount due is $"+(totalAmount - discountAmount + totalTax));

104.                       System.out.println("");

105.                   }

106.               }

Show more
LEARN MORE EFFECTIVELY AND GET BETTER GRADES!
Ask a Question