SlideShare a Scribd company logo
JAVA Programming
Design a class Message that models an e-mail message. A message has a recipient, a sender, and
a message text. Support the following methods:
a. A constructor that takes the sender and recipient
b. A method append that appends a line of text to the message body
c. A method toString that makes the message into one long string like this: “From: Fname
Lname To: Some Recipient …”
Write a driver program that uses this class to make a message and print it.
Solution
MessageTest.java
import java.util.Scanner;
public class MessageTest {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.println("Enter Recipient Name: ");
String recipientName = scan.nextLine();
System.out.println("Enter Sender Name: ");
String senderName = scan.nextLine();
System.out.println("Enter the body text: ");
String text = scan.nextLine();
Message m = new Message(recipientName, senderName);
m.append(text);
System.out.println(m.toString());
}
}
Message.java
public class Message {
private String recipient;
private String sender;
private String text;
public Message(String r, String s){
this.recipient = r;
this.sender = s;
text = "";
}
public void append(String t){
text = text + t +" ";
}
public String toString(){
return "From: "+sender+"  "+text+" To: "+recipient+" ";
}
}

More Related Content

Similar to JAVA ProgrammingDesign a class Message that models an e-mail messa.pdf

3.Lesson Plan - Input.pdf.pdf
3.Lesson Plan - Input.pdf.pdf3.Lesson Plan - Input.pdf.pdf
3.Lesson Plan - Input.pdf.pdf
AbhishekSingh757567
 
An input file A1-txt is given which contains a list of integer values-.docx
An input file A1-txt is given which contains a list of integer values-.docxAn input file A1-txt is given which contains a list of integer values-.docx
An input file A1-txt is given which contains a list of integer values-.docx
lauracallander
 
Please include comments if at all possible Use a socket connection t.pdf
Please include comments if at all possible Use a socket connection t.pdfPlease include comments if at all possible Use a socket connection t.pdf
Please include comments if at all possible Use a socket connection t.pdf
fashionfootwear1
 
(java) eclipse PleaseDevelop an application that implements a pro.pdf
(java) eclipse PleaseDevelop an application that implements a pro.pdf(java) eclipse PleaseDevelop an application that implements a pro.pdf
(java) eclipse PleaseDevelop an application that implements a pro.pdf
aroraopticals15
 
Chapter 2 - Getting Started with Java
Chapter 2 - Getting Started with JavaChapter 2 - Getting Started with Java
Chapter 2 - Getting Started with Java
Eduardo Bergavera
 
Java căn bản - Chapter2
Java căn bản - Chapter2Java căn bản - Chapter2
Java căn bản - Chapter2Vince Vo
 
Text field and textarea
Text field and textareaText field and textarea
Text field and textareamyrajendra
 
Class notes(week 5) on command line arguments
Class notes(week 5) on command line argumentsClass notes(week 5) on command line arguments
Class notes(week 5) on command line arguments
Kuntal Bhowmick
 
Introduction to objective c
Introduction to objective cIntroduction to objective c
Introduction to objective cSunny Shaikh
 
Computer programming 2 chapter 1-lesson 2
Computer programming 2  chapter 1-lesson 2Computer programming 2  chapter 1-lesson 2
Computer programming 2 chapter 1-lesson 2
MLG College of Learning, Inc
 
Advanced java jee material by KV Rao sir
Advanced java jee material by KV Rao sirAdvanced java jee material by KV Rao sir
Advanced java jee material by KV Rao sir
AVINASH KUMAR
 
Handling inputs via scanner class
Handling inputs via scanner classHandling inputs via scanner class
Handling inputs via scanner class
simarsimmygrewal
 
Android development training programme , Day 3
Android development training programme , Day 3Android development training programme , Day 3
Android development training programme , Day 3
DHIRAJ PRAVIN
 
Java Basics 1.pptx
Java Basics 1.pptxJava Basics 1.pptx
Java Basics 1.pptx
TouseeqHaider11
 
compiler design
compiler designcompiler design
compiler design
Ishwor2
 
JAVA Question : Programming Assignment
JAVA Question : Programming AssignmentJAVA Question : Programming Assignment
JAVA Question : Programming Assignment
Coding Assignment Help
 
Write a Java program that opens the file, reads all the Grade from t.pdf
Write a Java program that opens the file, reads all the Grade from t.pdfWrite a Java program that opens the file, reads all the Grade from t.pdf
Write a Java program that opens the file, reads all the Grade from t.pdf
fashiionbeutycare
 
Taking User Input in Java
Taking User Input in JavaTaking User Input in Java
Taking User Input in Java
Eftakhairul Islam
 

Similar to JAVA ProgrammingDesign a class Message that models an e-mail messa.pdf (18)

3.Lesson Plan - Input.pdf.pdf
3.Lesson Plan - Input.pdf.pdf3.Lesson Plan - Input.pdf.pdf
3.Lesson Plan - Input.pdf.pdf
 
An input file A1-txt is given which contains a list of integer values-.docx
An input file A1-txt is given which contains a list of integer values-.docxAn input file A1-txt is given which contains a list of integer values-.docx
An input file A1-txt is given which contains a list of integer values-.docx
 
Please include comments if at all possible Use a socket connection t.pdf
Please include comments if at all possible Use a socket connection t.pdfPlease include comments if at all possible Use a socket connection t.pdf
Please include comments if at all possible Use a socket connection t.pdf
 
(java) eclipse PleaseDevelop an application that implements a pro.pdf
(java) eclipse PleaseDevelop an application that implements a pro.pdf(java) eclipse PleaseDevelop an application that implements a pro.pdf
(java) eclipse PleaseDevelop an application that implements a pro.pdf
 
Chapter 2 - Getting Started with Java
Chapter 2 - Getting Started with JavaChapter 2 - Getting Started with Java
Chapter 2 - Getting Started with Java
 
Java căn bản - Chapter2
Java căn bản - Chapter2Java căn bản - Chapter2
Java căn bản - Chapter2
 
Text field and textarea
Text field and textareaText field and textarea
Text field and textarea
 
Class notes(week 5) on command line arguments
Class notes(week 5) on command line argumentsClass notes(week 5) on command line arguments
Class notes(week 5) on command line arguments
 
Introduction to objective c
Introduction to objective cIntroduction to objective c
Introduction to objective c
 
Computer programming 2 chapter 1-lesson 2
Computer programming 2  chapter 1-lesson 2Computer programming 2  chapter 1-lesson 2
Computer programming 2 chapter 1-lesson 2
 
Advanced java jee material by KV Rao sir
Advanced java jee material by KV Rao sirAdvanced java jee material by KV Rao sir
Advanced java jee material by KV Rao sir
 
Handling inputs via scanner class
Handling inputs via scanner classHandling inputs via scanner class
Handling inputs via scanner class
 
Android development training programme , Day 3
Android development training programme , Day 3Android development training programme , Day 3
Android development training programme , Day 3
 
Java Basics 1.pptx
Java Basics 1.pptxJava Basics 1.pptx
Java Basics 1.pptx
 
compiler design
compiler designcompiler design
compiler design
 
JAVA Question : Programming Assignment
JAVA Question : Programming AssignmentJAVA Question : Programming Assignment
JAVA Question : Programming Assignment
 
Write a Java program that opens the file, reads all the Grade from t.pdf
Write a Java program that opens the file, reads all the Grade from t.pdfWrite a Java program that opens the file, reads all the Grade from t.pdf
Write a Java program that opens the file, reads all the Grade from t.pdf
 
Taking User Input in Java
Taking User Input in JavaTaking User Input in Java
Taking User Input in Java
 

More from connellalykshamesb60

In which of the following structures are spores formed (Select all .pdf
In which of the following structures are spores formed (Select all .pdfIn which of the following structures are spores formed (Select all .pdf
In which of the following structures are spores formed (Select all .pdf
connellalykshamesb60
 
How does Windows managestore user names and passwords How does it .pdf
How does Windows managestore user names and passwords How does it .pdfHow does Windows managestore user names and passwords How does it .pdf
How does Windows managestore user names and passwords How does it .pdf
connellalykshamesb60
 
How to use class set a function(double money(); receive a number and .pdf
How to use class set a function(double money(); receive a number and .pdfHow to use class set a function(double money(); receive a number and .pdf
How to use class set a function(double money(); receive a number and .pdf
connellalykshamesb60
 
For each of the following descriptions indicate which best describes.pdf
For each of the following descriptions indicate which best describes.pdfFor each of the following descriptions indicate which best describes.pdf
For each of the following descriptions indicate which best describes.pdf
connellalykshamesb60
 
Explain how an Annelidian differs from a MolluscanSolutionMoll.pdf
Explain how an Annelidian differs from a MolluscanSolutionMoll.pdfExplain how an Annelidian differs from a MolluscanSolutionMoll.pdf
Explain how an Annelidian differs from a MolluscanSolutionMoll.pdf
connellalykshamesb60
 
DNA s composed of nucleotides that are joined together by covalent bo.pdf
DNA s composed of nucleotides that are joined together by covalent bo.pdfDNA s composed of nucleotides that are joined together by covalent bo.pdf
DNA s composed of nucleotides that are joined together by covalent bo.pdf
connellalykshamesb60
 
Discuss some of the challenges involved in ensuring that critical kn.pdf
Discuss some of the challenges involved in ensuring that critical kn.pdfDiscuss some of the challenges involved in ensuring that critical kn.pdf
Discuss some of the challenges involved in ensuring that critical kn.pdf
connellalykshamesb60
 
Biologically, the term is synonymous with [Choose the term race. refe.pdf
Biologically, the term is synonymous with [Choose the term race. refe.pdfBiologically, the term is synonymous with [Choose the term race. refe.pdf
Biologically, the term is synonymous with [Choose the term race. refe.pdf
connellalykshamesb60
 
Anyone good with linguistics Are the following headlines transitive.pdf
Anyone good with linguistics Are the following headlines transitive.pdfAnyone good with linguistics Are the following headlines transitive.pdf
Anyone good with linguistics Are the following headlines transitive.pdf
connellalykshamesb60
 
A mother and father both have normal karyotypes. The father is color .pdf
A mother and father both have normal karyotypes. The father is color .pdfA mother and father both have normal karyotypes. The father is color .pdf
A mother and father both have normal karyotypes. The father is color .pdf
connellalykshamesb60
 
A man has a condition where all of his gametes undergo nondisjunctio.pdf
A man has a condition where all of his gametes undergo nondisjunctio.pdfA man has a condition where all of his gametes undergo nondisjunctio.pdf
A man has a condition where all of his gametes undergo nondisjunctio.pdf
connellalykshamesb60
 
____ The pigment produced by S. marvel scenes would appear first on t.pdf
____ The pigment produced by S. marvel scenes would appear first on t.pdf____ The pigment produced by S. marvel scenes would appear first on t.pdf
____ The pigment produced by S. marvel scenes would appear first on t.pdf
connellalykshamesb60
 
Write the advantages of using JavaFX with compare to Swing and AWT..pdf
Write the advantages of using JavaFX with compare to Swing and AWT..pdfWrite the advantages of using JavaFX with compare to Swing and AWT..pdf
Write the advantages of using JavaFX with compare to Swing and AWT..pdf
connellalykshamesb60
 
Write a program in c++ that produces a bar chart showing the populat.pdf
Write a program in c++ that produces a bar chart showing the populat.pdfWrite a program in c++ that produces a bar chart showing the populat.pdf
Write a program in c++ that produces a bar chart showing the populat.pdf
connellalykshamesb60
 
Write a 2 page essay describing what life was like in the Great Depr.pdf
Write a 2 page essay describing what life was like in the Great Depr.pdfWrite a 2 page essay describing what life was like in the Great Depr.pdf
Write a 2 page essay describing what life was like in the Great Depr.pdf
connellalykshamesb60
 
Why do silver nanoparticles of 10 nanometers in diameter have lower m.pdf
Why do silver nanoparticles of 10 nanometers in diameter have lower m.pdfWhy do silver nanoparticles of 10 nanometers in diameter have lower m.pdf
Why do silver nanoparticles of 10 nanometers in diameter have lower m.pdf
connellalykshamesb60
 
Why Computer System Management is so critical for the companies (50.pdf
Why Computer System Management is so critical for the companies (50.pdfWhy Computer System Management is so critical for the companies (50.pdf
Why Computer System Management is so critical for the companies (50.pdf
connellalykshamesb60
 
Which of the following statements is not true about facilitated diff.pdf
Which of the following statements is not true about facilitated diff.pdfWhich of the following statements is not true about facilitated diff.pdf
Which of the following statements is not true about facilitated diff.pdf
connellalykshamesb60
 
Which is not a hypothesis for the origin of virusesThey originated .pdf
Which is not a hypothesis for the origin of virusesThey originated .pdfWhich is not a hypothesis for the origin of virusesThey originated .pdf
Which is not a hypothesis for the origin of virusesThey originated .pdf
connellalykshamesb60
 
1. When does a corporation need a board of directors Who should and.pdf
1. When does a corporation need a board of directors Who should and.pdf1. When does a corporation need a board of directors Who should and.pdf
1. When does a corporation need a board of directors Who should and.pdf
connellalykshamesb60
 

More from connellalykshamesb60 (20)

In which of the following structures are spores formed (Select all .pdf
In which of the following structures are spores formed (Select all .pdfIn which of the following structures are spores formed (Select all .pdf
In which of the following structures are spores formed (Select all .pdf
 
How does Windows managestore user names and passwords How does it .pdf
How does Windows managestore user names and passwords How does it .pdfHow does Windows managestore user names and passwords How does it .pdf
How does Windows managestore user names and passwords How does it .pdf
 
How to use class set a function(double money(); receive a number and .pdf
How to use class set a function(double money(); receive a number and .pdfHow to use class set a function(double money(); receive a number and .pdf
How to use class set a function(double money(); receive a number and .pdf
 
For each of the following descriptions indicate which best describes.pdf
For each of the following descriptions indicate which best describes.pdfFor each of the following descriptions indicate which best describes.pdf
For each of the following descriptions indicate which best describes.pdf
 
Explain how an Annelidian differs from a MolluscanSolutionMoll.pdf
Explain how an Annelidian differs from a MolluscanSolutionMoll.pdfExplain how an Annelidian differs from a MolluscanSolutionMoll.pdf
Explain how an Annelidian differs from a MolluscanSolutionMoll.pdf
 
DNA s composed of nucleotides that are joined together by covalent bo.pdf
DNA s composed of nucleotides that are joined together by covalent bo.pdfDNA s composed of nucleotides that are joined together by covalent bo.pdf
DNA s composed of nucleotides that are joined together by covalent bo.pdf
 
Discuss some of the challenges involved in ensuring that critical kn.pdf
Discuss some of the challenges involved in ensuring that critical kn.pdfDiscuss some of the challenges involved in ensuring that critical kn.pdf
Discuss some of the challenges involved in ensuring that critical kn.pdf
 
Biologically, the term is synonymous with [Choose the term race. refe.pdf
Biologically, the term is synonymous with [Choose the term race. refe.pdfBiologically, the term is synonymous with [Choose the term race. refe.pdf
Biologically, the term is synonymous with [Choose the term race. refe.pdf
 
Anyone good with linguistics Are the following headlines transitive.pdf
Anyone good with linguistics Are the following headlines transitive.pdfAnyone good with linguistics Are the following headlines transitive.pdf
Anyone good with linguistics Are the following headlines transitive.pdf
 
A mother and father both have normal karyotypes. The father is color .pdf
A mother and father both have normal karyotypes. The father is color .pdfA mother and father both have normal karyotypes. The father is color .pdf
A mother and father both have normal karyotypes. The father is color .pdf
 
A man has a condition where all of his gametes undergo nondisjunctio.pdf
A man has a condition where all of his gametes undergo nondisjunctio.pdfA man has a condition where all of his gametes undergo nondisjunctio.pdf
A man has a condition where all of his gametes undergo nondisjunctio.pdf
 
____ The pigment produced by S. marvel scenes would appear first on t.pdf
____ The pigment produced by S. marvel scenes would appear first on t.pdf____ The pigment produced by S. marvel scenes would appear first on t.pdf
____ The pigment produced by S. marvel scenes would appear first on t.pdf
 
Write the advantages of using JavaFX with compare to Swing and AWT..pdf
Write the advantages of using JavaFX with compare to Swing and AWT..pdfWrite the advantages of using JavaFX with compare to Swing and AWT..pdf
Write the advantages of using JavaFX with compare to Swing and AWT..pdf
 
Write a program in c++ that produces a bar chart showing the populat.pdf
Write a program in c++ that produces a bar chart showing the populat.pdfWrite a program in c++ that produces a bar chart showing the populat.pdf
Write a program in c++ that produces a bar chart showing the populat.pdf
 
Write a 2 page essay describing what life was like in the Great Depr.pdf
Write a 2 page essay describing what life was like in the Great Depr.pdfWrite a 2 page essay describing what life was like in the Great Depr.pdf
Write a 2 page essay describing what life was like in the Great Depr.pdf
 
Why do silver nanoparticles of 10 nanometers in diameter have lower m.pdf
Why do silver nanoparticles of 10 nanometers in diameter have lower m.pdfWhy do silver nanoparticles of 10 nanometers in diameter have lower m.pdf
Why do silver nanoparticles of 10 nanometers in diameter have lower m.pdf
 
Why Computer System Management is so critical for the companies (50.pdf
Why Computer System Management is so critical for the companies (50.pdfWhy Computer System Management is so critical for the companies (50.pdf
Why Computer System Management is so critical for the companies (50.pdf
 
Which of the following statements is not true about facilitated diff.pdf
Which of the following statements is not true about facilitated diff.pdfWhich of the following statements is not true about facilitated diff.pdf
Which of the following statements is not true about facilitated diff.pdf
 
Which is not a hypothesis for the origin of virusesThey originated .pdf
Which is not a hypothesis for the origin of virusesThey originated .pdfWhich is not a hypothesis for the origin of virusesThey originated .pdf
Which is not a hypothesis for the origin of virusesThey originated .pdf
 
1. When does a corporation need a board of directors Who should and.pdf
1. When does a corporation need a board of directors Who should and.pdf1. When does a corporation need a board of directors Who should and.pdf
1. When does a corporation need a board of directors Who should and.pdf
 

Recently uploaded

Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
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
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
heathfieldcps1
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
Peter Windle
 
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
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
TechSoup
 
678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf
CarlosHernanMontoyab2
 
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
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
Celine George
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
joachimlavalley1
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
vaibhavrinwa19
 
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)
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
kaushalkr1407
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
Jisc
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
Vikramjit Singh
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
BhavyaRajput3
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
TechSoup
 

Recently uploaded (20)

Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
 
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
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
 
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
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
 
678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf
 
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
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
 

JAVA ProgrammingDesign a class Message that models an e-mail messa.pdf

  • 1. JAVA Programming Design a class Message that models an e-mail message. A message has a recipient, a sender, and a message text. Support the following methods: a. A constructor that takes the sender and recipient b. A method append that appends a line of text to the message body c. A method toString that makes the message into one long string like this: “From: Fname Lname To: Some Recipient …” Write a driver program that uses this class to make a message and print it. Solution MessageTest.java import java.util.Scanner; public class MessageTest { public static void main(String[] args) { Scanner scan = new Scanner(System.in); System.out.println("Enter Recipient Name: "); String recipientName = scan.nextLine(); System.out.println("Enter Sender Name: "); String senderName = scan.nextLine(); System.out.println("Enter the body text: "); String text = scan.nextLine(); Message m = new Message(recipientName, senderName); m.append(text); System.out.println(m.toString()); } } Message.java public class Message { private String recipient; private String sender;
  • 2. private String text; public Message(String r, String s){ this.recipient = r; this.sender = s; text = ""; } public void append(String t){ text = text + t +" "; } public String toString(){ return "From: "+sender+" "+text+" To: "+recipient+" "; } }