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...
Write a java program which asks the user to enter name and age and calls the...
Write a java program which asks the user to enter name and age and calls the following methods: printName(): Takes name as parameter and prints it 20 times using a while loop. printAge(): Takes age as parameter and prints all the numbers from 1 up to age. Write a java program that will print first 10 multiples of 3 in a single line.
write program in java Create a class named PersonalDetails with the fields name and address. The...
write program in java Create a class named PersonalDetails with the fields name and address. The class should have a parameterized constructor and get method for each field.  Create a class named Student with the fields ID, PersonalDetails object, major and GPA. The class should have a parameterized constructor and get method for each field. Create an application/class named StudentApp that declare Student object. Prompts (GUI input) the user for student details including ID, name, address, major and GPA....
Python: Write a program that asks the user for the name of a file. The program...
Python: Write a program that asks the user for the name of a file. The program should display the contents of the file line by line.
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,...
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...
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 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...
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT