Question

In: Computer Science

UML Diagram for this java code //java code import java.util.*; class Message { private String sentence;...

UML Diagram for this java code

//java code

import java.util.*;

class Message
{
private String sentence;
Message()
{
sentence="";
}
Message(String text)
{
setSentence(text);
}
void setSentence(String text)
{
sentence=text;
}


String getSentence()
{
return sentence;
}
int getVowels()
{
int count=0;
for(int i=0;i<sentence.length();i++)
{
char ch=sentence.charAt(i);
if(ch=='a' || ch=='e' || ch=='i' || ch=='o' || ch=='u' || ch=='A' || ch=='E' || ch=='I' || ch=='O' || ch=='U')
{
count=count+1;
}
}
return count;
}

int getConsonants()
{
int count=0;
for(int i=0;i<sentence.length();i++)
{
char ch=sentence.charAt(i);
if((ch>='a' && ch<='z') || (ch>='A' && ch<='Z'))
{
if(ch=='a' || ch=='e' || ch=='i' || ch=='o' || ch=='u' || ch=='A' || ch=='E' || ch=='I' || ch=='O' || ch=='U')
{
}
else
{
count=count+1;
}
}
}
return count;
}

int getDigits()
{
int count=0;
for(int i=0;i<sentence.length();i++)
{
char ch=sentence.charAt(i);
if(ch>=48 && ch<=57)
{
count++;
}
}
return count;
}

int getUpperCase()
{
int count=0;
for(int i=0;i<sentence.length();i++)
{
char ch=sentence.charAt(i);
if(ch>=65 && ch<=90)
{
count++;
}
}
return count;
}

int getLowerCase()
{
int count=0;
for(int i=0;i<sentence.length();i++)
{
char ch=sentence.charAt(i);
if(ch>=97 && ch<=122)
{
count++;
}
}
return count;
}

public static void main(String args[])
{
String sentence;
Scanner input=new Scanner(System.in);
System.out.print("Enter a sentence : ");
sentence=input.nextLine();
Message msg=new Message(sentence);
System.out.println("Entered phrase or sentence is "+msg.getSentence());
System.out.println("The number of vowels in the sentence: "+msg.getVowels());
System.out.println("The number of consonants in the sentence: "+msg.getConsonants());
System.out.println("The number of digits in the sentence: "+msg.getDigits());
System.out.println("The number of uppercase letters in the sentence: "+msg.getUpperCase());
System.out.println("The number of lowercase letters in the sentence: "+msg.getLowerCase());
}
}

Solutions

Expert Solution

UML Class Diagram

The UML class diagram for the given class named "Message" is given above. The class has 1 attribute, 2 constructors, and 8 methods. In the UML class diagram we represent each class with a rectangle containing 3 sections: Class Name, List of attributes, List of constructors and methods. Since we have only 1 class, we have only 1 rectangle.

Representing the attributes

The Class name is Message, so the Title is set to "Message". There is only 1 attribute called "sentence" of data type String, so it is listed next in the attribute section. The attribute name is preceded with a - (minus) sign to indicate that its scope is private.

Representing the constructors

There are 2 constructors: one no-argument constructor and another parameterized constructor. They are then listed in the 3rd section of the rectangle, each preceded by a ~ (tilde) to indicate they are of package scope (i.e. default scope in Java). Constructors have no return type so none are mentioned. The parameters to the constructor are specified within parenthesis after the constructor name as parameter-name : data-type.

Representing the methods

Each method of the class is listed next after the constructors. Methods which return int are stated as so by appending the return type after the parameter list after the colon. Methods which do not return any value are specified as void. The main() method is a static method and hence is underlined as per conventions of UML class diagrams.


Related Solutions

