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...
Create a java program with class Customer: Name, Surname, ID (incremental ID by 1 for each...
Create a java program with class Customer: Name, Surname, ID (incremental ID by 1 for each new customer), Email, Phone, Address. The program must create New customer, and Print information for customer with a certain ID.   
Write a program in java that asks the name of the buyer and the number of...
Write a program in java that asks the name of the buyer and the number of shares bought. Your program must then calculate and display the following. sold stock/shares to the general public at the rate of $24.89 per share. Theres a 2 percent (2%) commission for the transaction. Outputs need Amount paid for buying the stock ($) Amount paid for the commission ($) Total amount ($)
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....
Write a java program that prompts user to enter his name and KSU ID using format...
Write a java program that prompts user to enter his name and KSU ID using format name-ID as one value, his gender as char, and his GPA out of 5. Then your program should do the following: Print whether the ID is valid or not, where a valid ID should be of length = 9, and should start with 4. Calculate the GPA out of 100 which is calculated as follows GPA/5 * 100. Update the name after converting the...
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...
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT