SlideShare a Scribd company logo
1 of 8
Download to read offline
Assignment #4 will be the construction of 2 new classes and a driver program/class (the
class containing a main method).You are required, but not limited, to turn in the following
source files:
Assignment4.java (I have pasted this at the end of the assignment)
Pet.java
BirthInfo.java
BirthInfo class
The BirthInfo class describes information of the birth of a pet. It has following attributes:
Attribute name Attribute type Description
date int The date of the birth
month int The month of the birth
year int The year of the birth
place String The place of departure or arrival
The default value of date, month, and year is 0 and the default for place is "?". Provide a
constructor to set these default values.
public BirthInfo()
The following accessor methods should be provided to get the attributes:
public int getDate()
public int getMonth()
public int getYear()
public String getPlace()
The following modifier(mutator) methods should be provided to set the attributes:
public void setDate(int date1)
public void setMonth(int month1)
public void setYear(int year1)
public void setPlace(String place1)
The following method must be defined:
public String toString()
toString method should return a string of the following format:
Date 4/Month 7/Year 2006/Place BeverlyHills
where "4" is a date, "7" is a month, "2006" is a year, and "BeverlyHills" is a place. So you
need to insert "/", "Data", "Month", "Year", and "Place" in between these variables.
Pet class
The Pet class describes a pet that an owner can have. It has the following attributes:
Attribute name Attribute type Description
petName String The name of a pet.
type String The pet type
birth BirthInfo The birth information of a pet
The default value of strings is "?". Provide a constructor to set these default values.
public Pet()
The following accessor methods should be provided to get the attributes:
public String getPetName()
public String getType()
public BirthInfo getBirthInfo()
The following modifier(mutator) methods should be provided to change the attributes:
public void setPetName(String pName)
public void setType(String pType)
public void setBirthInfo(int date, int month, int year, String place)
The following method must be defined:
public String toString()
The toString() method constructs a string of the following format:
nPet Name:ttChloen
Type:tttChihuahuaDogn
Birth Information:tDate 4/Month 7/Year 2006/Place BeverlyHillsnn
Assignment4
(Note that this part is already done in the Assignment4.java file that is given to you. This
explains each functionality of this class.)
In this assignment, download Assignment4.java file by clicking the link, and use it for your
assignment. You do not need to change Assignment4.java file. You only need to write
Pet.java and BirthInfo.java files.
The following is the description of Assignment4 class.
The driver program will allow the user to interact with your other class modules. The
purpose of this module is to handle all user input and screen output. The main method
should start by displaying the following menu in this exact format:
ChoicettActionn
------tt------n
AttAdd Petn
DttDisplay Petn
QttQuitn
?ttDisplay Helpnn
Next, the following prompt should be displayed:
What action would you like to perform?n
Read in the user input and execute the appropriate command. After the execution of each
command, re-display the prompt. Commands should be accepted in both lowercase and
uppercase.
Add Pet
Your program should display the following prompt:
Please enter the pet information:n
Enter a pet name:n
Read in the user input and set the pet name on the pet object. Then the following prompt:
Enter its type:n
Read in the user input and set the pet type on the pet object. Then the following prompt:
Enter its birth date:n
Read in the user input. Then the following prompt:
Enter its birth month:n
Read in the user input. Then the following prompt:
Enter its birth year:n
Read in the user input. Then the following prompt:
Enter its birth place:n
Read in the user input and set the birth date, month, year, and place on the pet object. Then
the following prompt:
Note that there is only one Pet object in this assignment. Thus when "Add Pet" option is
selected more than once, the new one overwrites the old Pet object information.
Display Pet
Your program should display the pet information in the following format:
nPet Name:ttChloen
Type:tttChihuahuaDogn
Birth Information:tDate 4/Month 7/Year 2006/Place BeverlyHillsnn
Make use of the toString method of the Pet class to display this information. The toString
method is used together with System.out.print method.
(System.out is NOT to be used within the toString method.)
Quit
Your program should stop executing and output nothing.
Display Help
Your program should redisplay the "choice action" menu.
Invalid Command
If an invalid command is entered, display the following line:
Unknown actionn
Input
The following files are the test cases that will be used as input for your program (Right-
click and use "Save As"):
Test Case #1
Test Case #2
Test Case #3
Test Case #4
Output
The following files are the expected outputs of the corresponding input files from the
previous section (Right-click and use "Save As"):
Test Case #1
Test Case #2
Test Case #3
Test Case #4
hw4testcases.jar All test case files are in this file. To extract each file:
jar xf hw4testcases.jar
Error Handling
Your program is expected to be robust to handle four test cases.
Here is assignment 4:
// Assignment #: 4
// Name: Your name
// StudentID: Your ID
// Lecture: Your section
// Description: Assignment 4 class displays a menu of choices to a user
// and performs the chosen task. It will keep asking a user to
// enter the next choice until the choice of 'Q' (Quit) is entered.
import java.io.*; //to use InputStreamReader and BufferedReader
import java.util.*;
public class Assignment4
{
public static void main (String[] args)
{
// local variables, can be accessed anywhere from the main method
char input1 = 'Z';
String inputInfo;
String name, type, place;
int date, month, year;
String line = new String();
// instantiate a Pet object
Pet pet1 = new Pet();
printMenu();
//Create a Scanner object to read user input
Scanner scan = new Scanner(System.in);
do // will ask for user input
{
System.out.println("What action would you like to perform?");
line = scan.nextLine();
if (line.length() == 1)
{
input1 = line.charAt(0);
input1 = Character.toUpperCase(input1);
// matches one of the case statement
switch (input1)
{
case 'A': //Add Pet
System.out.print("Please enter the pet information:n");
System.out.print("Enter a pet name:n");
name = scan.nextLine();
pet1.setPetName(name);
System.out.print("Enter its type:n");
type = scan.nextLine();
pet1.setType(type);
System.out.print("Enter its birth date:n");
date = Integer.parseInt(scan.nextLine());
System.out.print("Enter its birth month:n");
month = Integer.parseInt(scan.nextLine());
System.out.print("Enter its birth year:n");
year = Integer.parseInt(scan.nextLine());
System.out.print("Enter its birth place:n");
place = scan.nextLine();
pet1.setBirthInfo(date, month, year, place);
break;
case 'D': //Display course
System.out.print(pet1);
break;
case 'Q': //Quit
break;
case '?': //Display Menu
printMenu();
break;
default:
System.out.print("Unknown actionn");
break;
}
}
else
{
System.out.print("Unknown actionn");
}
} while (input1 != 'Q' || line.length() != 1);
}
/** The method printMenu displays the menu to a user **/
public static void printMenu()
{
System.out.print("ChoicettActionn" +
"------tt------n" +
"AttAdd Petn" +
"DttDisplay Petn" +
"QttQuitn" +
"?ttDisplay Helpnn");
}
}
Build Pet and BirthInfo Classes

More Related Content

What's hot

Lecture 4 - Object Interaction and Collections
Lecture 4 - Object Interaction and CollectionsLecture 4 - Object Interaction and Collections
Lecture 4 - Object Interaction and CollectionsSyed Afaq Shah MACS CP
 
Basics of Object Oriented Programming in Python
Basics of Object Oriented Programming in PythonBasics of Object Oriented Programming in Python
Basics of Object Oriented Programming in PythonSujith Kumar
 
Booa8 Slide 02
Booa8 Slide 02Booa8 Slide 02
Booa8 Slide 02oswchavez
 
1 1 5 Clases
1 1 5 Clases1 1 5 Clases
1 1 5 ClasesUVM
 
Inheritance in C++
Inheritance in C++Inheritance in C++
Inheritance in C++RAJ KUMAR
 
Doctrator Symfony Live 2011 Paris
Doctrator Symfony Live 2011 ParisDoctrator Symfony Live 2011 Paris
Doctrator Symfony Live 2011 Parispablodip
 
Object Oriented Programming in Python
Object Oriented Programming in PythonObject Oriented Programming in Python
Object Oriented Programming in PythonSujith Kumar
 
Chap4 oop class (php) part 1
Chap4 oop class (php) part 1Chap4 oop class (php) part 1
Chap4 oop class (php) part 1monikadeshmane
 

What's hot (13)

Lecture 4 - Object Interaction and Collections
Lecture 4 - Object Interaction and CollectionsLecture 4 - Object Interaction and Collections
Lecture 4 - Object Interaction and Collections
 
PHP OOP
PHP OOPPHP OOP
PHP OOP
 
Basics of Object Oriented Programming in Python
Basics of Object Oriented Programming in PythonBasics of Object Oriented Programming in Python
Basics of Object Oriented Programming in Python
 
Python oop third class
Python oop   third classPython oop   third class
Python oop third class
 
Booa8 Slide 02
Booa8 Slide 02Booa8 Slide 02
Booa8 Slide 02
 
1 1 5 Clases
1 1 5 Clases1 1 5 Clases
1 1 5 Clases
 
Oop concepts in python
Oop concepts in pythonOop concepts in python
Oop concepts in python
 
Inheritance in C++
Inheritance in C++Inheritance in C++
Inheritance in C++
 
inheritance
inheritanceinheritance
inheritance
 
Doctrator Symfony Live 2011 Paris
Doctrator Symfony Live 2011 ParisDoctrator Symfony Live 2011 Paris
Doctrator Symfony Live 2011 Paris
 
Object Oriented Programming in Python
Object Oriented Programming in PythonObject Oriented Programming in Python
Object Oriented Programming in Python
 
Java New Features
Java New FeaturesJava New Features
Java New Features
 
Chap4 oop class (php) part 1
Chap4 oop class (php) part 1Chap4 oop class (php) part 1
Chap4 oop class (php) part 1
 

Similar to Build Pet and BirthInfo Classes

CSE 110 - Lab 6 What this Lab Is About  Working wi.docx
CSE 110 - Lab 6 What this Lab Is About  Working wi.docxCSE 110 - Lab 6 What this Lab Is About  Working wi.docx
CSE 110 - Lab 6 What this Lab Is About  Working wi.docxfaithxdunce63732
 
Overview You are tasked with writing a program called Social Security.pdf
Overview You are tasked with writing a program called Social Security.pdfOverview You are tasked with writing a program called Social Security.pdf
Overview You are tasked with writing a program called Social Security.pdfinfo961251
 
Code to copy Person.java .pdf
Code to copy Person.java .pdfCode to copy Person.java .pdf
Code to copy Person.java .pdfanokhijew
 
Lect 1-java object-classes
Lect 1-java object-classesLect 1-java object-classes
Lect 1-java object-classesFajar Baskoro
 
Hello. Im currently working on the last section to my assignment a.pdf
Hello. Im currently working on the last section to my assignment a.pdfHello. Im currently working on the last section to my assignment a.pdf
Hello. Im currently working on the last section to my assignment a.pdfirshadkumar3
 
Lab 8 User-CF Recommender System – Part I 50 points .docx
Lab 8 User-CF Recommender System – Part I 50 points .docxLab 8 User-CF Recommender System – Part I 50 points .docx
Lab 8 User-CF Recommender System – Part I 50 points .docxsmile790243
 
Below is my program, I just have some issues when I want to check ou.pdf
Below is my program, I just have some issues when I want to check ou.pdfBelow is my program, I just have some issues when I want to check ou.pdf
Below is my program, I just have some issues when I want to check ou.pdfdhavalbl38
 
Defining classes-and-objects-1.0
Defining classes-and-objects-1.0Defining classes-and-objects-1.0
Defining classes-and-objects-1.0BG Java EE Course
 
First compile all the classes.But to run the program we have to run .pdf
First compile all the classes.But to run the program we have to run .pdfFirst compile all the classes.But to run the program we have to run .pdf
First compile all the classes.But to run the program we have to run .pdfaoneonlinestore1
 
Repeat Programming Project 2 in Chapter 5. This time, add the follow.pdf
Repeat Programming Project 2 in Chapter 5. This time, add the follow.pdfRepeat Programming Project 2 in Chapter 5. This time, add the follow.pdf
Repeat Programming Project 2 in Chapter 5. This time, add the follow.pdfarracollection
 
Implementation Your program shall contain at least the follo.pdf
Implementation Your program shall contain at least the follo.pdfImplementation Your program shall contain at least the follo.pdf
Implementation Your program shall contain at least the follo.pdfADITIEYEWEAR
 
Main issues with the following code-Im not sure if its reading the fil.pdf
Main issues with the following code-Im not sure if its reading the fil.pdfMain issues with the following code-Im not sure if its reading the fil.pdf
Main issues with the following code-Im not sure if its reading the fil.pdfaonesalem
 
Java căn bản - Chapter7
Java căn bản - Chapter7Java căn bản - Chapter7
Java căn bản - Chapter7Vince Vo
 
Chapter 7 - Defining Your Own Classes - Part II
Chapter 7 - Defining Your Own Classes - Part IIChapter 7 - Defining Your Own Classes - Part II
Chapter 7 - Defining Your Own Classes - Part IIEduardo Bergavera
 
1 INVALID & VALID PARTY & FAVOR CHOICES P.docx
1  INVALID & VALID PARTY & FAVOR CHOICES   P.docx1  INVALID & VALID PARTY & FAVOR CHOICES   P.docx
1 INVALID & VALID PARTY & FAVOR CHOICES P.docxmercysuttle
 
INTERMIDIATE PROGRAMMINGCMPSC 122LAB 9 INHERITANCE AND POLYMO.docx
INTERMIDIATE PROGRAMMINGCMPSC 122LAB 9 INHERITANCE AND POLYMO.docxINTERMIDIATE PROGRAMMINGCMPSC 122LAB 9 INHERITANCE AND POLYMO.docx
INTERMIDIATE PROGRAMMINGCMPSC 122LAB 9 INHERITANCE AND POLYMO.docxnormanibarber20063
 
Write a program that mimics the operations of several vending machin.pdf
Write a program that mimics the operations of several vending machin.pdfWrite a program that mimics the operations of several vending machin.pdf
Write a program that mimics the operations of several vending machin.pdfeyebolloptics
 

Similar to Build Pet and BirthInfo Classes (20)

CSE 110 - Lab 6 What this Lab Is About  Working wi.docx
CSE 110 - Lab 6 What this Lab Is About  Working wi.docxCSE 110 - Lab 6 What this Lab Is About  Working wi.docx
CSE 110 - Lab 6 What this Lab Is About  Working wi.docx
 
Overview You are tasked with writing a program called Social Security.pdf
Overview You are tasked with writing a program called Social Security.pdfOverview You are tasked with writing a program called Social Security.pdf
Overview You are tasked with writing a program called Social Security.pdf
 
Code to copy Person.java .pdf
Code to copy Person.java .pdfCode to copy Person.java .pdf
Code to copy Person.java .pdf
 
Lect 1-java object-classes
Lect 1-java object-classesLect 1-java object-classes
Lect 1-java object-classes
 
Hello. Im currently working on the last section to my assignment a.pdf
Hello. Im currently working on the last section to my assignment a.pdfHello. Im currently working on the last section to my assignment a.pdf
Hello. Im currently working on the last section to my assignment a.pdf
 
Lab 8 User-CF Recommender System – Part I 50 points .docx
Lab 8 User-CF Recommender System – Part I 50 points .docxLab 8 User-CF Recommender System – Part I 50 points .docx
Lab 8 User-CF Recommender System – Part I 50 points .docx
 
Below is my program, I just have some issues when I want to check ou.pdf
Below is my program, I just have some issues when I want to check ou.pdfBelow is my program, I just have some issues when I want to check ou.pdf
Below is my program, I just have some issues when I want to check ou.pdf
 
Defining classes-and-objects-1.0
Defining classes-and-objects-1.0Defining classes-and-objects-1.0
Defining classes-and-objects-1.0
 
First compile all the classes.But to run the program we have to run .pdf
First compile all the classes.But to run the program we have to run .pdfFirst compile all the classes.But to run the program we have to run .pdf
First compile all the classes.But to run the program we have to run .pdf
 
Repeat Programming Project 2 in Chapter 5. This time, add the follow.pdf
Repeat Programming Project 2 in Chapter 5. This time, add the follow.pdfRepeat Programming Project 2 in Chapter 5. This time, add the follow.pdf
Repeat Programming Project 2 in Chapter 5. This time, add the follow.pdf
 
Implementation Your program shall contain at least the follo.pdf
Implementation Your program shall contain at least the follo.pdfImplementation Your program shall contain at least the follo.pdf
Implementation Your program shall contain at least the follo.pdf
 
Main issues with the following code-Im not sure if its reading the fil.pdf
Main issues with the following code-Im not sure if its reading the fil.pdfMain issues with the following code-Im not sure if its reading the fil.pdf
Main issues with the following code-Im not sure if its reading the fil.pdf
 
Java session4
Java session4Java session4
Java session4
 
Java căn bản - Chapter7
Java căn bản - Chapter7Java căn bản - Chapter7
Java căn bản - Chapter7
 
Chapter 7 - Defining Your Own Classes - Part II
Chapter 7 - Defining Your Own Classes - Part IIChapter 7 - Defining Your Own Classes - Part II
Chapter 7 - Defining Your Own Classes - Part II
 
1 INVALID & VALID PARTY & FAVOR CHOICES P.docx
1  INVALID & VALID PARTY & FAVOR CHOICES   P.docx1  INVALID & VALID PARTY & FAVOR CHOICES   P.docx
1 INVALID & VALID PARTY & FAVOR CHOICES P.docx
 
Pj01 x-classes and objects
Pj01 x-classes and objectsPj01 x-classes and objects
Pj01 x-classes and objects
 
INTERMIDIATE PROGRAMMINGCMPSC 122LAB 9 INHERITANCE AND POLYMO.docx
INTERMIDIATE PROGRAMMINGCMPSC 122LAB 9 INHERITANCE AND POLYMO.docxINTERMIDIATE PROGRAMMINGCMPSC 122LAB 9 INHERITANCE AND POLYMO.docx
INTERMIDIATE PROGRAMMINGCMPSC 122LAB 9 INHERITANCE AND POLYMO.docx
 
Numerical data.
Numerical data.Numerical data.
Numerical data.
 
Write a program that mimics the operations of several vending machin.pdf
Write a program that mimics the operations of several vending machin.pdfWrite a program that mimics the operations of several vending machin.pdf
Write a program that mimics the operations of several vending machin.pdf
 

More from hwbloom3

Do not use arrays or any library sorting method. Declare 3String variables: s...
Do not use arrays or any library sorting method. Declare 3String variables: s...Do not use arrays or any library sorting method. Declare 3String variables: s...
Do not use arrays or any library sorting method. Declare 3String variables: s...hwbloom3
 
I accidentally installed Ask Toolbar, and it changed my Homepage,Search engin...
I accidentally installed Ask Toolbar, and it changed my Homepage,Search engin...I accidentally installed Ask Toolbar, and it changed my Homepage,Search engin...
I accidentally installed Ask Toolbar, and it changed my Homepage,Search engin...hwbloom3
 
Please show a screenshot of the code. Thank you. Solve the function F= 25x^2...
Please show a screenshot of the code. Thank you.  Solve the function F= 25x^2...Please show a screenshot of the code. Thank you.  Solve the function F= 25x^2...
Please show a screenshot of the code. Thank you. Solve the function F= 25x^2...hwbloom3
 
9.4 ?Use Warshall
9.4   ?Use Warshall9.4   ?Use Warshall
9.4 ?Use Warshallhwbloom3
 
Your company has assigned you the task of evaluating its computer networks. Y...
Your company has assigned you the task of evaluating its computer networks. Y...Your company has assigned you the task of evaluating its computer networks. Y...
Your company has assigned you the task of evaluating its computer networks. Y...hwbloom3
 
There are three sections of a class. There are 12 students in section 1. Ther...
There are three sections of a class. There are 12 students in section 1. Ther...There are three sections of a class. There are 12 students in section 1. Ther...
There are three sections of a class. There are 12 students in section 1. Ther...hwbloom3
 
Please follow the requiremen
Please follow the requiremenPlease follow the requiremen
Please follow the requiremenhwbloom3
 

More from hwbloom3 (7)

Do not use arrays or any library sorting method. Declare 3String variables: s...
Do not use arrays or any library sorting method. Declare 3String variables: s...Do not use arrays or any library sorting method. Declare 3String variables: s...
Do not use arrays or any library sorting method. Declare 3String variables: s...
 
I accidentally installed Ask Toolbar, and it changed my Homepage,Search engin...
I accidentally installed Ask Toolbar, and it changed my Homepage,Search engin...I accidentally installed Ask Toolbar, and it changed my Homepage,Search engin...
I accidentally installed Ask Toolbar, and it changed my Homepage,Search engin...
 
Please show a screenshot of the code. Thank you. Solve the function F= 25x^2...
Please show a screenshot of the code. Thank you.  Solve the function F= 25x^2...Please show a screenshot of the code. Thank you.  Solve the function F= 25x^2...
Please show a screenshot of the code. Thank you. Solve the function F= 25x^2...
 
9.4 ?Use Warshall
9.4   ?Use Warshall9.4   ?Use Warshall
9.4 ?Use Warshall
 
Your company has assigned you the task of evaluating its computer networks. Y...
Your company has assigned you the task of evaluating its computer networks. Y...Your company has assigned you the task of evaluating its computer networks. Y...
Your company has assigned you the task of evaluating its computer networks. Y...
 
There are three sections of a class. There are 12 students in section 1. Ther...
There are three sections of a class. There are 12 students in section 1. Ther...There are three sections of a class. There are 12 students in section 1. Ther...
There are three sections of a class. There are 12 students in section 1. Ther...
 
Please follow the requiremen
Please follow the requiremenPlease follow the requiremen
Please follow the requiremen
 

Recently uploaded

Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...RKavithamani
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 

Recently uploaded (20)

Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 

Build Pet and BirthInfo Classes

  • 1. Assignment #4 will be the construction of 2 new classes and a driver program/class (the class containing a main method).You are required, but not limited, to turn in the following source files: Assignment4.java (I have pasted this at the end of the assignment) Pet.java BirthInfo.java BirthInfo class The BirthInfo class describes information of the birth of a pet. It has following attributes: Attribute name Attribute type Description date int The date of the birth month int The month of the birth year int The year of the birth place String The place of departure or arrival The default value of date, month, and year is 0 and the default for place is "?". Provide a constructor to set these default values. public BirthInfo() The following accessor methods should be provided to get the attributes: public int getDate() public int getMonth() public int getYear() public String getPlace() The following modifier(mutator) methods should be provided to set the attributes: public void setDate(int date1) public void setMonth(int month1) public void setYear(int year1) public void setPlace(String place1) The following method must be defined: public String toString() toString method should return a string of the following format: Date 4/Month 7/Year 2006/Place BeverlyHills where "4" is a date, "7" is a month, "2006" is a year, and "BeverlyHills" is a place. So you need to insert "/", "Data", "Month", "Year", and "Place" in between these variables. Pet class
  • 2. The Pet class describes a pet that an owner can have. It has the following attributes: Attribute name Attribute type Description petName String The name of a pet. type String The pet type birth BirthInfo The birth information of a pet The default value of strings is "?". Provide a constructor to set these default values. public Pet() The following accessor methods should be provided to get the attributes: public String getPetName() public String getType() public BirthInfo getBirthInfo() The following modifier(mutator) methods should be provided to change the attributes: public void setPetName(String pName) public void setType(String pType) public void setBirthInfo(int date, int month, int year, String place) The following method must be defined: public String toString() The toString() method constructs a string of the following format: nPet Name:ttChloen Type:tttChihuahuaDogn Birth Information:tDate 4/Month 7/Year 2006/Place BeverlyHillsnn Assignment4 (Note that this part is already done in the Assignment4.java file that is given to you. This explains each functionality of this class.) In this assignment, download Assignment4.java file by clicking the link, and use it for your assignment. You do not need to change Assignment4.java file. You only need to write Pet.java and BirthInfo.java files. The following is the description of Assignment4 class. The driver program will allow the user to interact with your other class modules. The purpose of this module is to handle all user input and screen output. The main method
  • 3. should start by displaying the following menu in this exact format: ChoicettActionn ------tt------n AttAdd Petn DttDisplay Petn QttQuitn ?ttDisplay Helpnn Next, the following prompt should be displayed: What action would you like to perform?n Read in the user input and execute the appropriate command. After the execution of each command, re-display the prompt. Commands should be accepted in both lowercase and uppercase. Add Pet Your program should display the following prompt: Please enter the pet information:n Enter a pet name:n Read in the user input and set the pet name on the pet object. Then the following prompt: Enter its type:n Read in the user input and set the pet type on the pet object. Then the following prompt: Enter its birth date:n Read in the user input. Then the following prompt: Enter its birth month:n Read in the user input. Then the following prompt: Enter its birth year:n Read in the user input. Then the following prompt: Enter its birth place:n
  • 4. Read in the user input and set the birth date, month, year, and place on the pet object. Then the following prompt: Note that there is only one Pet object in this assignment. Thus when "Add Pet" option is selected more than once, the new one overwrites the old Pet object information. Display Pet Your program should display the pet information in the following format: nPet Name:ttChloen Type:tttChihuahuaDogn Birth Information:tDate 4/Month 7/Year 2006/Place BeverlyHillsnn Make use of the toString method of the Pet class to display this information. The toString method is used together with System.out.print method. (System.out is NOT to be used within the toString method.) Quit Your program should stop executing and output nothing. Display Help Your program should redisplay the "choice action" menu. Invalid Command If an invalid command is entered, display the following line: Unknown actionn Input The following files are the test cases that will be used as input for your program (Right- click and use "Save As"): Test Case #1 Test Case #2 Test Case #3 Test Case #4
  • 5. Output The following files are the expected outputs of the corresponding input files from the previous section (Right-click and use "Save As"): Test Case #1 Test Case #2 Test Case #3 Test Case #4 hw4testcases.jar All test case files are in this file. To extract each file: jar xf hw4testcases.jar Error Handling Your program is expected to be robust to handle four test cases. Here is assignment 4: // Assignment #: 4 // Name: Your name // StudentID: Your ID // Lecture: Your section // Description: Assignment 4 class displays a menu of choices to a user // and performs the chosen task. It will keep asking a user to // enter the next choice until the choice of 'Q' (Quit) is entered. import java.io.*; //to use InputStreamReader and BufferedReader import java.util.*; public class Assignment4 { public static void main (String[] args) { // local variables, can be accessed anywhere from the main method char input1 = 'Z'; String inputInfo; String name, type, place; int date, month, year; String line = new String(); // instantiate a Pet object
  • 6. Pet pet1 = new Pet(); printMenu(); //Create a Scanner object to read user input Scanner scan = new Scanner(System.in); do // will ask for user input { System.out.println("What action would you like to perform?"); line = scan.nextLine(); if (line.length() == 1) { input1 = line.charAt(0); input1 = Character.toUpperCase(input1); // matches one of the case statement switch (input1) { case 'A': //Add Pet System.out.print("Please enter the pet information:n"); System.out.print("Enter a pet name:n"); name = scan.nextLine(); pet1.setPetName(name); System.out.print("Enter its type:n"); type = scan.nextLine(); pet1.setType(type); System.out.print("Enter its birth date:n"); date = Integer.parseInt(scan.nextLine()); System.out.print("Enter its birth month:n"); month = Integer.parseInt(scan.nextLine()); System.out.print("Enter its birth year:n"); year = Integer.parseInt(scan.nextLine()); System.out.print("Enter its birth place:n"); place = scan.nextLine(); pet1.setBirthInfo(date, month, year, place); break; case 'D': //Display course
  • 7. System.out.print(pet1); break; case 'Q': //Quit break; case '?': //Display Menu printMenu(); break; default: System.out.print("Unknown actionn"); break; } } else { System.out.print("Unknown actionn"); } } while (input1 != 'Q' || line.length() != 1); } /** The method printMenu displays the menu to a user **/ public static void printMenu() { System.out.print("ChoicettActionn" + "------tt------n" + "AttAdd Petn" + "DttDisplay Petn" + "QttQuitn" + "?ttDisplay Helpnn"); } }