Question

In: Computer Science

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

Coding in 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.

g.

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 Java Assignment Write the following static methods. Assume they are all in the same class....
Coding 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 class...
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...
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...
Write a java program that contains 3 overloaded static methods for calculating area of a circle,...
Write a java program that contains 3 overloaded static methods for calculating area of a circle, area of a cylinder and volume of a cylinder. Also create an output method which uses JOptionPaneto display instance field(s) and the result of the computing. Then code a driver class which will run and test calling each of these overloaded methods with hard-coded data and display the data and the result of the calculation by calling output method. Thanks!!
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....
CIT 149 JAVA 1 program question? Write a program that will use static methods as described...
CIT 149 JAVA 1 program question? Write a program that will use static methods as described in the specifications below. Utilizing the if and else statements, write a program which will calculate a commission based on a two-tiered commission plan of 3% and 7% paid on amounts of $15,000 or less, or over $15,000 in monthly sales by a sales force paid on a commission basis. Use the output specifications below. ? Specifications There will be two classes (separate files)...
Write the following methods in a Java project: a) A Java method to determine and return...
Write the following methods in a Java project: a) A Java method to determine and return the sum of first three numbers, where three numbers are received as parameters. b) A Java method to determine and return the highest of N integers. The number of integers is received as a parameter. The method should prompt the user to enter the N numbers, then it return the highest. c) A Java method to determine and return an appropriate value indicating if...
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 JAVA program that contains the following 4 void methods whic will print all subtrings...
Write a JAVA program that contains the following 4 void methods whic will print all subtrings of s in specific orders: printSub1(String s), printSub2(String s), printSub3(String s), and printSub4(String s) For example, if S = "abcd": printSub1 will print "a", "ab", "abc", "abcd", "b", "bc", "bcd", "c", "cd", "d" printSub2 will print "a", "ab", "b", "abc", "bc", "c", "abcd", "bcd", "cd", "d" printSub3 will print "d", "c", "b", "a", "cd", "bc", "ab", "bcd", "abc", "abcd" printSub4 will print "abcd", "bcd",...
JAVA Add static methods largest and smallest to the Measurable interface. The methods should return the...
JAVA Add static methods largest and smallest to the Measurable interface. The methods should return the object with the largest or smallest measure from an array of Measurable objects.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT