Question

***PLEASE HELP!!!***

PLEASE READ INSTRUCTIONS CAREFULLY ANF PLEASE THOROUGHLY COMPLETE. Will reward full points!

PROGRAMMING LANGUAGE: JAVA

Thank you in advance.

Summary Now for something a little different In a hypothetical world, a new mobile game emerges where players collect digital characters called Digit The players start out with a selection of Digitoids oids (specific to the region of world they began at) from which they choose one to be their first Digitoid However, players can also visit famous landmarks (e.g. Space Needle) to purchase a special code to get a randomly chosen Digitoid that are available only in that landmark (e.g. a rock and roll green martian) There are two modes for these Digitoids a Virtual Reality mode where the Digitoid will interact with other Digitoid in a persistent virtual world in the Cloud and an Augmented Reality world where the Digitoid can interact with the real world such as finding discounts, giving you information about sights, provide directions, etc. For this homework assignment, create a simplified version of a Digitoid and the corresponding Driver class Skills Expected All the skills from previous Assignment(s) Overrides: tostring, equals Runtime Exception Enums Assignment Description You will create two Class objects (and subsequently submit two java files) Digitoid Driver Notes: ONLY the Driver Class should have static methods. The Device Class should NOT have static methods or static instance variables (constants ok).

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Hi,

Please see the classes and output. Please comment for any queries/feedbacks.

Thanks,

Digitoid.java


public class Digitoid {
   private String name;
   private String type;
   private double experience;

   //Constructor
   public Digitoid(String name) throws Exception{
       super();
       if(null!= name && !"".equalsIgnoreCase(name) ){
           this.name = name;
           this.type = "default";
       }
       else{
           throw new Exception("Invalid name!");
       }

   }

   //Overloaded Constructor
   public Digitoid(String name, String type) throws Exception{
       super();
       if(null!= type && !"".equalsIgnoreCase(type)){
           if(null!= name && !"".equalsIgnoreCase(name)){
               this.name = name;
               this.type = type;
           }
           else{
               throw new Exception("Invalid type!");
           }
       }
       else{
           throw new Exception("Invalid name!");
       }

   }
  
   public void interact(Digitoid digitoid){
       if(this.equals(digitoid)){
           // Attempt to interact with itself (should NOT be allowed)
           System.out.println("Cannot interact with same digitoid");
           return;
       }
       if(this.getExperience()<digitoid.getExperience()){
           //If the other Digitoid is More experienced, increase experience by 3
           this.setExperience(this.getExperience()+3);
       }
       else if(this.getExperience() == digitoid.getExperience()){
           //If the other Digitoid is Equally experienced, increase experience by 2
           this.setExperience(this.getExperience()+2);
       }
       else if(this.getExperience() > digitoid.getExperience()){
           //If the other Digitoid is Less experienced, increase experience by 1
           this.setExperience(this.getExperience()+1);
       }
      
      
       if(this.getType().equalsIgnoreCase(digitoid.getType())){
           //If the other Digitoid is Of the same type, multiple experience gained by 2
           this.setExperience(this.getExperience()*2);
       }
       else{
           //If the other Digitoid is Of another type, multiple experience gained by 3
           this.setExperience(this.getExperience()*3);
       }
      
       if(this.equals(digitoid)){
           //The “same” Digitoid (e.g. equals() returns true),
           //halve all experience gained through this interaction
           //(multiply experience again by 0.5)
           this.setExperience(this.getExperience() * .5);
       }
   }
   //Getters and setters
   public String getName() {
       return name;
   }
   public void setName(String name) {
       this.name = name;
   }
   public String getType() {
       return type;
   }
   public void setType(String type) {
       this.type = type;
   }
   public double getExperience() {
       return experience;
   }
   public void setExperience(double experience) {
       this.experience = experience;
   }

   /**
   * toString
   */
   public String toString(){
       String retString = "Name : "+this.getName()+" Type : "+this.getType()+" Exp : "+this.getExperience();
       return retString;
   }
  
   /**
   * equals
   */
   public boolean equals(Digitoid digitoid){
       //This will return true if the two digitoids have same name and type
       if(this.getName().equalsIgnoreCase(digitoid.getName())
               && this.getType().equalsIgnoreCase(digitoid.getType())){
           return true;
       }
       else{
           return false;
       }
   }

}

Driver.java


public class Driver {

   public static void main(String [] args) throws Exception{
      
       /**** "Positive" testing (checking for "valid" conditions) ****/
       // Create a Digitoid with only name
       System.out.println("Creating digitoid1");
       Digitoid digitoid1 = new Digitoid("Dig1");
      
       // Create a Digitoid with both name and type
       System.out.println("Creating digitoid2 with type humanoid");
       Digitoid digitoid2 = new Digitoid("Dig2","humanoid");
      
       // Compare two Digitoids where the equals() method returns true
       Digitoid digitoid3 = new Digitoid("Dig3","robotic");
       Digitoid digitoid4 = new Digitoid("Dig3","robotic");
       System.out.println("digitoid3 equals digitoid4 ? :" +digitoid3.equals(digitoid4));
      
       // Compare two Digitoids where the equals() method returns false
       Digitoid digitoid5 = new Digitoid("Dig5","flying");
       Digitoid digitoid6 = new Digitoid("Dig6","flying");
       System.out.println("digitoid5 equals digitoid6 ? :" +digitoid5.equals(digitoid6));
      
       // Print the toString() of a Digitoid
       Digitoid digitoid7 = new Digitoid("Dig7","insectoid");
       System.out.println(digitoid7);
      
       /**** “Negative” testing (checking for “invalid” conditions) ****/
       // Attempt to create a Digitoid with “invalid” name (e.g. empty string)
       System.out.println("Creating digitoid8 with invalid name");
   //   Digitoid digitoid8 = new Digitoid(""); // uncomment this line for Invalid name test
       // Attempt to interact with itself (should NOT be allowed)
       digitoid7.interact(digitoid7);

       /**** Interaction Testing ****/
      
       //Same type, higher experience
       Digitoid digitoid9 = new Digitoid("digitoid9","alien");
       Digitoid digitoid10 = new Digitoid("digitoid10","alien");
       digitoid9.setExperience(3);
       digitoid10.setExperience(5);
       digitoid10.interact(digitoid9);
       System.out.println("digitoid10 : " +digitoid10);
      
       // Same type, same experience
       Digitoid digitoid11 = new Digitoid("digitoid11","alien");
       Digitoid digitoid12 = new Digitoid("digitoid12","alien");
       digitoid11.setExperience(3);
       digitoid12.setExperience(3);
       digitoid11.interact(digitoid12);
       System.out.println("digitoid11 : " +digitoid11);
      
       // Same type, lower experience
       Digitoid digitoid13 = new Digitoid("digitoid13","alien");
       Digitoid digitoid14 = new Digitoid("digitoid14","alien");
       digitoid13.setExperience(3);
       digitoid14.setExperience(1);
       digitoid13.interact(digitoid14);
       System.out.println("digitoid11 : " +digitoid13);
      
      
       // Different type, higher experience
       Digitoid digitoid15 = new Digitoid("digitoid15","insectoid");
       Digitoid digitoid16 = new Digitoid("digitoid16","alien");
       digitoid15.setExperience(3);
       digitoid16.setExperience(1);
       digitoid15.interact(digitoid16);
       System.out.println("digitoid15 : " +digitoid15);
      
       //Different type, same experience
       Digitoid digitoid17 = new Digitoid("digitoid17","insectoid");
       Digitoid digitoid18 = new Digitoid("digitoid18","alien");
       digitoid17.setExperience(3);
       digitoid18.setExperience(3);
       digitoid17.interact(digitoid18);
       System.out.println("digitoid17 : " +digitoid17);
      
       //Different type, lower experience
       Digitoid digitoid19 = new Digitoid("digitoid19","insectoid");
       Digitoid digitoid20 = new Digitoid("digitoid20","alien");
       digitoid19.setExperience(3);
       digitoid20.setExperience(8);
       digitoid19.interact(digitoid20);
       System.out.println("digitoid19 : " +digitoid19);
      
       //Where equals() is false
       Digitoid digitoid21 = new Digitoid("digitoid21","insectoid");
       Digitoid digitoid22 = new Digitoid("digitoid22","insectoid");
       digitoid21.setExperience(3);
       digitoid22.setExperience(8);
       digitoid21.interact(digitoid22);
       System.out.println("digitoid21 : " +digitoid21);
      
       // Where equals() is true
       Digitoid digitoid23 = new Digitoid("digitoid23","insectoid");
       Digitoid digitoid24 = new Digitoid("digitoid23","insectoid");
       digitoid23.setExperience(3);
       digitoid22.setExperience(8);
       digitoid23.interact(digitoid24);
       System.out.println("digitoid23 : " +digitoid23);

         
   }
}

Sample output:

Creating digitoid1
Creating digitoid2 with type humanoid
digitoid3 equals digitoid4 ? :true
digitoid5 equals digitoid6 ? :false
Name : Dig7 Type : insectoid Exp : 0.0
Creating digitoid8 with invalid name
Cannot interact with same digitoid
digitoid10 : Name : digitoid10 Type : alien Exp : 12.0
digitoid11 : Name : digitoid11 Type : alien Exp : 10.0
digitoid11 : Name : digitoid13 Type : alien Exp : 8.0
digitoid15 : Name : digitoid15 Type : insectoid Exp : 12.0
digitoid17 : Name : digitoid17 Type : insectoid Exp : 15.0
digitoid19 : Name : digitoid19 Type : insectoid Exp : 18.0
digitoid21 : Name : digitoid21 Type : insectoid Exp : 12.0
Cannot interact with same digitoid
digitoid23 : Name : digitoid23 Type : insectoid Exp : 3.0

Add a comment
Know the answer?
Add Answer to:
***PLEASE HELP!!!*** PLEASE READ INSTRUCTIONS CAREFULLY ANF PLEASE THOROUGHLY COMPLETE. Will reward full points! PROGRAMMING LANGUAGE:...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Needs Help with Java programming language For this assignment, you need to write a simulation program...

    Needs Help with Java programming language For this assignment, you need to write a simulation program to determine the average waiting time at a grocery store checkout while varying the number of customers and the number of checkout lanes. Classes needed: SortedLinked List: Implement a generic sorted singly-linked list which contains all of the elements included in the unsorted linked list developed in class, but modifies it in the following way: • delete the addfirst, addlast, and add(index) methods and...

  • Please complete the following programming with clear explanations. Thanks! Homework 1 – Programming with Java: What...

    Please complete the following programming with clear explanations. Thanks! Homework 1 – Programming with Java: What This Assignment Is About? Classes (methods and attributes) • Objects Arrays of Primitive Values Arrays of Objects Recursion for and if Statements Selection Sort    Use the following Guidelines: Give identifiers semantic meaning and make them easy to read (examples numStudents, grossPay, etc.) Use upper case for constants. • Use title case (first letter is upper case) for classes. Use lower case with uppercase...

  • JAVA project PLEASE complete/ create project with comments in the programming explaining everything Text file Year...

    JAVA project PLEASE complete/ create project with comments in the programming explaining everything Text file Year of storm/ Name of storm/ mmdd storm started/ mmdd storm ended/ magnitude of storm/ //made up data 2004/Ali/1212/1219/1 2003/Bob/1123/1222/3 1980/Sarah/0123/0312/0 1956/Michael/1211/1223/4 1988/Ryan/0926/1019/ 1976/Tim/0318/1010/0 2006/Ronald/0919/1012/2 1996/Mona/0707/0723/1 2000/Kim/0101/0201/1 2001/Jim/1101/1201/3 Text file Class storm{ private String nameStorm; private int yearStorm; private int startStorm; private int endStorm; private int magStorm; public storm(String name, int year, int start, int end, int mag){ nameStorm = name; yearStorm = year; startStorm...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT