Results 1 to 3 of 3
  1. #1
    freky8ss is offline Member
    Join Date
    May 2013
    Location
    Virginia
    Posts
    1
    Rep Power
    0

    Talking User inputs string to get calculated output

    Java- two strings that equal separate math functions output when user enters either word?
    Up to the strings, everything is fine. I am VERY new to java. I'm looking to see if I'm heading in the right direction. I would like the user to either enter 'total' or 'person' to get the grand total or total per person. If the enter neither, I want it to say 'Please enter either one'. I want that to loop until they enter the right word. When they do, I want it to output the answer. I have the formulas below but I'm not sure if the formatting is correct. I have to use two loops. I'm preferring a while and if else loop. Thank you!!!!!


    import java.util.Scanner;

    public class Reunion {

    public static void main ( String[] args ) {

    System.out.println("This program calculates the cost of a class reunion event.");
    System.out.println("It gives back the total cost and the cost per person.");


    Scanner in = new Scanner(System.in);
    int rent = 200;
    double hour;
    double totalrent;

    System.out.println("Please enter the number of hours you would like to rent a room: ");

    hour= in.nextDouble();

    totalrent= rent * hour;

    System.out.printf("Your total cost for renting a room is: $%3.0f\n", totalrent);

    System.out.println("Enter number of guests for cost of dinner plates: ");

    int plate = 40;
    int guest;
    int totalplate;

    guest= in.nextInt();

    totalplate= plate * guest;

    System.out.printf("Your total cost for dinner plates is: $%d%n", totalplate);


    System.out.println("Enter 'total' for grand total, which includes hourly rent, dinner, and band.");
    System.out.println("Enter 'person' to get total for each person; dividing the grand total evenly.");

    String.total = int total;
    String.person = int person;
    int band = 350;
    int total;

    total = band + totalplate + totalrent;
    person = total/guest;

    while(!String.total.equals("total") && !String.person.equals("person")) {
    System.out.println("Please only enter 'total' or 'person'.");

    if(input.equals("total")){
    System.out.printf("Your grand total is: $%3.0f\n", total);

    else if(input.equals("person")){
    System.out.printf("Your total per person is: $%3.2f\n", person);



    System.out.println("End of program");
    }
    }

  2. #2
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,798
    Rep Power
    7

    Default Re: User inputs string to get calculated output

    Do you have a specific question?

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,251
    Rep Power
    19

Similar Threads

  1. Replies: 1
    Last Post: 10-24-2012, 12:21 PM
  2. Question on user inputs and strings
    By steve0827 in forum New To Java
    Replies: 7
    Last Post: 10-04-2012, 02:49 PM
  3. Controlling User Inputs
    By time-space in forum New To Java
    Replies: 5
    Last Post: 05-30-2011, 02:50 PM
  4. Sum positive numbers using 10 inputs from user
    By pvictory1 in forum New To Java
    Replies: 15
    Last Post: 10-10-2010, 01:30 AM
  5. Replies: 0
    Last Post: 09-13-2008, 12:59 AM

Posting Permissions

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