Results 1 to 2 of 2
  1. #1
    sgaffigan is offline Member
    Join Date
    Feb 2017
    Posts
    1
    Rep Power
    0

    Default Help with methods program

    I have a program due but i'm new to Java and can't figure out how to fix my program. Here's what I have so far and I attached the assignment. If someone could help me out that would be great!
    //--Import the needed packages--
    import java.util.Scanner;
    //--Start class Methods--
    public class Methods
    {
    //--Declare class level variables--
    static String strMethodCalls= "";
    //--Begin main method--
    public static void main (String [] args)
    {
    //--Will declare Scanner and begin a do-while loop--
    //--this will display the menu and process accordingly--
    Scanner input = new Scanner (System.in);
    double dTotal = 0;
    int iChoose;
    do
    {
    iChoose = displayMenu();

    switch (iChoose){
    case 1:
    getFlightOption();
    break;
    case 2:
    getHotelOption();
    break;
    case 3:
    calculateAndDisplayTotal();
    break;
    case 9:
    break;
    default:
    System.out.println("Please enter a valid menu option");
    }
    System.out.println("\nOur global string is now: "+strMethodCalls);
    } while (iChoose !=9);
    System.out.println("Thank you for using our program!");
    }

    public static int displayMenu(Scanner input)
    {
    Scanner input = new Scanner (System.in);
    int iChoice =0;
    System.out.println("Welcome to Mustang Vacations");
    System.out.println("============================== ====");
    System.out.println("Choose from the following menu options: ");
    System.out.println("1) Flights");
    System.out.println("2) Hotels");
    System.out.println("3) Display Total");
    System.out.println("9) Exit");
    System.out.println("Enter option: ");
    iChoice = input.nextInt();
    return iChoice;
    }
    //--Method methodOne
    //--------------------------
    public static void getFlightOption(Scanner scn)
    {
    Scanner input = new Scanner (System.in);
    int iFlight = 0;

    System.out.println("Choose from the following flight options: ");
    System.out.println("-----------------------------------------");
    System.out.println("1) Morning flight ($500.00) ");
    System.out.println("2) Afternoon flight ($600.00) ");
    System.out.println("3) Evening flight ($700.00) ");
    System.out.println("(Press any other number to exit the flight menu and return to the main menu)");
    System.out.println("Enter option: ");
    iFlight = scn.nextInt();
    if (iFlight==1) {
    System.out.println("Your morning flight is booked! Morning flights are $500.00 + tax.");
    }
    if (iFlight==2) {
    System.out.println("Your afternoon flight is booked! Afternoon flights are $600.00 + tax.");
    }
    if (iFlight==3) {
    System.out.println("Your evening flight is booked! Evening flights are $700.00 + tax.");
    }
    strMethodCalls += " ";
    return;
    }
    //--Method methodTwo
    //----------------------------
    public static void getHotelOption(Scanner scn)
    {
    Scanner input = new Scanner (System.in);
    int iNights = 0;
    System.out.println("How many nights would you like to stay? Enter the number of nights: ");
    iNights = scn.nextInt();
    if (iNights==1){
    System.out.println("The rate for 1 night is $100.00 + tax");
    }
    if (iNights==2){
    System.out.println("The rate for 2 nights is $120.00 + tax");
    }
    if (iNights==3){
    System.out.println("The rate for 3 nights is $130.00 + tax");
    }

    strMethodCalls += " ";
    }
    //--Method methodThree
    //-----------------------------
    public static void calculateAndDisplayTotal(Scanner scn)
    {
    System.out.println("Your total before taxes is: ");
    System.out.println("You recieved a discount of : ");
    System.out.println("Your total after discount + taxes is: ");
    strMethodCalls += "Called Method Three.";
    return;
    }
    } //--End Class
    Attached Files Attached Files

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,001
    Rep Power
    33

    Default Re: Help with methods program

    Please edit your post and wrap your code with code tags:

    [code]
    **YOUR CODE GOES HERE**
    [/code]

    to get highlighting and preserve formatting.

    how to fix my program
    Why do you think it needs to be fixed? Can you explain?
    Post something here that shows what the program does and add comments saying what is wrong.
    If you don't understand my response, don't ignore it, ask a question.

Similar Threads

  1. Need Help With creating a Methods Program
    By jonathan in forum New To Java
    Replies: 5
    Last Post: 07-18-2012, 10:49 PM
  2. New to Methods -- need help with a counting program
    By ajfonty in forum New To Java
    Replies: 2
    Last Post: 05-18-2012, 07:46 PM
  3. New to Methods -- need help with a counting program
    By ajfonty in forum New To Java
    Replies: 0
    Last Post: 05-18-2012, 06:59 PM
  4. Incorporating Methods into my program
    By Moltisanti in forum New To Java
    Replies: 16
    Last Post: 10-12-2009, 06:48 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •