Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8800495
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T00:36:11+00:00 2026-06-14T00:36:11+00:00

I’m a beginner programmer looking to tweak a project. I did not include code

  • 0

I’m a beginner programmer looking to tweak a project. I did not include code as I have no clue where to start. Basically, I’m capturing input for different airline ticket classes. Such as: type 1 for 1st class, 2 for business, and 3 for economy. Then the input is run through if else statements to determine the cost of each ticket depending on the class. After the price is figured out and passed to another method for calculation with discount rate, I want to display the class type in the output window.

For further clarity it would say something like, (name + “Your class type is: ” + classType + “Your discount price is: ” + discountPrice + “Your finalPrice is:” + finalPrice)…..plus all the formatting elegance. I would like classType to display the actual word instead of just “1” “2” or “3”. I’ve been able to, at least, capture the input and assign prices then calculate. I just wish after doing this that I could return a string value instead of the numeric type. To those who help, thank you much and please remember I’m a noob and haven’t had the opportunity to learn arrays and anything more complicated than that.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T00:36:12+00:00Added an answer on June 14, 2026 at 12:36 am

    Since it’s a simple enough scenario, you can do something like this:

    int typeNum; // This is what holds 1, 2, 3 etc for the type of ticket
                 // 0 is used, so we'll just put a "NONE" as the string for it
    String classType[] = {"NONE", "First Class", "Business", "Economy"};
    ...
    System.out.println(name + 
                       "Your class type is: " + classType[typeNum] + 
                       "Your discount price is: " + discountPrice + 
                       "Your finalPrice is:" + finalPrice);
    

    The “proper” way to do a type-to-string mapping (and just using types in general) is to use enum‘s: http://docs.oracle.com/javase/tutorial/java/javaOO/enum.html

    (Update): As requested for a way to do this without arrays:

    int typeNum; // Still the int that should be either 1, 2, or 3 for type of ticket
    ...
    
    String classType;
    
    if ( typeNum == 1 ) {
        classType = "First Class";
    } else if ( typeNum == 2 ) {
        classType = "Business";
    } else if ( typeNum == 3 ) {
        classType = "Economy";
    } else {
        classType = "(Unrecognized Ticket Type)";
    }
    
    System.out.println(name + 
                       "Your class type is: " + classType + 
                       "Your discount price is: " + discountPrice + 
                       "Your finalPrice is:" + finalPrice);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
Basically, what I'm trying to create is a page of div tags, each has
this is what i have right now Drawing an RSS feed into the php,
Specifically, suppose I start with the string string =hello \'i am \' me And

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.