Object-oriented _ purchase tickets

Source: Internet
Author: User

 Packageexercise;ImportJava.util.Scanner; Public classExe4_ticket_type { Public Static voidMain (string[] args) {//TODO auto-generated Method StubScanner input =NewScanner (system.in); System.out.println ("Please enter the total number of votes"); intTicket =Input.nextint ();  for(inti = 0; I < ticket; i++) {System.out.println ("Please enter your name:"); String name1=Input.next (); if(Name1.equals ("n") {System.out.println ("Exit program");  Break; } System.out.println ("Please enter your Age:"); intAge1 =Input.nextint (); Exe4_ticket Zhangsan=NewExe4_ticket ();        Zhangsan.tic (NAME1,AGE1);    } input.close (); }}
 Packageexercise; Public classexe4_ticket {String name; intAge ; /*Public void Nam (String name) {if (Name.equals ("n")) {System.out.println ("exit program");        Return }    }*/     Public voidTic (String name,intAge ) {        if(Age <= 5) {System.out.println (name+ "The Age is:" +age+ ", Ticket free"); }        Else{System.out.println (name+ "The Age is:" +age+ ", ticket price: 20 Yuan"); }    }        //constructor Function    /*Public Exe4_ticket () {} public Exe4_ticket (String name, int age) {this.name = name;    This.age = age; }*/}

Object-oriented _ purchase tickets

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.