Question

entry level java program Office Supplies Inc, an office supply store, services many customers. As customers’...


entry level java program

Office Supplies Inc, an office supply store, services many customers. As customers’ orders for office supplies are shipped, information is entered into a file. Office Supplies Inc bills their customers once each month. At the end of each month, the CEO requests a report of all customers sorted by their customer id (from lowest to highest). The report includes their bill balance and tax liability. Write a program to produce the outstanding balance report sorted by customer ID number from the data in the text file. Below is a description of the information on the text file:
 The first line in the file contains the number of customers in the file (integer)
 Then, the fields below repeat for each customer:
o Customer ID (integer)
o Customer name (String)
o Email address (String)
o Bill balance (double)
o Tax liability (double or String)
The customers served by the office supply store are of two types: tax-exempt or non-tax- exempt. For a tax-exempt customer, the tax liability field on the file is the reason for the tax exemptions: education, non-profit, government, other (String). For a non-tax-exempt customer, the tax liability field is the percent of tax that the customer will pay (double) based on the state in which the customer’s business resides.



0 0
Add a comment Improve this question Transcribed image text
Answer #1

// CUSTOMER CLASS

/*

* Customer class to store customer information which implements Comparable Interface

*/

public class Customer implements Comparable<Customer>{

private int customerID;

private String customerName;

private String email;

private double billBalance;

private String taxLiability;

//Compare to method to compare customer based on customer id

@Override

public int compareTo(Customer otherCustomer) {

return (this.customerID < otherCustomer.customerID ) ? -1: (this.customerID > otherCustomer.customerID) ? 1:0 ;

}

/**

* @return the customerID

*/

public int getCustomerID() {

return customerID;

}

/**

* @param customerID the customerID to set

*/

public void setCustomerID(int customerID) {

this.customerID = customerID;

}

/**

* @return the customerName

*/

public String getCustomerName() {

return customerName;

}

/**

* @param customerName the customerName to set

*/

public void setCustomerName(String customerName) {

this.customerName = customerName;

}

/**

* @return the email

*/

public String getEmail() {

return email;

}

/**

* @param email the email to set

*/

public void setEmail(String email) {

this.email = email;

}

/**

* @return the billBalance

*/

public double getBillBalance() {

return billBalance;

}

/**

* @param billBalance the billBalance to set

*/

public void setBillBalance(double billBalance) {

this.billBalance = billBalance;

}

/**

* @return the taxLiability

*/

public String getTaxLiability() {

return taxLiability;

}

/**

* @param taxLiability the taxLiability to set

*/

public void setTaxLiability(String taxLiability) {

this.taxLiability = taxLiability;

}

}

// GENERATEREPORT CLASS with main method

import java.io.File;

import java.io.FileNotFoundException;

import java.util.ArrayList;

import java.util.Collections;

import java.util.Scanner;

public class GenerateReport {

public static void main(String[] args) throws FileNotFoundException {

Customer customer;

File file = new File("input.txt"); //file containing customers’ orders

Scanner sc = new Scanner(file);

int records = Integer.parseInt(sc.nextLine()); //no of customers

ArrayList<Customer> customerList = new ArrayList<Customer>(records); //List to store customers

String line;

String fields[];

while(sc.hasNextLine()){

line = sc.nextLine();

fields = line.split(" ");

customer = new Customer();

//Setting customer fields from the file

customer.setCustomerID(Integer.parseInt(fields[0]));

customer.setCustomerName(fields[1]);

customer.setEmail(fields[2]);

customer.setBillBalance(Double.parseDouble(fields[3]));

customer.setTaxLiability(fields[4]);

//adding customer to list

customerList.add(customer);

}

sc.close();

//sorting customers based on customer id (implemented in compareTo method in Customer class)

Collections.sort(customerList);

//Printing report to the console

System.out.print(String.format("%-8s %-20s %-20s %-15s %-8s\n","ID", "Customer Name", "Email", "Bill Balance", "Tax Liability"));

for (Customer var : customerList) {

System.out.print(String.format("%-8s %-20s %-20s %-15s %-8s\n", var.getCustomerID(), var.getCustomerName(), var.getEmail(), var.getBillBalance(), var.getTaxLiability()));

}

}

}

// input.txt file for sample input

5
189 Rafique [email protected] 12550.3 10.0
180 Raj [email protected] 12340.3 12.0
111 Bilkish [email protected] 2550.3 20.0
100 Zarina [email protected] 90550.3 40.0
220 Ranjit [email protected] 2011 Education

Add a comment
Know the answer?
Add Answer to:
entry level java program Office Supplies Inc, an office supply store, services many customers. As customers’...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write in java language ================== Office Supplies Inc., an office supply store, services many customers. As...

    Write in java language ================== Office Supplies Inc., an office supply store, services many customers. As customers’ orders for office supplies are shipped, information is entered into a file. Office Supplies bills their customers once each month. At the end of each month, the Chief Executive Officer requests a report of all customers sorted by their customer id (from lowest to highest). The report includes their bill balance and tax liability. Write a program to produce the outstanding balance report...

  • Office supply store: South of Fifth Copy Boutique is a small office supplies/office services store that...

    Office supply store: South of Fifth Copy Boutique is a small office supplies/office services store that sells stationery and mailing supplies, such as envelopes, paper boxes, pens, tape, etc. It also has a two printers, a scanner, and two copy machines that customers can use on a first-come first-serve basis, or reserve them in advance in 15 minute blocks of time. The owner is also a general manager and runs the operations, and employs one part-time worker who is usually...

  • Write a Java program to read customer details from an input text file corresponding to problem...

    Write a Java program to read customer details from an input text file corresponding to problem under PA07/Q1, Movie Ticketing System The input text file i.e. customers.txt has customer details in the following format: A sample data line is provided below. “John Doe”, 1234, “Movie 1”, 12.99, 1.99, 2.15, 13.99 Customer Name Member ID Movie Name Ticket Cost Total Discount Sales Tax Net Movie Ticket Cost Note: if a customer is non-member, then the corresponding memberID field is empty in...

  • Java Question 3 Implement a program to store the applicant's information for a visa office. You...

    Java Question 3 Implement a program to store the applicant's information for a visa office. You need to implement the following: A super class called Applicant, which has the following instance variables: A variable to store first name of type String. A variable to store last name of type String. A variable to store date of birth, should be implemented as another class to store day, month and year. A variable to store number of years working of type integer...

  • Files, Pointers and Dynamic Memory Allocation, and Structs Due date/time: Tuesday, Nov 26th, 11:00 PM. WRITE...

    Files, Pointers and Dynamic Memory Allocation, and Structs Due date/time: Tuesday, Nov 26th, 11:00 PM. WRITE A C++ PROGRAM (USE DYNAMIC MEMORY ALLOCATION) THAT READS N CUSTOMER RECORDS FROM A TEXT FILE (CUSTOMERS.TXT) SUCH THAT THE NUMBER OF THE RECORDS IS STORED ON THE FIRST LINE IN THE FILE. EACH RECORD HAS 4 FIELDS (PIECES OF INFORMATION) AND STORED IN THE FILE AS SHOWN BELOW: Account Number (integer) Customer full name (string) Customer email (string) Account Balance (double) The program...

  • Cant figure out how to fix error Code- import java.io.File; import java.io.IOException; import java.util.*; public class Program8 {    public static void main(String[] args)throws IOException{       ...

    Cant figure out how to fix error Code- import java.io.File; import java.io.IOException; import java.util.*; public class Program8 {    public static void main(String[] args)throws IOException{        File prg8 = new File("program8.txt");        Scanner reader = new Scanner(prg8);        String cName = "";        int cID = 0;        double bill = 0.0;        String email = "";        double nExempt = 0.0;        String tExempt = "";        int x = 0;        int j = 1;        while(reader.hasNextInt()) {            x = reader.nextInt();}        Customers c1 [] = new Customers [x];        for (int...

  • Needs Help with Java programming language For this assignment, you need to write a simulation program...

    Needs Help with Java programming language For this assignment, you need to write a simulation program to determine the average waiting time at a grocery store checkout while varying the number of customers and the number of checkout lanes. Classes needed: SortedLinked List: Implement a generic sorted singly-linked list which contains all of the elements included in the unsorted linked list developed in class, but modifies it in the following way: • delete the addfirst, addlast, and add(index) methods and...

  • Write a Java program which will store, manipulate, and print student registration information. As part of...

    Write a Java program which will store, manipulate, and print student registration information. As part of the solution, identify the following classes: Student Admissions. The class Student must have the following fields – Name, Address, Id number, Courses, and Date, where: Name is a user defined class comprising of at minimum first name and last name. Address is a user defined class comprising of fields - street, city, state, and zip code. Date is a predefined class in the java.util...

  • write a code on .C file Problem Write a C program to implement a banking application...

    write a code on .C file Problem Write a C program to implement a banking application system. The program design must use a main and the below functions only. The program should use the below three text files that contain a set of lines. Sample data of these files are provided with the assessment. Note that you cannot use the library string.h to manipulate string variables. For the file operations and manipulations, you can use only the following functions: fopen(),...

  • In this assignment, we will be making a program that reads in customers' information, and create...

    In this assignment, we will be making a program that reads in customers' information, and create a movie theatre seating with a number of rows and columns specified by a user. Then it will attempt to assign each customer to a seat in a movie theatre. 1. First, you need to add one additional constructor method into Customer.java file. Method Description of the Method public Customer (String customerInfo) Constructs a Customer object using the string containing customer's info. Use the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT