Question

In: Computer Science

Write a Java program which asks customer name, id, address and other personal information, there are...

Write a Java program which asks customer name, id, address and other personal information, there are two types of customers, walk-in and credit card. The rates of items are different for both type of customers. System also asks for customer type. Depending upon customer type, it calculates total payment.
A credit-card customer will pay 5 % extra the actual price.
Use object-oriented concepts to solve the problem. Define as many items and prices as you want.
Example Output:
Enter Name of Customer: John
Enter Id: 15
Customer Type: Card
Select items:1 3 6
The total price is 560

Solutions

Expert Solution

Customer.java

//defining a customer class

class Customer{

String name, id, address, email, customerType;

int phone;

//parameterized constructor

public Customer(String _name, String _id, String _address, int _phone, String _email, String _customerType){

name = _name;

id = _id;

address = _address;

phone = _phone;

email = _email;

customerType = _customerType;

}

}

Item.java

class Item{

int id;

double price;

public Item(int _id, double _price){

id = _id;

price = _price;

}

}

Main.java

import java.util.*;

class Main {

public static void main(String[] args) {

Scanner scn = new Scanner(System.in);

//input user details

String _name, _id, _address, _email;

int _phone;

System.out.print("Name: ");

_name = scn.next();

System.out.print("ID: ");

_id = scn.next();

System.out.print("Address: ");

_address = scn.next();

System.out.print("Phone: ");

_phone = scn.nextInt();

System.out.print("Emial: ");

_email = scn.next();

System.out.print("Customer Type ");

String _customerType = scn.next();

//create a customer object with given details

Customer customer = new Customer(_name, _id, _address, _phone, _email, _customerType);

//add some items to our items catalog

ArrayList<Item> items = new ArrayList<>();

items.add(new Item(1, 20));

items.add(new Item(3, 50));

items.add(new Item(6, 60));

items.add(new Item(4, 90));

System.out.println("Select items");

//create a shoping cart for our customer

ArrayList<Item> cart = new ArrayList<>();

int j = 0;

//item entered by th customer are added to cart if the exist in our cataog

while(j < 3){

int item = scn.nextInt();

for(Item i : items){

if(item == i.id){

cart.add(i);

}

}

j++;

}

//after all items are added to the cart we begin calculating the price

double price = 0;

for(Item i: cart){

price += i.price;

}

//if customer is a credit card customer than he has to pay 5% extra

if(customer.customerType.compareTo("CARD") == 0){

price += price * 0.05;

}

//output the price details

System.out.println("The total price is "+price);

}

}


Related Solutions

Write a Java program for a restaurant with the following features: ◦ Customer: Name, Surname, ID...
Write a Java program for a restaurant with the following features: ◦ Customer: Name, Surname, ID (incremental ID by 1 for each new customer), Email, Phone, Address. ◦ Service: ID (incremental ID by1 for each group),CustomerID, Priority (High, Medium, Low, Other), ResolutionTimeFrame (Measured in Man hours), AssignedUser, Status(resolved or not), Fee. ◦ User (simple user of system): ID, Name, Surname, Username and Password (insert from code five fixed users), Address , PhoneNumber ◦ Manager: Name, Surname, Username and Password (insert...
Code in Java Write a Student class which has two instance variables, ID and name. This...
Code in Java Write a Student class which has two instance variables, ID and name. This class should have a two-parameter constructor that will set the value of ID and name variables. Write setters and getters for both instance variables. The setter for ID should check if the length of ID lies between 6 to 8 and setter for name should check that the length of name should lie between 0 to 20. If the value could not be set,...
This is Java In this problem we will write a program that asks the user to...
This is Java In this problem we will write a program that asks the user to enter a) The user's first name and b) a series of integers separated by commas. The integers may not include decimal points nor commas. The full string of numbers and commas will not include spaces either, just digits and commas. An example of valid input string is:        7,9,10,2,18,6 The string must be input by the user all at once; do not use a loop...
Write a Java program to process the information for a bank customer.  Create a class to manage...
Write a Java program to process the information for a bank customer.  Create a class to manage an account, include the necessary data members and methods as necessary.  Develop a tester class to create an object and test all methods and print the info for 1 customer.  Your program must be able to read a record from keyboard, calculate the bonus and print the details to the monitor.  Bonus is 2% per year of deposit, if the amount is on deposit for 5 years...
Write a program IN JAVA that asks the user for a number. The program should check...
Write a program IN JAVA that asks the user for a number. The program should check the number to ensure that it is valid (if not, the user should enter a valid number to continue.) The program should print out all of the prime numbers from 2 up to the number, with up to 10 numbers per line. (Recall: A prime number is a number that is only divisible by itself and 1.) The code should ask the user if...
Program should be written in Java a) Write a program that asks the user to enter...
Program should be written in Java a) Write a program that asks the user to enter the approximate current population of India. You should have the computer output a prompt and then YOU (as the user should enter the population.)  For testing purposes you may use the value of 1,382,000,000 from August 2020. Assume that the growth rate is 1.1% per year. Predict and print the predicted population for 2021 and 2022. The printout should include the year and the estimated...
Write a program that asks the user to enter the name of a file, and then...
Write a program that asks the user to enter the name of a file, and then asks the user to enter a character. The program should count and display the number of times that the specified character appears in the file. Use Notepad or another text editor to create a sample file that can be used to test the program. Sample Run java FileLetterCounter Enter file name: wc4↵ Enter character to count: 0↵ The character '0' appears in the file...
Tail of a File, C++ Program. write a program that asks the user for the name...
Tail of a File, C++ Program. write a program that asks the user for the name of a text file. The program should display the last 10 lines, or all lines if less than 10. The program should do this using seekg Here is what I have so far. #include<iostream> #include<fstream> #include<string> using namespace std; class File { private:    fstream file;    string name; public:    int countlines();    void printlines(); }; int File::countlines() {    int total =...
Write a Java program that asks the user to enter an integer that is used to...
Write a Java program that asks the user to enter an integer that is used to set a limit that will generate the following four patterns of multiples of five using nested loops •Ascending multiples of five with ascending length triangle •Ascending multiples of five with descending length (inverted) triangle •Descending multiples of five with ascending length triangle •Descending multiples of five with descending length (inverted) triangle Use error checking to keep asking the user for a positive number until...
Problem: Read the following tables and answer the following questions: Customers Customer ID Name Address Phone...
Problem: Read the following tables and answer the following questions: Customers Customer ID Name Address Phone Email 9087 John Doe 204 University Ave. 987-098-9087 [email protected] 2098 Bill Lawrence 123 Jones St 717-387-3387 Business 2398 Laura Smith 0900 West Blvd. 901-234-4567 Information Transactions Customer ID Account Number Date of Last Transaction 9087 375 01/31/98 2098 123 03/09/97 2398 375 09/21/97 2098 375 12/31/97 2398 123 02/01/98 Accounts Account Number Balance Account Type 375 234.45 Checking 123 056.90 Savings 1. Who owns...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT