Question

im taking java102 can someone help with this ? call it (Student Version 2) Write another...

im taking java102

can someone help with this ?

call it (Student Version 2)

Write another version of class Student that has a firstName,
lastName, id, mobilePhone and a count. Declare the count as a static
variable. The count is incremented every time an object of this class is
created. Write the default constructor, a constructor that takes
parameters: firstName, lastName, id and mobilePhone. Write a third
constructor that takes only firstName and lastName. Write the set
and get methods for your attributes. Make sure that the phone
number consists of 10 numbers and that the first name and last name
consist of more than 2 characters. Create a function that displays all
the student information and another that displays only the name.

Then write a demo program that tests the methods of your Student
class.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#source code:

import java.util.*;
import java.lang.*;
class Student{
   String firstname;
   String lastname;
   String phonenumber;
   int id;
   static int count=0;
  
   Student(){
       /*default constructor*/
  
      
   }
   Student(String fname,String lname,int id,String pnumber){
       count++;
       this.firstname=fname;
       this.lastname=lname;
       this.id=id;
       this.phonenumber=pnumber;
       if(this.firstname.length()<=2 || this.lastname.length()<=2 || this.phonenumber.length()<10 || this.phonenumber.length()>10){
           System.out.println("name lessthan 2 characters or phone number error");
       }
       else{
           display_information();
          
       }
      
   }
   Student(String fname,String lname){
       count++;
       display_names(fname,lname);
      
   }
  
   void display_information(){
       System.out.println("firstname:"+firstname+" lastname:"+lastname+" id:"+id+" phonenumber:"+phonenumber);
   }
   void display_names(String firstname,String lastname){
       System.out.println("names:"+firstname+" "+lastname);
   }
   public static void main(String args[]){
       Student s1=new Student("vishnu","namana",14,"9703850705");
       Student s2=new Student("vishnu","namana");
       Student s3=new Student("v","namana",15,"9709850705");
       Student s4=new Student("v","namana");
       Student s5=new Student("red","namana",14,"970850705");
       Student s6=new Student("red","namana");
       System.out.println("object is created:"+Student.count);

   }
}

#output:

#if you have any doubt comment below.....

Add a comment
Know the answer?
Add Answer to:
im taking java102 can someone help with this ? call it (Student Version 2) Write another...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT