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...
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....
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 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...
in Java please For this assignment you are to write a class that supports the addition...
in Java please For this assignment you are to write a class that supports the addition of extra long integers, by using linked-lists. Longer than what is supported by Java's built-in data type, called long. Your program will take in two strings, consisting of only digits, covert each of them to a linked-list that represents an integer version on that string. Then it will create a third linked-list that represents the sum of both of the linked lists. Lastly, it...
Write the following methods in java class ARM that represent state information as well as functional...
Write the following methods in java class ARM that represent state information as well as functional blocks of the ARM platform. [Go through the following 5 classes then write methods for the instructions: mov, str, ldr, add in class ARM, finally, write a print method for ARM in Main.java that can display the registers and the memory locations that have been used. (make sure to make a visualization of the print method instead of just a console dump)] --- Please...
In Lab 4, you made a class with static methods. The static methods converted an integer...
In Lab 4, you made a class with static methods. The static methods converted an integer in binary, Hex, and Octal. To do this, you made a class of static methods. The class did not have any fields. The static methods received the integer value as a parameter. For this lab, make all of the static methods, non-static methods. Lab 5 Requirements Create a class named “Lab5_IntConv_Class Have one private field name intValue. Add two constructors: One is a default...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT