Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*Write a class of COMPASS member.
- Attributes: name, member ID, gender and IC no.
- use default constructor with no parameter
- use mutator that set all variables
- write all the accessor
- write a toString() method
- write another method to check age is 20 or greater and return true. otherwise return false
- In the main program, ask for data input from user. Display each data.
- If the user are 20 years old or greater and a male, display "You can play games in the Lab.".
- otherwise, display "You can't play games in the Lab."
- */
- import javax.swing.*;
- public class COMPASSDataInput{
- public static void main(String[] args){
- COMPASSMember Member = new COMPASSMember(); // constructor - > DONT FORGET. if normal construct, must after INPUT
- String name,ID,gender,IC;
- name = JOptionPane.showInputDialog(null,"Enter your name.");
- ID = JOptionPane.showInputDialog(null,"Enter your Member ID.");
- gender = JOptionPane.showInputDialog(null,"Enter your gender[male/female].");
- IC = JOptionPane.showInputDialog(null,"Enter your IC no[990101130101].");
- Member.setData(name,ID,gender,IC);
- JOptionPane.showMessageDialog(null,Member);
- //System.out.println(Member.getAge());
- if ((Member.getGender()).equalsIgnoreCase("Male")){
- if (Member.checkAge20())
- JOptionPane.showMessageDialog(null,"You can play games in the Lab.");
- }
- else
- JOptionPane.showMessageDialog(null,"You can NOT play games in the Lab.");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement