Question: Based on the code below and the relation below. Write a separate function, in which submits the users order. The program acquires a confirmation of

Based on the code below and the relation below. Write a separate function, in which submits the users order. The program acquires a confirmation of submitting the order before it is submitted. The program returns back to the main menu with the function displayMenu() after the order is submitted and the cart is emptied. However, if the memeber does not confirm the submission of the order, the program also returns the main menu and the shopping cart stays intact.

MEMBER(last_name, first_name, email, password, user, street, city, state, zip, card_type, card_no, expiration, name_on_card)

CAR_SALE(listing_no, seller, isbn, condition, price)

ORDERS(order_no, buyer, order_date, total)

ITEMS(order_no, listing_no)

CAR(model, make, year, transmission, type, keywords)

import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; import java.util.List; import java.util.Scanner;

import javax.swing.event.CaretListener;

public class CarSale { class Car{ int car_no; String seller; String make; String model; int price; public int getCar_no() { return car_no; } public void setCar_no(int car_no) { this.car_no = car_no; } public String getSeller() { return seller; } public void setSeller(String seller) { this.seller = seller; } public String getMake() { return make; } public void setMake(String make) { this.make = make; } public String getModel() { return model; } public void setModel(String model) { this.model = model; } public int getPrice() { return price; } public void setPrice(int price) { this.price = price; } @Override public String toString(){ return "Seller: " + seller + " Price: " + price + " Make: "+ make + " Model: " + model; } } private static String url = "jdbc:postgresql://localhost/trainingdb"; private static String user = "postgres"; private static String password = "postgres"; private static String query = "SELECT * FROM CAR_SALE WHERE CAR_NO = ?"; public static Connection connect() { Connection conn = null; try { conn = DriverManager.getConnection(url, user, password); System.out.println("Connected to the PostgreSQL server successfully."); } catch (SQLException e) { System.out.println(e.getMessage()); } return conn; } public static void main(String args[]) { int count = 0; List lstCart = new ArrayList<>(); List carList = new ArrayList<>(); Connection conn = connect(); if(conn!=null){ System.out.println("Connection OK"); }else System.out.println("Connection failed."); Scanner scan = new Scanner(System.in); System.out.print(" Enter car number to search: "); String car_no = scan.nextLine(); PreparedStatement ps = conn.prepareStatement(query); ps.setInt(1,Integer.parseInt(car_no)); ResultSet rs = ps.executeQuery(); while(rs.next()){ Car car = new CarSale().new Car(); car.setCar_no(rs.getInt(1)); car.setSeller(rs.getString(2)); car.setPrice(rs.getInt(3)); car.setModel(rs.getString(4)); car.setMake(rs.getString(5)); carList.add(car); count++; } if(count == 0){ System.out.println("No car available matching the car number " + car_no); }else{ for(int i=0;i=count) System.out.println("Wrong option try again..."); else{ Car car = carList.get(option); StringBuilder sb = new StringBuilder(); sb.append("Details of cart "); sb.append("Seller: " + car.getSeller()+" "); sb.append("Make: " + car.getMake() + " "); sb.append("Model: " + car.getModel()+" "); sb.append("price: " + car.getPrice()); System.out.println("Car added to cart successfully"); System.out.println(sb.toString()); break; } }while(true); }

} }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!