Respuesta :
Using the knowledge in computational language in JAVA it is possible to write a code that handles the order list for if I were an online retailer.
Writting the code:
import java.lang.*;
import java.util.*;
class Fruit{
private String fruit_name;
private double tot_weights;
private double price;
public const static String fruit_nvalue="?";
public const static double def_value=0.0;
public Fruit(){
fruit_name=fruit_nvalue;
tot_weights=price=def_value;
}
public Fruit(String fruit_name,double tot_weights,double price){
this.fruit_name=fruit_name;
this.tot_weights=tot_weights;
this.price=price;
}
public double order(double order_weights){
if(order_weights>tot_weights){
return double(-1);
}
else{
tot_weights=tot_weights - order_weights;
return order_weights*price;
}
}
public Boolean equals(String fruit1,double wei1,double price1,String fruit2,double wei2,double price2){
if(((fruit1.equals(fruit2)) &&(wei1==wei2) && (price1==price2))== true ){
return true
}
}
public String toString(){
return fruit_name+" "+tot_weights+" "+price;
}
}
class OnlineSuperMarket{
private Fruit[] fruit_objects;
private String store_name;
private String web_address;
public const static float tax_rate = 0.095;
public const static int size=10;
public const static sn="TBD";
public const static wa="www.unknown.com";
Scanner scan=new Scanner(System.in);
public OnlineSuperMarket(){
fruit_objects=new Fruit[size];
store_name = sn;
web_address = wa;
}
public OnlineSuperMarket(String store_name,String web_address){
this.store_name=store_name;
this.web_address=web_address;
fruit_objects=new Fruit[size];
}
public void init(){
String fruit_names[];
double weights[];
double prices[];
for(int i=0;i<fruit_objects.length;i++){
fruit_objects[i]=new Fruit(scan.next(),scan.nextDouble(),scan.nextDouble());
}
}
public void sort(){
Arrays.sort(fruit_objects);
}
public void run(){
while(true){
System.out.println(" Enter a fruit name or Q (or q) to end:");
String choice= scan.next();
if(choice = "Q" || choice = "q"){
quit();
}
else{
if(find(choice)){
System.out.println("Enter weight in lbs:");
double weight=new nextDouble();
double price = order(weight);
if(price == double(-1)){
System.out.println("quantity not available");
}
else{
total_cost = price+tax_rate;
System.out.println("You ordered");
System.out.println("Fruit: "+choice);
System.out.println("Weight: "+weight+" lbs");
System.out.println("Price: "+price+"/lbs");
System.out.println("Total cost (plus tax): $"+total_cost);
}
}
else{
System.out.println(choice+" not available");
}
}
}
}
public void showFruits(){
for(Fruit obj:fruit_objects){
System.out.println(obj.toString());
}
}
public void quit(){
showFruits();
System.out.println("Thanks for your visit. Please come again!");
System.exit();
}
public Boolean find(Strign fruit_name){
sort();
int first=0;
int last = fruit_objects.length;
int mid = (first + last)/2;
while( first <= last ){
if (fruit_objects[mid] < fruit_name ){
first = mid + 1;
}else if ( fruit_objects[mid].equals(fruit_name) ){
return true;
break;
}else{
last = mid - 1;
}
mid = (first + last)/2;
}
if ( first > last ){
return false;
}
}
}
public class Design{
public static void main(String[] args) {
OnlineSuperMarket osm=null;
osm = new OnlineSuperMarket(store_name, web_address);
init();
showFruits();
sort();
showFruits();
}
}
See more about JAVA at brainly.com/question/12975450
#SPJ1