Question

In: Computer Science

Coding Java Assignment Write the following static methods. Assume they are all in the same class....

Coding Java Assignment

  1. Write the following static methods. Assume they are all in the same class. Assume the reference variable input for the Scanner class and any class-level variables mentioned are already declared. All other variables will have to be declared as local unless they are parameter variables. Use printf.
  1. A method that prompts for the customer’s name and returns it from the keyboard.

  1. A method called shippingInvoice() that prompts for an invoice number and stores it in a class variable (field) called invoiceNo. Assume the invoice number is a combination of numbers and text.

  1. Overload the method coded in 1b above so that it accepts a customer’s name through its parameter list, concatenates the name and invoice number in a header and returns the header. This method will not prompt for the name or invoice number. The content of the header will look like this where the Xs represent the actual customer name and invoice number:

Customer Name: Xxxxxxxxxxxx

Invoice No: XXXXXXXX

  1. A method that prompts for the subtotal and returns it from the keyboar
  1. A method that prompts for the number of items purchased and returns it from the keyboard.

  1. A method that accepts the noItemsPurchased and the subtotal through its parameter list and returns an average dollar amount of the items purchased. No prompts are needed.

  1. A method that accepts what is returned by the methods coded in 1c and 1f to print the following:

Customer Name: Xxxxxxxxxxxx

Invoice No: XXXXXXXX

Average of Items Purchased: $ZZZ,ZZ9.99

2. Write statements that will call each of the methods you coded above. Be conscious of the value-returning methods. Assume the method calls are done in the main() and the main() is in the same class.

a.

b.

c.

d.

e.

f.

Solutions

Expert Solution

1).ANSWER:

GIVEN BELOW:

import java.util.Scanner;


public class CustomerShopping {
Scanner sc=new Scanner(System.in);
String customerName;
String InvoiceNo;
int noItemsPurchased;
double subTotal;
// A method that prompts for the customer’s name and returns it from the keyboard.
public String setCustomerName() {
System.out.print("Enter customer Name :");
this.customerName = sc.nextLine();
return this.customerName;
}
// A method called shippingInvoice() that prompts for an invoice number and stores it in a class variable (field) called invoiceNo. Assume the invoice number is a combination of numbers and text.
public String shippingInvoice() {
System.out.print("Enter Invoice Number :");
this.InvoiceNo = sc.nextLine();
return this.InvoiceNo;
}
// Overload the method coded in 1b above so that it accepts a customer’s name through its parameter list, concatenates the name and invoice number in a header and returns the header. This method will not prompt for the name or invoice number. The content of the header will look like this where the Xs represent the actual customer name and invoice number:
public String CombineNameInvoice(String customerName){
String combinedCode = customerName+this.InvoiceNo;
return combinedCode;
}
// A method that prompts for the number of items purchased and returns it from the keyboard.
public int setNoItemsPurchased() {
System.out.print("Enter No of items purchased :");
this.noItemsPurchased = sc.nextInt();
return this.noItemsPurchased;
}
// A method that prompts for the subtotal and returns it from the keyboar
public double setSubTotal() {
System.out.print("Enter Sub Total :");
this.subTotal = sc.nextInt();
return this.subTotal;
}
// A method that accepts the noItemsPurchased and the subtotal through its parameter list and returns an average dollar amount of the items purchased. No prompts are needed.
public double calculateAverage(int noItemsPurchased,double subTotal){
return (double)subTotal/noItemsPurchased;
}
// A method that accepts what is returned by the methods coded in 1c and 1f to print the following:
public void displayBill(String combinedName,double average){
System.out.println("Customer Name: "+combinedName);
System.out.println("Invoice No: "+InvoiceNo);
System.out.println("Average of Items Purchased: "+average);
}

public static void main(String[] args) {
CustomerShopping customer =new CustomerShopping();
String customerName=customer.setCustomerName();
String InvoiceNo=customer.shippingInvoice();
int noItemsPurchased = customer.setNoItemsPurchased();
double subTotal=customer.setSubTotal();
String CombineNameInvoice = customer.CombineNameInvoice(customerName);
double average = customer.calculateAverage(noItemsPurchased, subTotal);
customer.displayBill(CombineNameInvoice, average);
  
}
}


Related Solutions

Coding in Java Assignment Write the following static methods. Assume they are all in the same...
Coding in Java Assignment Write the following static methods. Assume they are all in the same class. Assume the reference variable input for the Scanner class and any class-level variables mentioned are already declared. All other variables will have to be declared as local unless they are parameter variables. Use printf. A method that prompts for the customer’s name and returns it from the keyboard. A method called shippingInvoice() that prompts for an invoice number and stores it in a...
Write a class called VLPUtility with the following static methods: Java Language 1. concatStrings that will...
Write a class called VLPUtility with the following static methods: Java Language 1. concatStrings that will accept a variable length parameter list of Strings and concatenate them into one string with a space in between and return it. 2. Overload this method with two parameters, one is a boolean named upper and one is a variable length parameter list of Strings. If upper is true, return a combined string with spaces in upper case; otherwise, return the combined string as...
JAVA programming- answer prompts as apart of one java assignment Static static variables static methods constants...
JAVA programming- answer prompts as apart of one java assignment Static static variables static methods constants Create a class Die representing a die to roll randomly. ☑ Give Die a public final static int FACES, representing how many faces all dice will have for this run of the program. ☑ In a static block, choose a value for FACES that is a randomly chosen from the options 4, 6, 8, 10, 12, and 20. ☑ Give Die an instance variable...
Create a Class with Data Fields and Methods in Java. Provide a Java coding solution for...
Create a Class with Data Fields and Methods in Java. Provide a Java coding solution for the following: 1. Name the class SalonServices 2. Add private data fields: a. salonServiceDescription – This field is a String type b. price - This field is a double type 3. Create two methods that will set the field values. a. The first method setSalonServiceDescription() accepts a String parameter defined as service and assigns it to the salonServiceDescription. The method is not static b....
Using Java Write the class RecursiveProbs, with the methods listed below. Write all the methods using...
Using Java Write the class RecursiveProbs, with the methods listed below. Write all the methods using recursion, NOT LOOPS. You may use JDK String Methods like substring() and length(), but do not use the JDK methods to avoid coding algorithms assigned. For example, don’t use String.revers(). public boolean recursiveContains(char c, String s) { if (s.length() == 0) return false; if (s.charAt(s.length() - 1) == c) return true; else return recursiveContains(c, s.substring(0, s.length() - 1)); } public boolean recursiveAllCharactersSame(String s) return...
Question 3 A java source module contains the following class with the static methods main and...
Question 3 A java source module contains the following class with the static methods main and procedure1, and the instance method procedure2 (assume given the bodies of procedure1 and procedure2): public class TestQuestion3             {                         static int result, num1 = 10;                         public static void Main( String [ ] args )                         {                                     int [ ] list1 =   { 2, 4, 6, 8, 10}, list2;                                     .    .    .                         }                         static void procedure1( void )                         {                                     .   .   .                         } void procedure2( void )...
Write a class that has three overloaded static methods for calculating the areas of the following...
Write a class that has three overloaded static methods for calculating the areas of the following geometric shapes: - circles - rectangles - cylinders Here are the formulas for calculating the area of the shapes. Area of a circle: Area = π r2, where p is Math.PI and r is the circle's radius Area of a rectangle: Area = Width x Length Area of a cylinder: Area = π r2 h, where p is Math.PI, r is the radius of...
Write a class that has three overloaded static methods for calculating the areas of the following...
Write a class that has three overloaded static methods for calculating the areas of the following geometric shapes: - circles - rectangles - cylinders Here are the formulas for calculating the area of the shapes. Area of a circle: Area = π r2, where p is Math.PI and r is the circle's radius Area of a rectangle: Area = Width x Length Area of a cylinder: Area = π r2 h, where p is Math.PI, r is the radius of...
Write in Java Modify the parent class (Plant) by adding the following abstract methods:(The class give...
Write in Java Modify the parent class (Plant) by adding the following abstract methods:(The class give in the end of question) a method to return the botanical (Latin) name of the plant a method that describes how the plant is used by humans (as food, to build houses, etc) Add a Vegetable class with a flavor variable (sweet, salty, tart, etc) and 2 methods that return the following information: list 2 dishes (meals) that the vegetable can be used in...
write program that develop a Java class Dictionary to support the following public methods of an...
write program that develop a Java class Dictionary to support the following public methods of an abstract data type: public class Dictionary { // insert a (key, value) pair into the Dictionary, key value must be unique, the value is associated with the key; only the last value inserted for a key will be kept public void insert(String key, String value); // return the value associated with the key value public String lookup(String key); // delete the (key, value) pair...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT