Question

How can help me to create this program?

Acrobat Reader File Edit View Window Help 28% H., Thu 11:47 PM a + lab08 (2).pdf Home Tools lab08 (2).pdf x 7596 t Share Purpose The main prpose of this lab is to give you experience designing and implementing your own object classes in Java. You will write one object class for each part, and you will use the provided Java applications to test your completed object classes. Each of your object classes ust be arranged in the following three sections, each marked with a comment: instance variables, constructor(s). and instance metbods. You toString methods should return a String containing all instance variables in a sentence, with any instance variables representing monetary values formatted as money formatted to two decimal places. HnnsTips: Though the details of cach class are different, the steps to take in writing your object classes are the same steps taken in Lecture 23 to write the LightSwitch class. As usual, it is a good idea to write your class one section or method at a time, testing for compilation after each. You can also write short test applications that test the completed methods before all the methods are written and ready for the final test program. Tasks Part A. Design and implement a Java object class named Martian that simulates a martian, and test it using the supplied Java application PartADriverjava. Your Martian class ust meet the 1. A Martian should be represented by the following attributes (i e, instance variables) e a name an integer number of legs an integer number of times that the Martian has spoken 2. Your Martian class must implement the methods shown in the attacbed API All methods should behave as descibed in the API (see details of he speak method below). 3. The speak method will output a message as follows. If the Martian has previously spoken an even mumber of times, the method should output name says: Burble!. where name is replaced with the name of tbe Martian. If the Martian has previously spoken an odd umber of times, the method should instead outputname says: Take me to yourleader. (where name is again replaced with the name of the Martian) 0 Once your Martian class compiles test it by compiling and running the PartADriverjava application Submit the output along with your source code file. I+

PartADriver

public class PartADriver
{
   public static void main (String [] args)
   {
// create two martians
Martian m1 = new Martian();
Martian m2 = new Martian("Grey", 3);

// display both martians
Output.showMessage("After instantiation.\n" +
"Martian #1: " + m1.toString() +
"\nMartian #2: " + m2.toString());

// make the first martian speak 3 times
for (int count = 0; count < 3; count++)
   m1.speak();

// make the second martian speak once
m2.speak();

// display both martians
Output.showMessage("After speaking.\n" +
"Martian #1: " + m1.toString() +
"\nMartian #2: " + m2.toString());

// try some other methods
m1.setName("Martin");
m2.setNumLegs(7);
Output.showMessage("After calling some setters.\n" +
"Martian #1: " + m1.toString() +
"\nMartian #2: " + m2.toString());

if (m1.getNumLegs() > m2.getNumLegs())
   Output.showMessage(m1.getName() + " has the most legs.");
else
   Output.showMessage(m2.getName() + " has the most legs.");

   } // method main
} // class PartADriver

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

Here i hvae create two class Martian and PartADriver

Code for partadriver project


package partadriver;
//class Martian
class Martian
{
//class variable
String Name;
int Legs;
int speackcount;//for counting speak
//defualt constractor
Martian()
{
speackcount=0;
}
//perameterize constractor
Martian(String name,int numLegs)
{
Name=name;
Legs=numLegs;
speackcount=0;
}
//get name
public String getName()
{
return Name;
}
//get number of legs
public int getNumLegs()
{
return Legs;
}
//set name
public String setName(String name)
{
this.Name=name;
return Name;
}
//set number of legs
public int setNumLegs(int numLegs)
{
this.Legs=numLegs;
return Legs;
}
//method speak
public void speak()
{//if even
if(speackcount%2==0)
{
System.out.println(Name+" says: Burble!");
}
//else odd
else
{
System.out.println(Name+" says: Take me to your leader!");
}
speackcount++;
}
//to string
public String toString()
{
return "name"+Name+" Legs"+Legs;
}
}
public class PartADriver
{


public static void main(String[] args)
{
// create two martians
Martian m1 = new Martian();
Martian m2 = new Martian("Grey", 3);
m1.setName("Blue");
m1.setNumLegs(2);
// display both martians
System.out.println("After instantiation.\n" +
"Martian #1: " + m1.toString() +
"\nMartian #2: " + m2.toString());

// make the first martian speak 3 times
for (int count = 0; count < 3; count++)
m1.speak();

// make the second martian speak once
m2.speak();

// display both martians
System.out.println("After speaking.\n" +
"Martian #1: " + m1.toString() +
"\nMartian #2: " + m2.toString());

// try some other methods
m1.setName("Martin");
m2.setNumLegs(7);
System.out.println("After calling some setters.\n" +
"Martian #1: " + m1.toString() +
"\nMartian #2: " + m2.toString());

if (m1.getNumLegs() > m2.getNumLegs())
System.out.println(m1.getName() + " has the most legs.");
else
System.out.println(m2.getName() + " has the most legs.");
}
  
}

PartADriver-NetBeans IDE 8.0.1 File Edit View Navigate Source Refactor Run Debug Profie Teem Iools Window Help Search (Ct1+) <defoult config> Projects Files Services 申, DoubleEndedoueue PartADriver.java x Emai_validation package partadriver Source Packages 白恒 factorprinefactor 3/class Martian class Martian FactorPrimeFactor.javz Lbraries //class variable il Hash set-Vowels 申-b insertionsort String Name: int Legs: int speackcount://for counting speak //defualt constractor Martian) 申 LinklistQueqe 10 Source Packages 12 13 speackcount-0: PartADriver.ava 15 16 17 18 19 20 21 /perameterize constractor Martian (String name,int numLegs) Martian-Navigator x Members Martan0 MartiarStrng name, intnuLE | Legs-numLegs: speackcount-0 cone0: object O equals(Object ob) : boolean finalize O oetdlass0:Cass O getWame0: String //get name public String getName) 23 24 25 26 27 28 29 return Name: O hashCode(): int o notfy0 O notifyAllO /get number of legs public int getNumLegs) setNametstring name) : Stina ︾ return Legs; 四Q Search Results LS Output 13:27 INS O Type here to search С л IN 16-112018 ) ENG 16-1112018-

Output:

Thank you if you have any query regarding above answer please ask me in comment box.

if you like my work appreciate with thums up.

Thank You.

Add a comment
Know the answer?
Add Answer to:
How can help me to create this program? PartADriver public class PartADriver {    public static...
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
  • Hello. I need help writing the following Java Program. Thank you Develop a class encapsulating the...

    Hello. I need help writing the following Java Program. Thank you Develop a class encapsulating the concept of a college course, assuming that a course has following attributers: code (for instance COSC1337), a description, and a number of credits (for instance 3). Include a constructor, the accessors, mutators and methods ‘toString’, ‘equals’, and ‘finalize’. Write a client class to test the behavior of the class and its methods. The outline of the class is given as follows: public class Course...

  • Java Program (PLEASE PROVIDE SCREENSHOT OF THE CODE) Create a class Person which is a super...

    Java Program (PLEASE PROVIDE SCREENSHOT OF THE CODE) Create a class Person which is a super class. The class includes four private String instance variables: first name, last name, social security number, and state. Write a constructor and get methods for each instance variable. Also, add a toString method to print the details of the person. After that create a class Teacher which extends the class, Person. Add a private instance variable to store number of courses. Write a constructor...

  • Need help to create general class Classes Data Element - Ticket Create an abstract class called...

    Need help to create general class Classes Data Element - Ticket Create an abstract class called Ticket with: two abstract methods called calculateTicketPrice which returns a double and getld0 which returns an int instance variables (one of them is an object of the enumerated type Format) which are common to all the subclasses of Ticket toString method, getters and setters and at least 2 constructors, one of the constructors must be the default (no-arg) constructor. . Data Element - subclasses...

  • Java Create four classes: 1.      An Animal class that acts as a superclass for Dog and...

    Java Create four classes: 1.      An Animal class that acts as a superclass for Dog and Bird 2.      A Bird class that is a descendant of Animal 3.      A Dog class that is a descendant of Animal 4.      A “driver” class named driver that instantiates an Animal, a Dog, and a Bird object. The Animal class has: ·        one instance variable, a private String variable named   name ·        a single constructor that takes one argument, a String, used to set...

  • Create a NetBeans project called "Question 1". Then create a public class inside question1 package called Author according to the following information (Make sure to check the UML diagram)

    Create a NetBeans project called "Question 1". Then create a public class inside question1 package called Author according to the following information (Make sure to check the UML diagram) Author -name:String -email:String -gender:char +Author(name:String, email:String, gender:char) +getName():String +getEmail):String +setEmail (email:String):void +getGender():char +tostring ):String . Three private instance variables: name (String), email (String), and gender (char of either 'm' or 'f'): One constructor to initialize the name, email and gender with the given values . Getters and setters: get Name (), getEmail() and getGender (). There are no setters for name and...

  • JAVA Create a Java project to implement a simple Name class. This class will have the...

    JAVA Create a Java project to implement a simple Name class. This class will have the following class variable: First Name, Middle Name, Last Name, and Full Name Create the accessor/getter and mutator/setter methods. In addition to these methods, create a toString() method, which overrides the object class toString() method. This override method prints the current value of any of this class object. Create a main() method to test your project.

  • JAVA /** * This class stores information about an instructor. */ public class Instructor { private...

    JAVA /** * This class stores information about an instructor. */ public class Instructor { private String lastName, // Last name firstName, // First name officeNumber; // Office number /** * This constructor accepts arguments for the * last name, first name, and office number. */ public Instructor(String lname, String fname, String office) { lastName = lname; firstName = fname; officeNumber = office; } /** * The set method sets each field. */ public void set(String lname, String fname, String...

  • Create a UML diagram to help design the class described in exercise 3 below. Do this...

    Create a UML diagram to help design the class described in exercise 3 below. Do this exercise before you attempt to code the solution. Think about what instance variables will be required to describe a Baby class object; should they be private or public? Determine what class methods are required; should they be private or public? Write Java code for a Baby class. A Baby has a name of type String and an age of type integer. Supply two constructors:...

  • Please help me with this Java problem. Would greatly appreciate comments in the code as well:...

    Please help me with this Java problem. Would greatly appreciate comments in the code as well: Define a class called Counter whose internal "count" variable is a basic integer counter. This class track that count from its instantiation in the constructor (can be set to any positive integer, or 0). The count should never be allowed to be negative. Include methods that will set the counter to 0, increase the count by 1, and decrease the count by 1. Include...

  • In this assignment you will create two Java programs: The first program will be a class...

    In this assignment you will create two Java programs: The first program will be a class that holds information (variables) about an object of your choice and provides the relevant behavior (methods) The second program will be the main program which will instantiate several objects using the class above, and will test all the functions (methods) of the class above. You cannot use any of the home assignments as your submitted assignment. Your programs must meet the following qualitative and...

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