I am working on a project where I need to return 3 values I understand I can only return one using a method alone! So I need to add 2 instance variables, that will return the other 2 values. Can someone please assist me in this? Here is my code, it may be completely wrong! I have used a larger font and commented as much as possible about where I am having a problem!
Here is my separate classimport java.util.Scanner; // The Bandwidth class public class WebHostOrder14 { private double highestCharge; // instance variable for highestCharge private double lowestCharge; // instance variable for lowestCherge private Scanner scanner; //create a new constructor to do the work public WebHostOrder14() { WebHost webHost; double average; double shipping; double highest; double lowest; System.out.println("\nWelcome to the Web Host Ordering System\n"); scanner = new Scanner(System.in); average = computeAverageSales(); System.out.printf("\nThe average sales for these packages is: $" + average); if (average >= 200) { System.out.println("\nWow! Those sales are awesome!!\n"); } shipping = computeShippingCharges(); System.out.printf("\nThe shipping charges total up to $" + shipping); } private double computeAverageSales() { WebHost webHost; double average; double total = 0; int counter = 0; while (true) { System.out.printf("Please enter the price of the new package: $"); double webHostPrice = scanner.nextDouble(); total = webHostPrice + total; counter++; if (webHostPrice == 0 || webHostPrice == 0.00) { break; } else if (webHostPrice <= -1) { System.out.println("Please, enter a positive number!"); } else if (webHostPrice > 500) { System.out.println("That is unrealistic, please enter the correct amount!"); } else if (webHostPrice >=1 || webHostPrice <= 500){ System.out.printf("You entered price $" + webHostPrice); }// end webHostPrice validation System.out.print("What will be the product ID: "); int webHostId = scanner.nextInt(); scanner.nextLine(); if (webHostId <= 0) { System.out.println("Please, enter a positive number!"); } else if (webHostId > 10000) { System.out.println("Please enter the correct produce ID!"); } // end webHostId validation statements System.out.print("What is the product name: "); String webHostName = scanner.next(); if (webHostName == null){ System.out.println("Please enter a valid product name!"); }// end webHostName validation System.out.print("Please enter the required Bandwidth needed for your site? "); double webHostBandwidth = scanner.nextDouble(); if (webHostBandwidth <= 0){ System.out.println("Please enter a positive number!"); } else if (webHostBandwidth > 1000000){ System.out.println("That seems high are you sure?"); } // end webHostBandwidth validation System.out.print("How many FTP accounts do you need? "); int webHostFtp = scanner.nextInt(); if (webHostFtp <= 0){ System.out.println("Please enter a positive number!"); } else if (webHostFtp > 100){ System.out.println("Please enter a valid number!"); } // emd webHostFtp validation System.out.print("How many email accounts do you need? "); int webHostMail = scanner.nextInt(); if (webHostMail <= 0){ System.out.print("Please enter a positive number!"); } else if (webHostMail > 500){ System.out.println("Please enter a valid number!"); } // end webHostMail validation System.out.print("What is your domain name? "); String webHostDomain = scanner.next(); if (webHostDomain == null){ System.out.println("Please enter a valid domain!"); } // end webHostDomain validation } // end while statement average = total / (counter - 1); return average; } // end computeAverageSales [SIZE=4] /*Here is where my problem is*/[/SIZE] private double computeShippingCharges() { WebHost webHost; double shipping = 0; double highest; double lowest; double x = 0; double y = 0; System.out.println("\nWelcome to the Shipping Wizard!\n"); System.out.println("\nEnter 0 to end!\n"); // while (true) { // Acquire a price. A price == 0 indicates end-of-data System.out.print("Please enter shipping charges: $"); double charges = scanner.nextDouble(); charges = x; if (charges < x){ highest = x; System.out.printf("The highest sales price added was $" + highest); } else if (charges > x){ x= y; lowest = y; System.out.print("The lowest value was $" + lowest); } // Test for end-of-data /* if (charges <= -1) { System.out.println("Please enter a positive number!"); charges = scanner.nextDouble(); } else if (charges > 1000) { System.out.println("That is unrealistic please enter the correct value!"); charges = scanner.nextDouble(); } else if (charges == 0){ break; } }*/ return shipping; } public static void main(String[] args) { WebHost webHost = new WebHost(); new WebHostOrder14(); } // end main } // end program
class WebHost { private double bandwidth, price, [SIZE=4]highest, lowest[/SIZE]; private int ftp, mail, id; private String domain, name; // Constructors WebHost() { setWebHostBandwidth(0.0); setWebHostPrice(0.0); [SIZE=4]setWebHostHighest(0.0); //// added this//// setWebHostLowest(0.0); //// and added this////[/SIZE] setWebHostFtp(0); setWebHostMail(0); setWebHostId(0); setWebHostDomain(""); setWebHostName(""); } // End WebHost WebHost(double bandwidth, double price, [SIZE=4]double highest, double lowest[/SIZE], int ftp, int mail, int id, String domain, String name) { setWebHostBandwidth(bandwidth); setWebHostPrice(price); [SIZE=4]setWebHostHighest(highest); setWebHostLowest(lowest);[/SIZE] setWebHostFtp(ftp); setWebHostMail(mail); setWebHostId(id); setWebHostDomain(domain); setWebHostName(name); } // end WebHost //Getters and Setters public double getWebHostBandwidth() { return bandwidth; } //end getWebHostBandwidth public double getWebHostPrice() { return price; } //end getWebHostPrice [SIZE=4]////added the next 2 sections of code below//// public double getWebHostHighest(){ return highest; } public double getWebHostLowest(){ return lowest; } [/SIZE] public int getWebHostFtp() { return ftp; } //end getWebHostFtp public int getWebHostMail() { return mail; } //end getWebHostMail public int getWebHostId() { return id; } //end getWebHostId public String getWebHostDomain() { return domain; } //end getWebHostDomain public String getWebHostName() { return name; } //end getWebHostName public final void setWebHostBandwidth(double bandwidth) { this.bandwidth = bandwidth; } //end setBandwidth public final void setWebHostPrice(double price) { this.price = price; }//end setPrice [SIZE=4]//// again I added the next 2 sections below as well////// public final void setWebHostHighest(double highest){ this.highest = highest; } public final void setWebHostLowest(double lowest){ this.lowest = lowest; } [/SIZE] public final void setWebHostFtp(int ftp) { this.ftp = ftp; } //end setFtp public final void setWebHostMail(int mail) { this.mail = mail; } //end setMail public final void setWebHostId(int id) { this.id = id; } //end setId public final void setWebHostDomain(String domain) { this.domain = domain; } //end setDomain public final void setWebHostName(String name) { this.name = name; } //end setName // Display WebHost data public void display() { System.out.println("\nThank you for your order you ordered a package " + "with\n" + "Bandwidth: " + getWebHostBandwidth() + " Mbits\n" + getWebHostFtp() + " FTP accounts\n" + getWebHostMail() + " mail accounts\n" + "For the domain of\n " + getWebHostDomain()); System.out.println("This package has an ID of: " + getWebHostId() + "/nThe package name is: " + getWebHostName() + "/nThe price is set at: $" + getWebHostPrice()); } // end display() } // end class WebHost