NEed UML diagram for this java code: import java.util.ArrayList; import java.util.Scanner; class ToDoList { private ArrayList<Task>...
NEed UML diagram for this java code: import java.util.ArrayList; import java.util.Scanner; class ToDoList { private ArrayList<Task> list;//make private array public ToDoList() { //this keyword refers to the current object in a method or constructor this.list = new ArrayList<>(); } public Task[] getSortedList() { Task[] sortedList = new Task[this.list.size()];//.size: gives he number of elements contained in the array //fills array with given values by using a for loop for (int i = 0; i < this.list.size(); i++) { sortedList[i] = this.list.get(i);...
Convert this java code from hashmap into arraylist. import java.io.*; import java.util.*; public class Solution {...
Convert this java code from hashmap into arraylist. import java.io.*; import java.util.*; public class Solution { public static void main(String[] args) throws IOException { Scanner sc = new Scanner(System.in); HashMap labs = new HashMap(); while (true) { System.out.println("Choose operation : "); System.out.println("1. Create a Lab"); System.out.println("2. Modify a Lab"); System.out.println("3. Delete a Lab"); System.out.println("4. Assign a pc to a Lab"); System.out.println("5. Remove a pc from a Lab"); System.out.println("6. Quit"); int choice = sc.nextInt(); String name=sc.nextLine(); switch (choice) { case 1:...
INSERT STRING INTO SEPARATE CHAIN HASHTABLE & ITERATE THROUGH HASHTABLE: JAVA _________________________________________________________________________________________________________________ import java.util.*; public class...
INSERT STRING INTO SEPARATE CHAIN HASHTABLE & ITERATE THROUGH HASHTABLE: JAVA _________________________________________________________________________________________________________________ import java.util.*; public class HashTable implements IHash { // Method of hashing private HashFunction hasher; // Hash table : an ArrayList of "buckets", which store the actual strings private ArrayList<List<String>> hashTable; /** * Number of Elements */ private int numberOfElements; private int numberOfBuckets; /** * Initializes a new instance of HashTable. * <p> * Initialize the instance variables. <br> * Note: when initializing the hashTable, make sure to...
CONVERT CODE FROM JAVA TO C# PLEASE AND SHOW OUTPUT import java.util.*; public class TestPaperFolds {...
CONVERT CODE FROM JAVA TO C# PLEASE AND SHOW OUTPUT import java.util.*; public class TestPaperFolds {    public static void main(String[] args)    {        for(int i = 1; i <= 4; i++)               //loop for i = 1 to 4 folds        {            String fold_string = paperFold(i);   //call paperFold to get the String for i folds            System.out.println("For " + i + " folds we get: " + fold_string);        }    }    public static String paperFold(int numOfFolds)  ...
Please perform reverse engineering to compose a UML class diagram for the provided java code /*...
Please perform reverse engineering to compose a UML class diagram for the provided java code /* Encapsulated family of Algorithms * Interface and its implementations */ public interface IBrakeBehavior { public void brake(); } public class BrakeWithABS implements IBrakeBehavior { public void brake() { System.out.println("Brake with ABS applied"); } } public class Brake implements IBrakeBehavior { public void brake() { System.out.println("Simple Brake applied"); } } /* Client that can use the algorithms above interchangeably */ public abstract class Car {...
Please add comments to this code! JAVA Code: import java.text.NumberFormat; public class Item {    private...
Please add comments to this code! JAVA Code: import java.text.NumberFormat; public class Item {    private String name;    private double price;    private int bulkQuantity;    private double bulkPrice;    /***    *    * @param name    * @param price    * @param bulkQuantity    * @param bulkPrice    */    public Item(String name, double price, int bulkQuantity, double bulkPrice) {        this.name = name;        this.price = price;        this.bulkQuantity = bulkQuantity;        this.bulkPrice = bulkPrice;   ...
Draw a UML diagram for the classes. Code for UML: // Date.java public class Date {...
Draw a UML diagram for the classes. Code for UML: // Date.java public class Date {       public int month;    public int day;    public int year;    public Date(int month, int day, int year) {    this.month = month;    this.day = day;    this.year = year;    }       public Date() {    this.month = 0;    this.day = 0;    this.year = 0;    } } //end of Date.java // Name.java public class Name...
java code ============ public class BankAccount { private String accountID; private double balance; /** Constructs a...
java code ============ public class BankAccount { private String accountID; private double balance; /** Constructs a bank account with a zero balance @param accountID - ID of the Account */ public BankAccount(String accountID) { balance = 0; this.accountID = accountID; } /** Constructs a bank account with a given balance @param initialBalance the initial balance @param accountID - ID of the Account */ public BankAccount(double initialBalance, String accountID) { this.accountID = accountID; balance = initialBalance; } /** * Returns the...
I'm getting an error for this code? it won't compile import java.util.*; import java.io.*; public class...
I'm getting an error for this code? it won't compile import java.util.*; import java.io.*; public class Qup3 implements xxxxxlist {// implements interface    // xxxxxlnk class variables    // head is a pointer to beginning of rlinked list    private node head;    // no. of elements in the list    // private int count; // xxxxxlnk class constructor    Qup3() {        head = null;        count = 0;    } // end Dersop3 class constructor   ...
import java.util.*;    public class DataAnalysis{    static Set<String> Data_NaN(Set<String> set){        Set<String> set2 =...
import java.util.*;    public class DataAnalysis{    static Set<String> Data_NaN(Set<String> set){        Set<String> set2 = new HashSet<String>();    for (String temp : set) {        temp = temp.replaceAll(        "[^0-9]", "");                  if(!(set.isEmpty())){            set2.add(temp);        }    }    return set2;               } public static void main(String args[]) { // create empty set Set<String> set = new HashSet<String>(); // {3, 25, 33, 21, 55, 43, 78,...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT