Question

In: Computer Science

LANGUAGE: JAVA Create a New Project called YourLastNameDomainName. Write a DomainName class that encapsulates the concept...

LANGUAGE: JAVA

Create a New Project called YourLastNameDomainName.

Write a DomainName class that encapsulates the concept of a domain name, assuming a domain name has a single attribute: the domain name itself. Include the following:

- Constructor: accepts the domain name as an argument.

- getDomain: an accessor method for the domain name field.

- setDomain: a mutator method for the domain name field.

- prefix: a method returning whether or not the domain name starts with www.

- extension: a method returning the extension of the domain name (i.e. the letters after the last dot, for instance com, gov, or edu; if there is no dot in the domain name, then you should return "unknown")

- name: a method returning the name itself (which will be the characters between www and the extension; for instance, yahoo if the domain is www.yahoo.com- (Links to an external site.)--if there are fewer than two dots in the domain name, then your method should return "unknown").

Write a program that demonstrates the DomainName class by prompting the user for the domain name and displays the output of the last three methods.

NOTE: The DomainName class is a new class within your project. This does not affect the name of your Java Project above.

ALSO, DO NOT FORGET TO INCLUDE THE FOLLOWING AS A COMMENT SECTION AT THE TOP OF YOUR PROGRAM:

1. Student Name

2. Program Name

3. Short Program Description

4. Due Date

Domain Name Rubric
Criteria Ratings Points
Correct Project Name 2.0
Constructor Defined Correctly 2.0
Accessor and Mutator Method Defined Correctly 2.0
Prefix Method Defined Correctly 2.0
Extension Method Defined Correctly 2.0
Name Method Defined Correctly 2.0
DomainName Class Created Correctly 2.0
Output Correct 4.0
Total Possible Points 20.0

Solutions

Expert Solution


// DomainName.java

public class DomainName
{

   private String domainName;

   public DomainName()
   {
       domainName = "";
   }

   public DomainName(String name)
   {
       domainName = name;
   }

   public void SetDomain(String name)
   {
       domainName = name;
   }

   public String GetDomain()
   {
       return domainName;
   }

   public boolean prefix()
   {
       return domainName.startsWith("www");
   }

   public String extension()
   {
       int index= domainName.lastIndexOf('.');
       if(index>0)
           return domainName.substring(index+1);

       return "unknown";
   }

   public String name()
   {
       int first= domainName.indexOf('.');
       int last= domainName.lastIndexOf('.');
       if(first==-1 || last == -1 || first==last)
           return "unknown";

       return domainName.substring(first+1, last);
   }


   public static void main(String[] args)
   {
       DomainName y = new DomainName("www.bing.com");

       System.out.println("Domain start with www ? " + y.prefix());
       System.out.println("Domain name: " + y.name());;
       System.out.println("Domain extension: " + y.extension());;

   }

}

/*

output:

Domain start with www ? true
Domain name: bing
Domain extension: com


*/


Related Solutions

Java Language -Create a project and a class with a main method, TestCollectors. -Add new class,...
Java Language -Create a project and a class with a main method, TestCollectors. -Add new class, Collector, which has an int instance variable collected, to keep track of how many of something they collected, another available, for how many of that thing exist, and a boolean completist, which is true if we want to collect every item available, or false if we don't care about having the complete set. -Add a method addToCollection. In this method, add one to collected...
Create a Java project called Lab3B and a class named Lab3B. Create a second new class...
Create a Java project called Lab3B and a class named Lab3B. Create a second new class named Book. In the Book class: Add the following private instance variables: title (String) author (String) rating (int) Add a constructor that receives 3 parameters (one for each instance variable) and sets each instance variable equal to the corresponding variable. Add a second constructor that receives only 2 String parameters, inTitle and inAuthor. This constructor should only assign input parameter values to title and...
Create a Java project called Lab3A and a class named Lab3A. Create a second new class...
Create a Java project called Lab3A and a class named Lab3A. Create a second new class named Employee. In the Employee class: Add the following private instance variables: name (String) job (String) salary (double) Add a constructor that receives 3 parameters (one for each instance variable) and sets each instance variable equal to the corresponding variable. (Refer to the Tutorial3 program constructor if needed to remember how to do this.) Add a public String method named getName (no parameter) that...
Create a Java project called 5 and a class named 5 Create a second new class...
Create a Java project called 5 and a class named 5 Create a second new class named CoinFlipper Add 2 int instance variables named headsCount and tailsCount Add a constructor with no parameters that sets both instance variables to 0; Add a public int method named flipCoin (no parameters). It should generate a random number between 0 & 1 and return that number. (Important note: put the Random randomNumbers = new Random(); statement before all the methods, just under the...
Create a new Java project called lab1 and a class named Lab1 Create a second class...
Create a new Java project called lab1 and a class named Lab1 Create a second class called VolumeCalculator. Add a static field named PI which = 1415 Add the following static methods: double static method named sphere that receives 1 double parameter (radius) and returns the volume of a sphere. double static method named cylinder that receives 2 double parameters (radius & height) and returns the volume of a cylinder. double static method named cube that receives 1 double parameter...
Write in Java * Create a new client class called Plants.java * Write code in the...
Write in Java * Create a new client class called Plants.java * Write code in the Plants class that solves problems 1,2,3 and 4 * Include the solutions of the different problems in different methods and call them from the main method * Use the BagInterface.java and ArrayBag.java, but do not add any code Problem 1: Create a bag plantsCart, which holds the following spring seedlings(represented by String) Rose, Daisy, Cabbage, Cucumber, Carrot, Cucumber, Daffodil, Daisy, Rose, Iris, Rose, Spinach....
1. Create a new Java project called L2 and a class named L2 2. Create a...
1. Create a new Java project called L2 and a class named L2 2. Create a second class called ArrayExaminer. 3. In the ArrayExaminer class declare the following instance variables: a. String named textFileName b. Array of 20 integers named numArray (Only do the 1st half of the declaration here: int [] numArray; ) c. Integer variable named largest d. Integer value named largestIndex 4. Add the following methods to this class: a. A constructor with one String parameter that...
Step 1: Create a new Java project called Lab5.5. Step 2: Now create a new class...
Step 1: Create a new Java project called Lab5.5. Step 2: Now create a new class called aDLLNode. class aDLLNode { aDLLNode prev;    char data;    aDLLNode next; aDLLNode(char mydata) { // Constructor data = mydata; next = null;    prev = null;    } }; Step 3: In the main() function of the driver class (Lab5.5), instantiate an object of type aDLLNode and print the content of its class public static void main(String[] args) { System.out.println("-----------------------------------------");    System.out.println("--------Create...
Create a Project and a Class called “FinalGrade” Write a Java program to compute your final...
Create a Project and a Class called “FinalGrade” Write a Java program to compute your final grade for the course. Assume the following (you can hard-code these values in your program). Assignments are worth 30% Labs are worth 40% Mid-term is worth 15% Final is worth 15% Ask for the grades in each category. Store them in a double variable. Print out the final percentage grade.           For example, Final Grade Calculation Enter percentage grades in the following order. Assignments,...
Problem 1 Create a new project called Lab7 Create a class in that project called ListORama...
Problem 1 Create a new project called Lab7 Create a class in that project called ListORama Write a static method in that class called makeLists that takes no parameters and returns no value In makeLists, create an ArrayList object called avengers that can hold String objects. Problem 2 Add the following names to the avengers list, one at a time: Chris, Robert, Scarlett, Clark, Jeremy, Gwyneth, Mark Print the avengers object. You will notice that the contents are displayed in...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT