SlideShare a Scribd company logo
// MonsterAttack.java
public class MonsterAttack {
int id;
int day, month, year;
String nameOfMonster;
String location;
int numOfVictims;
public MonsterAttack(int id, String date, String nameOfMonster, String location, int
numOfVictims) {
String arr[] = date.split("/");
this.id = id;
this.day = Integer.parseInt(arr[1]);
this.month = Integer.parseInt(arr[0]);
this.year = Integer.parseInt(arr[2]);
this.nameOfMonster = nameOfMonster;
this.location = location;
this.numOfVictims = numOfVictims;
}
int getId() {
return id;
}
void setId(int id) {
this.id = id;
}
String getNameOfMonster() {
return nameOfMonster;
}
void setNameOfMonster(String nameOfMonster) {
this.nameOfMonster = nameOfMonster;
}
String getLocation() {
return location;
}
void setLocation(String location) {
this.location = location;
}
int getNumOfVictims() {
return numOfVictims;
}
void setNumOfVictims(int numOfVictims) {
this.numOfVictims = numOfVictims;
}
String getDate(){
return month + "/" + day + "/" + year;
}
void setDate(String date){
String arr[] = date.split("/");
this.day = Integer.parseInt(arr[1]);
this.month = Integer.parseInt(arr[0]);
this.year = Integer.parseInt(arr[2]);
}
public String toString(){
return "Attack # " + id + "occurred on " + getDate() + ". " + nameOfMonster +
"attacked " + location + ", resulting in " + numOfVictims + " tragic fatalities.";
}
}
// AttackMonitor.java
import java.util.ArrayList;
import javax.swing.JOptionPane;
public class AttackMonitor{
ArrayList attacks = new ArrayList();
void input(){
String nameOfMonster, location, date;
int id, numOfVictims;
nameOfMonster = JOptionPane.showInputDialog("Enter the name of the monster");
location = JOptionPane.showInputDialog("Enter the location of attack");
date = JOptionPane.showInputDialog("Enter the date of attack");
id = Integer.parseInt(JOptionPane.showInputDialog("Enter the id of attack"));
numOfVictims = Integer.parseInt(JOptionPane.showInputDialog("Enter the number of
victims"));
MonsterAttack temp = new MonsterAttack(id, date, nameOfMonster, location,
numOfVictims);
attacks.add(temp);
}
void display(){
for(int i = 0; i < attacks.size(); i++){
System.out.println(attacks.get(i));
}
}
void delete(){
display();
int id = Integer.parseInt(JOptionPane.showInputDialog("Enter the id of attack to delete"));
int i;
for(i = 0; i < attacks.size(); i++){
if(attacks.get(i).getId() == id){
break;
}
}
if(i != attacks.size()) attacks.remove(i);
}
void monitor(){
int choice = Integer.parseInt(JOptionPane.showInputDialog("Enter 1 for adding new
attack, 2 for displaying attacks, 3 for deleting an attack, any other number to exit"));
switch (choice) {
case 1:
input();
break;
case 2:
display();
break;
case 3:
delete();
break;
default:
return;
}
}
}
// MonsterAttackDriver.java
Give sample input/output ot input file
Solution
// MonsterAttack.java
public class MonsterAttack {
int id;
int day, month, year;
String nameOfMonster;
String location;
int numOfVictims;
public MonsterAttack(int id, String date, String nameOfMonster, String location, int
numOfVictims) {
String arr[] = date.split("/");
this.id = id;
this.day = Integer.parseInt(arr[1]);
this.month = Integer.parseInt(arr[0]);
this.year = Integer.parseInt(arr[2]);
this.nameOfMonster = nameOfMonster;
this.location = location;
this.numOfVictims = numOfVictims;
}
int getId() {
return id;
}
void setId(int id) {
this.id = id;
}
String getNameOfMonster() {
return nameOfMonster;
}
void setNameOfMonster(String nameOfMonster) {
this.nameOfMonster = nameOfMonster;
}
String getLocation() {
return location;
}
void setLocation(String location) {
this.location = location;
}
int getNumOfVictims() {
return numOfVictims;
}
void setNumOfVictims(int numOfVictims) {
this.numOfVictims = numOfVictims;
}
String getDate(){
return month + "/" + day + "/" + year;
}
void setDate(String date){
String arr[] = date.split("/");
this.day = Integer.parseInt(arr[1]);
this.month = Integer.parseInt(arr[0]);
this.year = Integer.parseInt(arr[2]);
}
public String toString(){
return "Attack # " + id + "occurred on " + getDate() + ". " + nameOfMonster +
"attacked " + location + ", resulting in " + numOfVictims + " tragic fatalities.";
}
}
// AttackMonitor.java
import java.util.ArrayList;
import javax.swing.JOptionPane;
public class AttackMonitor{
ArrayList attacks = new ArrayList();
void input(){
String nameOfMonster, location, date;
int id, numOfVictims;
nameOfMonster = JOptionPane.showInputDialog("Enter the name of the monster");
location = JOptionPane.showInputDialog("Enter the location of attack");
date = JOptionPane.showInputDialog("Enter the date of attack");
id = Integer.parseInt(JOptionPane.showInputDialog("Enter the id of attack"));
numOfVictims = Integer.parseInt(JOptionPane.showInputDialog("Enter the number of
victims"));
MonsterAttack temp = new MonsterAttack(id, date, nameOfMonster, location,
numOfVictims);
attacks.add(temp);
}
void display(){
for(int i = 0; i < attacks.size(); i++){
System.out.println(attacks.get(i));
}
}
void delete(){
display();
int id = Integer.parseInt(JOptionPane.showInputDialog("Enter the id of attack to delete"));
int i;
for(i = 0; i < attacks.size(); i++){
if(attacks.get(i).getId() == id){
break;
}
}
if(i != attacks.size()) attacks.remove(i);
}
void monitor(){
int choice = Integer.parseInt(JOptionPane.showInputDialog("Enter 1 for adding new
attack, 2 for displaying attacks, 3 for deleting an attack, any other number to exit"));
switch (choice) {
case 1:
input();
break;
case 2:
display();
break;
case 3:
delete();
break;
default:
return;
}
}
}
// MonsterAttackDriver.java
Give sample input/output ot input file

More Related Content

More from anugrahafancy

X has +2 charge It has low first and second ioniz.pdf
                     X has +2 charge It has low first and second ioniz.pdf                     X has +2 charge It has low first and second ioniz.pdf
X has +2 charge It has low first and second ioniz.pdf
anugrahafancy
 
Valence Bond Theory According to valence band the.pdf
                     Valence Bond Theory According to valence band the.pdf                     Valence Bond Theory According to valence band the.pdf
Valence Bond Theory According to valence band the.pdf
anugrahafancy
 
total volume =25+25=50 ml total millimoles of KI=.pdf
                     total volume =25+25=50 ml total millimoles of KI=.pdf                     total volume =25+25=50 ml total millimoles of KI=.pdf
total volume =25+25=50 ml total millimoles of KI=.pdf
anugrahafancy
 
This type of deformation is irreversible. However.pdf
                     This type of deformation is irreversible. However.pdf                     This type of deformation is irreversible. However.pdf
This type of deformation is irreversible. However.pdf
anugrahafancy
 
stereoisomers .pdf
                     stereoisomers                                    .pdf                     stereoisomers                                    .pdf
stereoisomers .pdf
anugrahafancy
 
Some elements receive their respective symbol bas.pdf
                     Some elements receive their respective symbol bas.pdf                     Some elements receive their respective symbol bas.pdf
Some elements receive their respective symbol bas.pdf
anugrahafancy
 
phosphonium ylide is produced when phosphonium ha.pdf
                     phosphonium ylide is produced when phosphonium ha.pdf                     phosphonium ylide is produced when phosphonium ha.pdf
phosphonium ylide is produced when phosphonium ha.pdf
anugrahafancy
 
N1 V1 = N2 V2 50 x M1 = 1.50 x 2 x 17.7 M M1 = 1..pdf
                     N1 V1 = N2 V2 50 x M1 = 1.50 x 2 x 17.7 M M1 = 1..pdf                     N1 V1 = N2 V2 50 x M1 = 1.50 x 2 x 17.7 M M1 = 1..pdf
N1 V1 = N2 V2 50 x M1 = 1.50 x 2 x 17.7 M M1 = 1..pdf
anugrahafancy
 
In chemistry, an amphoteric species is a molecule.pdf
                     In chemistry, an amphoteric species is a molecule.pdf                     In chemistry, an amphoteric species is a molecule.pdf
In chemistry, an amphoteric species is a molecule.pdf
anugrahafancy
 
Chemistry is the science of matter, especially it.pdf
                     Chemistry is the science of matter, especially it.pdf                     Chemistry is the science of matter, especially it.pdf
Chemistry is the science of matter, especially it.pdf
anugrahafancy
 
Before this confederates began their general advance, General Lee pl.pdf
Before this confederates began their general advance, General Lee pl.pdfBefore this confederates began their general advance, General Lee pl.pdf
Before this confederates began their general advance, General Lee pl.pdf
anugrahafancy
 
An understanding of periodic trends is important .pdf
                     An understanding of periodic trends is important .pdf                     An understanding of periodic trends is important .pdf
An understanding of periodic trends is important .pdf
anugrahafancy
 
Acid contains hydrogen ions. Thus, iodate will re.pdf
                     Acid contains hydrogen ions. Thus, iodate will re.pdf                     Acid contains hydrogen ions. Thus, iodate will re.pdf
Acid contains hydrogen ions. Thus, iodate will re.pdf
anugrahafancy
 
There is a difference between to connect to a network and to communi.pdf
There is a difference between to connect to a network and to communi.pdfThere is a difference between to connect to a network and to communi.pdf
There is a difference between to connect to a network and to communi.pdf
anugrahafancy
 
The picture is not uploaded properly it is corrupted. please upload .pdf
The picture is not uploaded properly it is corrupted. please upload .pdfThe picture is not uploaded properly it is corrupted. please upload .pdf
The picture is not uploaded properly it is corrupted. please upload .pdf
anugrahafancy
 
No clarity in question . Not visibleSolutionNo clarity in ques.pdf
No clarity in question . Not visibleSolutionNo clarity in ques.pdfNo clarity in question . Not visibleSolutionNo clarity in ques.pdf
No clarity in question . Not visibleSolutionNo clarity in ques.pdf
anugrahafancy
 
Date Account title Debit credit jan 30 cash 45000 common sto.pdf
    Date Account title Debit credit   jan 30 cash 45000     common sto.pdf    Date Account title Debit credit   jan 30 cash 45000     common sto.pdf
Date Account title Debit credit jan 30 cash 45000 common sto.pdf
anugrahafancy
 
Initial Value=2.5Drift rate per annum=0.4Variance rate per annum.pdf
Initial Value=2.5Drift rate per annum=0.4Variance rate per annum.pdfInitial Value=2.5Drift rate per annum=0.4Variance rate per annum.pdf
Initial Value=2.5Drift rate per annum=0.4Variance rate per annum.pdf
anugrahafancy
 
IntroductionDarwin argused that living organisms evolved from one .pdf
IntroductionDarwin argused that living organisms evolved from one .pdfIntroductionDarwin argused that living organisms evolved from one .pdf
IntroductionDarwin argused that living organisms evolved from one .pdf
anugrahafancy
 
import java.awt.LinearGradientPaint; public class searchComparis.pdf
import java.awt.LinearGradientPaint; public class searchComparis.pdfimport java.awt.LinearGradientPaint; public class searchComparis.pdf
import java.awt.LinearGradientPaint; public class searchComparis.pdf
anugrahafancy
 

More from anugrahafancy (20)

X has +2 charge It has low first and second ioniz.pdf
                     X has +2 charge It has low first and second ioniz.pdf                     X has +2 charge It has low first and second ioniz.pdf
X has +2 charge It has low first and second ioniz.pdf
 
Valence Bond Theory According to valence band the.pdf
                     Valence Bond Theory According to valence band the.pdf                     Valence Bond Theory According to valence band the.pdf
Valence Bond Theory According to valence band the.pdf
 
total volume =25+25=50 ml total millimoles of KI=.pdf
                     total volume =25+25=50 ml total millimoles of KI=.pdf                     total volume =25+25=50 ml total millimoles of KI=.pdf
total volume =25+25=50 ml total millimoles of KI=.pdf
 
This type of deformation is irreversible. However.pdf
                     This type of deformation is irreversible. However.pdf                     This type of deformation is irreversible. However.pdf
This type of deformation is irreversible. However.pdf
 
stereoisomers .pdf
                     stereoisomers                                    .pdf                     stereoisomers                                    .pdf
stereoisomers .pdf
 
Some elements receive their respective symbol bas.pdf
                     Some elements receive their respective symbol bas.pdf                     Some elements receive their respective symbol bas.pdf
Some elements receive their respective symbol bas.pdf
 
phosphonium ylide is produced when phosphonium ha.pdf
                     phosphonium ylide is produced when phosphonium ha.pdf                     phosphonium ylide is produced when phosphonium ha.pdf
phosphonium ylide is produced when phosphonium ha.pdf
 
N1 V1 = N2 V2 50 x M1 = 1.50 x 2 x 17.7 M M1 = 1..pdf
                     N1 V1 = N2 V2 50 x M1 = 1.50 x 2 x 17.7 M M1 = 1..pdf                     N1 V1 = N2 V2 50 x M1 = 1.50 x 2 x 17.7 M M1 = 1..pdf
N1 V1 = N2 V2 50 x M1 = 1.50 x 2 x 17.7 M M1 = 1..pdf
 
In chemistry, an amphoteric species is a molecule.pdf
                     In chemistry, an amphoteric species is a molecule.pdf                     In chemistry, an amphoteric species is a molecule.pdf
In chemistry, an amphoteric species is a molecule.pdf
 
Chemistry is the science of matter, especially it.pdf
                     Chemistry is the science of matter, especially it.pdf                     Chemistry is the science of matter, especially it.pdf
Chemistry is the science of matter, especially it.pdf
 
Before this confederates began their general advance, General Lee pl.pdf
Before this confederates began their general advance, General Lee pl.pdfBefore this confederates began their general advance, General Lee pl.pdf
Before this confederates began their general advance, General Lee pl.pdf
 
An understanding of periodic trends is important .pdf
                     An understanding of periodic trends is important .pdf                     An understanding of periodic trends is important .pdf
An understanding of periodic trends is important .pdf
 
Acid contains hydrogen ions. Thus, iodate will re.pdf
                     Acid contains hydrogen ions. Thus, iodate will re.pdf                     Acid contains hydrogen ions. Thus, iodate will re.pdf
Acid contains hydrogen ions. Thus, iodate will re.pdf
 
There is a difference between to connect to a network and to communi.pdf
There is a difference between to connect to a network and to communi.pdfThere is a difference between to connect to a network and to communi.pdf
There is a difference between to connect to a network and to communi.pdf
 
The picture is not uploaded properly it is corrupted. please upload .pdf
The picture is not uploaded properly it is corrupted. please upload .pdfThe picture is not uploaded properly it is corrupted. please upload .pdf
The picture is not uploaded properly it is corrupted. please upload .pdf
 
No clarity in question . Not visibleSolutionNo clarity in ques.pdf
No clarity in question . Not visibleSolutionNo clarity in ques.pdfNo clarity in question . Not visibleSolutionNo clarity in ques.pdf
No clarity in question . Not visibleSolutionNo clarity in ques.pdf
 
Date Account title Debit credit jan 30 cash 45000 common sto.pdf
    Date Account title Debit credit   jan 30 cash 45000     common sto.pdf    Date Account title Debit credit   jan 30 cash 45000     common sto.pdf
Date Account title Debit credit jan 30 cash 45000 common sto.pdf
 
Initial Value=2.5Drift rate per annum=0.4Variance rate per annum.pdf
Initial Value=2.5Drift rate per annum=0.4Variance rate per annum.pdfInitial Value=2.5Drift rate per annum=0.4Variance rate per annum.pdf
Initial Value=2.5Drift rate per annum=0.4Variance rate per annum.pdf
 
IntroductionDarwin argused that living organisms evolved from one .pdf
IntroductionDarwin argused that living organisms evolved from one .pdfIntroductionDarwin argused that living organisms evolved from one .pdf
IntroductionDarwin argused that living organisms evolved from one .pdf
 
import java.awt.LinearGradientPaint; public class searchComparis.pdf
import java.awt.LinearGradientPaint; public class searchComparis.pdfimport java.awt.LinearGradientPaint; public class searchComparis.pdf
import java.awt.LinearGradientPaint; public class searchComparis.pdf
 

Recently uploaded

MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdfMASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
goswamiyash170123
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
Special education needs
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
DhatriParmar
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
vaibhavrinwa19
 
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Dr. Vinod Kumar Kanvaria
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
Scholarhat
 
Best Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDABest Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDA
deeptiverma2406
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBCSTRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
kimdan468
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
Vivekanand Anglo Vedic Academy
 
Chapter -12, Antibiotics (One Page Notes).pdf
Chapter -12, Antibiotics (One Page Notes).pdfChapter -12, Antibiotics (One Page Notes).pdf
Chapter -12, Antibiotics (One Page Notes).pdf
Kartik Tiwari
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
Peter Windle
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Atul Kumar Singh
 
Advantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO PerspectiveAdvantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO Perspective
Krisztián Száraz
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
Jean Carlos Nunes Paixão
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
MysoreMuleSoftMeetup
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Thiyagu K
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 

Recently uploaded (20)

MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdfMASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
 
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
 
Best Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDABest Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDA
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBCSTRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
 
Chapter -12, Antibiotics (One Page Notes).pdf
Chapter -12, Antibiotics (One Page Notes).pdfChapter -12, Antibiotics (One Page Notes).pdf
Chapter -12, Antibiotics (One Page Notes).pdf
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
 
Advantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO PerspectiveAdvantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO Perspective
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 

MonsterAttack.javapublic class MonsterAttack {    int id;  .pdf

  • 1. // MonsterAttack.java public class MonsterAttack { int id; int day, month, year; String nameOfMonster; String location; int numOfVictims; public MonsterAttack(int id, String date, String nameOfMonster, String location, int numOfVictims) { String arr[] = date.split("/"); this.id = id; this.day = Integer.parseInt(arr[1]); this.month = Integer.parseInt(arr[0]); this.year = Integer.parseInt(arr[2]); this.nameOfMonster = nameOfMonster; this.location = location; this.numOfVictims = numOfVictims; } int getId() { return id; } void setId(int id) { this.id = id; } String getNameOfMonster() { return nameOfMonster; } void setNameOfMonster(String nameOfMonster) { this.nameOfMonster = nameOfMonster; } String getLocation() { return location; } void setLocation(String location) { this.location = location;
  • 2. } int getNumOfVictims() { return numOfVictims; } void setNumOfVictims(int numOfVictims) { this.numOfVictims = numOfVictims; } String getDate(){ return month + "/" + day + "/" + year; } void setDate(String date){ String arr[] = date.split("/"); this.day = Integer.parseInt(arr[1]); this.month = Integer.parseInt(arr[0]); this.year = Integer.parseInt(arr[2]); } public String toString(){ return "Attack # " + id + "occurred on " + getDate() + ". " + nameOfMonster + "attacked " + location + ", resulting in " + numOfVictims + " tragic fatalities."; } } // AttackMonitor.java import java.util.ArrayList; import javax.swing.JOptionPane; public class AttackMonitor{ ArrayList attacks = new ArrayList(); void input(){ String nameOfMonster, location, date; int id, numOfVictims; nameOfMonster = JOptionPane.showInputDialog("Enter the name of the monster"); location = JOptionPane.showInputDialog("Enter the location of attack"); date = JOptionPane.showInputDialog("Enter the date of attack"); id = Integer.parseInt(JOptionPane.showInputDialog("Enter the id of attack")); numOfVictims = Integer.parseInt(JOptionPane.showInputDialog("Enter the number of victims"));
  • 3. MonsterAttack temp = new MonsterAttack(id, date, nameOfMonster, location, numOfVictims); attacks.add(temp); } void display(){ for(int i = 0; i < attacks.size(); i++){ System.out.println(attacks.get(i)); } } void delete(){ display(); int id = Integer.parseInt(JOptionPane.showInputDialog("Enter the id of attack to delete")); int i; for(i = 0; i < attacks.size(); i++){ if(attacks.get(i).getId() == id){ break; } } if(i != attacks.size()) attacks.remove(i); } void monitor(){ int choice = Integer.parseInt(JOptionPane.showInputDialog("Enter 1 for adding new attack, 2 for displaying attacks, 3 for deleting an attack, any other number to exit")); switch (choice) { case 1: input(); break; case 2: display(); break; case 3: delete(); break; default: return; }
  • 4. } } // MonsterAttackDriver.java Give sample input/output ot input file Solution // MonsterAttack.java public class MonsterAttack { int id; int day, month, year; String nameOfMonster; String location; int numOfVictims; public MonsterAttack(int id, String date, String nameOfMonster, String location, int numOfVictims) { String arr[] = date.split("/"); this.id = id; this.day = Integer.parseInt(arr[1]); this.month = Integer.parseInt(arr[0]); this.year = Integer.parseInt(arr[2]); this.nameOfMonster = nameOfMonster; this.location = location; this.numOfVictims = numOfVictims; } int getId() { return id; } void setId(int id) { this.id = id; } String getNameOfMonster() { return nameOfMonster; } void setNameOfMonster(String nameOfMonster) {
  • 5. this.nameOfMonster = nameOfMonster; } String getLocation() { return location; } void setLocation(String location) { this.location = location; } int getNumOfVictims() { return numOfVictims; } void setNumOfVictims(int numOfVictims) { this.numOfVictims = numOfVictims; } String getDate(){ return month + "/" + day + "/" + year; } void setDate(String date){ String arr[] = date.split("/"); this.day = Integer.parseInt(arr[1]); this.month = Integer.parseInt(arr[0]); this.year = Integer.parseInt(arr[2]); } public String toString(){ return "Attack # " + id + "occurred on " + getDate() + ". " + nameOfMonster + "attacked " + location + ", resulting in " + numOfVictims + " tragic fatalities."; } } // AttackMonitor.java import java.util.ArrayList; import javax.swing.JOptionPane; public class AttackMonitor{ ArrayList attacks = new ArrayList(); void input(){ String nameOfMonster, location, date;
  • 6. int id, numOfVictims; nameOfMonster = JOptionPane.showInputDialog("Enter the name of the monster"); location = JOptionPane.showInputDialog("Enter the location of attack"); date = JOptionPane.showInputDialog("Enter the date of attack"); id = Integer.parseInt(JOptionPane.showInputDialog("Enter the id of attack")); numOfVictims = Integer.parseInt(JOptionPane.showInputDialog("Enter the number of victims")); MonsterAttack temp = new MonsterAttack(id, date, nameOfMonster, location, numOfVictims); attacks.add(temp); } void display(){ for(int i = 0; i < attacks.size(); i++){ System.out.println(attacks.get(i)); } } void delete(){ display(); int id = Integer.parseInt(JOptionPane.showInputDialog("Enter the id of attack to delete")); int i; for(i = 0; i < attacks.size(); i++){ if(attacks.get(i).getId() == id){ break; } } if(i != attacks.size()) attacks.remove(i); } void monitor(){ int choice = Integer.parseInt(JOptionPane.showInputDialog("Enter 1 for adding new attack, 2 for displaying attacks, 3 for deleting an attack, any other number to exit")); switch (choice) { case 1: input(); break; case 2: display();