Ex6bConstructor

Ex6bConstructor - StudentInfo This class holds the information for a single student shows the use of a constructor public class StudentInfo cfw

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
/* StudentInfo * * This class holds the information for a single student. This example * shows the use of a constructor */ public class StudentInfo { String name , address, phone; int permNo; // the constructor has the same name as the class. // This is called when new is called. public StudentInfo(Scanner input) { System.out.print("Please enter student name: "); name = input.nextLine(); // read info System.out.print("Enter permanent number: "); permNo = input.nextInt(); input.nextLine(); // advance past carriage-return System.out.print("Enter address: "); address = readInfo.nextLine(); // read info System.out.print("Enter phone number: "); phone = readInfo.nextLine(); // read info } // Mutators – set methods public void setName(String n) { name = n; } public void setAddress(String a) { address = a; } public void setPhone(String p) { phone = p; } public void setPermNo(int p) { permNo = p;} // Accessors – get methods public String getName() { return name;} public String getAddress()
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 12/27/2011 for the course CMPSC 5 taught by Professor Franklin during the Fall '09 term at UCSB.

Page1 / 2

Ex6bConstructor - StudentInfo This class holds the information for a single student shows the use of a constructor public class StudentInfo cfw

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online