Issue#1189: help me solve this problem,by making changes in the body of class.

  • You will create a class Person and write a constructor that takes an integer, initial_Age. In this constructor, you should check that the initial_Age is not negative because we can't have people with negative ages.

    If the initial_Age is negative, set the instance's age equal to zero then print

    "This person is not valid, setting age to 0."
    

    without the <g class="gr_ gr_58 gr-alert gr_gramm undefined Punctuation multiReplace" data-gr-id="58" id="58">quotations..</g>

    Inside of this class, you will also create an instance variable called age and if initial_Age is not negative, then you will set age to equal the value of initial_Age. In addition, you will write an instance method, amIOld(), that prints whether people are old or not to the console.

    In amIOld(), do the following things:

    • If the age of the Person instance is less than 13, then print "You are young."
    • If the age of the Person instance is equal or greater than 13, but less 18, print "You are a teenager."
    • Otherwise, print "You are old."

    In addition, create an instance function called yearPasses() that increases the age of the person instance by one.

    Much of the structure of the code is given to you below, but in the future, you will write this. The code that will create instances of your Person class is in the main function. You may not understand it all yet, but take a look just to see what's going on. Do not change any of the variable names or remove any of the code given.

    Input Format

    <g class="gr_ gr_63 gr-alert gr_gramm undefined Grammar multiReplace" data-gr-id="63" id="63">First</g> line contains T, <g class="gr_ gr_62 gr-alert gr_gramm undefined Grammar only-ins doubleReplace replaceWithoutSep" data-gr-id="62" id="62">number</g> of test cases. Each test case contains an integer age, representing <g class="gr_ gr_61 gr-alert gr_gramm undefined Grammar only-ins doubleReplace replaceWithoutSep" data-gr-id="61" id="61">age</g> of the person.

    Constraints 
    1T4 
    5age30

    Output Format

    The code that will test your methods is already in the editor. All you have to do is edit the methods given to you in the editor so that they perform correctly as stated above. If your methods are implemented correctly, each <g class="gr_ gr_67 gr-alert gr_spell undefined ContextualSpelling ins-del multiReplace" data-gr-id="67" id="67">testcase</g> will print out either two or three lines.

    If the age is less than zero, then your program should print out:

    This person is not valid, setting age to 0.
    You are young.
    You are young.
    

    If the age is equal or greater than 0, then your program should print out two lines. The first line that the program prints out should be the output of amIOld() on the current age. Then, three years pass via yearPasses() and the second line the program prints should be the output of amIOld() after the time has passed.

    Sample Input

    4
    -1
    10
    16
    18
    

    Sample Output

    This person is not valid, setting age to 0.
    You are young.
    You are young.
    
    You are young.
    You are a teenager.
    
    You are a teenager.
    You are old.
    
    You are old.
    You are old.
    

    Explanation

    For the first <g class="gr_ gr_70 gr-alert gr_spell undefined ContextualSpelling ins-del multiReplace" data-gr-id="70" id="70">testcase</g>, the age is less than 0 so we set the age to 0.Three years pass and the age is 3. So we print out:

    This person is not valid, setting age to 0.
    You are young.
    You are young.
    

    For the second <g class="gr_ gr_71 gr-alert gr_spell undefined ContextualSpelling ins-del multiReplace" data-gr-id="71" id="71">testcase</g>, the age is 10, which is considered young according to our program. Three years pass and the age is 13. 13 is considered a 'teenager' age so we print out:

    You are young.
    You are a teenager.
    

    For the third <g class="gr_ gr_72 gr-alert gr_spell undefined ContextualSpelling ins-del multiReplace" data-gr-id="72" id="72">testcase</g>, the age is 16, which is the age of a teenager. Three years pass and the age is 19. 19 is considered an 'old' age according to our program so we print out:

    You are a teenager.
    You are old.
    

    For the last <g class="gr_ gr_73 gr-alert gr_spell undefined ContextualSpelling ins-del multiReplace" data-gr-id="73" id="73">testcase</g>, the age is 18, which is considered an old age according to our program. Three years pass and the age is 21. 21 is still considered old so we print out:

    You are old. You are old.

    class Person {
        public int age;     
    public Person(int initial_Age) {
           initial_Age=age; 
           if(initial_Age<0)
           {
               age=0;
               Console.WriteLine("This person is not valid, setting age to 0.");
           }
        }
         public void amIOld() {
          if(age<13)
              Console.WriteLine("You are young.");
             else if((age>=13) && (age<18))
                 Console.WriteLine("You are a teenager.");// Do some computations in here and print out the correct statement 
                 else
                 Console.WriteLine("You are old.");
         }

         public void yearPasses() {
            age=age+1;// Increment the age of the person in here
         }

    static void Main(String[] args) {
            int T=int.Parse(Console.In.ReadLine());
            for (int i = 0; i < T; i++) {
                int age=int.Parse(Console.In.ReadLine());
                Person p=new Person(age);
                 p.amIOld();
                    for (int j = 0; j < 3; j++) {
                      p.yearPasses();
                    }
                    p.amIOld();
                    Console.WriteLine();
            }
        }
    }



    0 Answers

    Sorry, your answer is too short !

  • Issue#6132: Unity - particle collision 2d never stop colliding, help need to solve this issue

    hi, i'm working on a 2d game and i'm using the new particle collision 2d available in the new unity 5.3.1 (i'm using patch 1), my particle is colliding in the right way with my player character, but after the first collision, the particle remain colliding, don't know why, this is the code that i'm using to detect the collision: Code (csharp):     public int[] DamageAmount = new int[3];   public float[] RestoreTime = new float[3];     private PlayerHealth PlayerScript;   private bool bBurned = false;... particle collision 2d never stop colliding, help need to solve this issue

  • Issue#10329: HP - Problem in connecting and making work the Fax line

    We are having a problem fetting our FAX line to work after disconnecting from previous printer we used now replaced by the Officejet Pro.Any suggestions

  • Issue#11481: Android - Issue/problem with MetroPCS music unlimited

    Hi Androidforums, is anyone else experiencing an issue with music unlimited, whenever they use up their data high speed data, music services such as spotify and iheartradio seem to stall as well? I am currently on the $40 dollar plan, and have a phone that I used prior with T-Mobile. T-Mobiles... Issue/problem with MetroPCS music unlimited

  • Issue#13599: Giffgaff - getting badly narked off as cant get any answers to the issue im trying to solve. need th

    Lost phone, cancelled. got virgin sim n cheap crappy phone. got giff gaff sim other day and put 10 on it. sim faulty, got new phone today (unlocked and ready) put 10 voucher on it - still cant use it. thats 20 ive put on 2 sims and cant get calling, i want to know if a)when new sim activated how do i pass the other 10 pound on faulty sim over.Im not getting any answers and need my phone so badly.ive been delighted with giff gaff but now there are problems I cant seem to find how to resolve them saer

  • Issue#17326: I need a sherlock to solve my issue. AMD 290x

     " So this is a thing that's been happening since I installed my 290x since..."

  • Issue#19547: Geforce - Driver/ Surround Problem/ Issue

    Hello, since the update yesterday I have been unable to use Nvidea Surround. I get the message Display connection error when I click on apply. The window I get is broken, and I have been through the steps of uninstalling, reinstalling, clean install, checking all my monitors are plugged into the correct ports. I am running SLI and the connection guide is useless. Please can you assist me.

  • Issue#21473: Linux - No windows driver for printer. Can raspberry pi solve the problem?

    We have a good (old) printer but the new microsoft os doesn't support the printer. Would a raspberry pi print server with the printer connected solve this problem? I'll pursue the project if the lack of microsoft drivers is not a stumbling block. TIA

  • Issue#25857: [MRT] now say must solve the problem in engineer way

    When no problem, first to go is engineer. When got problem, push all to engineer. Ch33 by3. FARK U

  • Issue#28402: Ubnt - How do you solve the https redirect problem when using a captive portal?

    This is public access wireless system so after you connect you're redirected to the ToS page so you can accept. If the wireless clients original destination page was vanilla http it's all good however If their original destination was an https page then it fails. Chrome throws an error about HSTS and IE stops because of an untrusted certificate. My portal page is http although I certainly can redirect to https if necessary. Is there a fix for this problem?

  • Issue#45004: Unity - if problem no one can solve it

    Hello guys no body can't solve my problem so i created this video to explain it and i w'd like to make it more Clear After watching the video i want to say that : i want to move the object Randomly so i need the condition to be int or boolean and as you can see in the video it is give me this bug that i don't understand it !

  • Issue#47597: After Effects - Solve my problem

    When i want to import still image(png, jpeg ,tiff) in After Effect CS6 (Mac) then i see this error "after effects error: the file format module could not parse the file 45 35" Please anybody Solve my problem.

  • Issue#47870: Can you solve this issue with mac-authentication and do1x authentication?

    We are using Brocade ICX 7450 switches, the scenario is, for example there is a port eth 1/1/1, 1. 1. if a known system is connected to it, it will be authenticated by mac-authentication and dot1x both and will gain full access. 2. if an ip phone is connected to it, phones should be bypassed from both the authentications, and should move to a particular vlan, say vlan 100. 3. if an unknown system is connected to the same port, it should bypass both the authentications like ipphones did but should move to a restricted vlan which should not be vlan 100 (where ip phones are moved). where it will have restricted access. I am confused and stuck on the point 2 and 3, how can we define two different restricted vlans? thanks! Umair Khan

  • Issue#61520: Sony - After I log in my laptop, the screen become completely black. How could I solve this problem?

    After I log in my laptop, the screen become completely black. How could I solve this problem?

  • Issue#62093: Playstation - Help us solve the dark/black PS3 screen issue

    This issue takes the form of most of the screen becoming black or very dark since the 4.02 patch on PS3.   Would you please help us nail down the details by answering a couple of questions in this thread so we can find the cause?   Are you experiencing this on a PS3? (If you have PS3 that still works fine, please let us know and still fill in the rest) What version of PS3 - is it the Regular, Slim or Superslim (or any other special version)? Did the game work for you before, or are you a first time user? What resolution are you using? (system settings, not in game settings) Thank you all for helping us by reporting your details! We're doing all we can to solve it as fast as possible.

  • Issue#62698: Qlik - Class() Data Issue

    As you can see, it seems to be counting REQUEST_IDs that are not within the Business Days Turn Around Time indicated in the class. For example, I would expect to see 16 REQUEST_IDs in Close Out for more than 120 days in the bottom table, but in reality there only appear to be 6. How do I get both charts to reflect the correct counts? 

  • Issue#69338: EA - How can i solve this problem on fut 16

    error connecting to fifa 16 ultimate team !!!! Would u please check my id out? Thxs anywah

  • Issue#80302: Solve charging issue Parrot ZIK 2.0

    Everyone - if your ZIK 2.0 won't allow you to charge the battery via the USB cable anymore here's a solution to the issue. I stumbled across it by accident and not even customer service suggested it:remove battery from headphoneplug headphone into laptop via USBturn headphone on (white light on button)put battery back into headphone (red light flickering)move USB cable from laptop to e.g. iPhone charger USB plugred light fades in/out - battery's chargingIf it works for you as well: congrats, you just spared yourself a new battery pack (which was recommended to me)

  • Issue#86286: Unity - I dont know how to solve this [noob problem]

    Code (CSharp): public class shooting 2 : MonoBehaviour {     public GameObject projectile;     public  speed ;       // Update is called once per frame     void Update(){             }     public void shoot()     {         instantiatedProjectile = Instantiate(projectile, transform.position, transform.rotation);         instantiatedProjectile.velocity = transform.TransformDirection(new Vector3(0, 0, speed));         Destroy(instantiatedProjectile, 3);     } } It is suposed to shot... I dont know how to solve this [noob problem]

  • Issue#89601: Spotify - How to solve external sound card problem?

    I just installed Spotify to my computer. Before I am sure the external audio sound card with jack worked, but when I started to listen to music it suddenly stopped after 10 seconds and I cant make it work. I've already reinstalled the sound card driver and tried rebooting, choosing different USB ports but none of them worked. Any idea what the program made with my computer?

  • Issue#93339: EA - What is the issue with World Class Solitaire?

    What is the issue with World Class Solitaire?  I've done all of the suggested fixes - cleared TIF, updated Java and it still gives me the "Cripes" screen right as it gets ready to load.  What's going on and why can't the game load?

  • Issue#107393: Paypal - So LINK actually solve problem with required US bank account in Europe ?

    Can anyone confirm this ? http://www.paypal.com/WDfunds It's mentioned in couple posts, everything started from one person then couple more confirmed then withdraw was completed but my concern is are we allowed to do this ? If they are working on something on their website/security this can make things only a bit more complicated.  They do not respond to me so that's why I'm asking here.

  • Issue#118935: Problem making iPhone backup with iTunes

    iPhone 6s - latest iOS. I can't seem to make a complete system backup of my phone. It will begin ok, but after a while I get a message window saying that there is a problem and that OSX can't do it. Any thoughts?

  • Issue#119482: Acer - Windows 7 to 10 update on my aspire 4741 failed. Any one solve this issue?

    After download and completion of 1st stage of installation after reboot blue screen appear with message that "a require file missing or contain error". Tried many time and get same error.Current OS is Windows 7 64bit

  • Issue#139230: Error 213:10 on windows 10. Please help to solve the problem

    Error 213:10 on windows 10. Please help to solve the problem

  • Issue#148794: Im about to solve everyones turret problem.

    Everyone has been complaining about the turret issue and how it can be used to bait you into going rogue. Ready for this super easy solution!!!!!????? Just hit the turret ability button again after its deplyed and it destroys the turret. Your Welcome lol

  • Issue#150495: Linux - LXer: Top 5: Open hardware farming, issue tracking tools, music making, and more

    Published at LXer: In this week's Top 5 articles on Opensource.com, we highlight low-cost, DIY, open hardware farming equipment; open source issue tracking tools; free and open source music making programs; a look inside the Secret Lab hackathon; and a new column on the site about how to build a business with open source. Read More...

  • Issue#150802: Solve Laptop HANG problem

    For the past month I have been plagued with my ASUS laptop HANGING suddenly on me Below is post copied from another 'Gaming Mouse' thread here Guess will have better response in my own thread instead I DON'T game (at most just play some free casino slot games) .. but recently have been getting almost DAILY Hanging Problems on my Asus laptop - due to wireless MOUSE suddenly 'hanging' the cursor/arrow etc .. using few-years-old Logitech M215 as well as a 2-month-old made-in-Singapore mouse [I have 'retired' 2 previous made-in-China 'flat' type mouse after they stopped working when dropped accidentally] - ALL also now give this DAILY 'hang problem' sighzzzz...... Initially I thought my laptop really Gone Case liao because kena Auto-Repair so many times Now I've learnt a trick - don't "force-close" anymore [initially thought No Choice since laptops don't seem to have the previous "Alt-ctrl-delete" method of shutting down anymore...???? or something else ????]

  • Issue#150994: Opening crate issue & a Camera problem

    Going up to a box to loot it and I get stuck in a twitchy state as my character tries and tries again to center himself before going through the animation. It also did this in the closed beta as well, its done it to me with my stash, its also done it to me with the computer keyboard you activate for Faye Lau in the first medical mission. Here's a clip of it https://www.youtube.com/watch?v=FPs14hcE4cU I've found that if I let up on square and push and hold it again, it normally corrects itself. But why should I have to do this just to open something? It should be seamless. The second issue i'm not sure if its a bug, but I do find it extremely annoying. When there's an object behind you (for example a taxi) and I am aiming down the sights of a weapon. If I back up against the taxi, it swaps which shoulder I'm looking over automatically. Why? it's done it to me several times. I understand the times I back up and my character vanishes as the camera is going through me. But why does

  • Issue#163693: Turret/Incindiary issue making me go rogue

    Came across a few times where a player not in my group would help me up and my turret would open fire on that person turning me rogue. Same as using a incindiary grenade and then a player running through flames would turn me rogue. Alot of accidental rogue happenings caused by other players actions.