Question

Hi, the language is Java.

Learning Outcomes and Introduction In this lab assignment you will practice: . applying access modifiers using getters and seTask 3: Improved class Car Car + make: String + model: String + year: int + owner: Person todometer: Jong - odometer: long +

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

This code below is solution to your problem.

Person Class (you didn't provide it, so I just assumed a sample)

package ForUML;

public class Person {

public String name;
public String phone_no;

public Person(String name, String phone_no) {
this.name = name;
this.phone_no = phone_no;
}

  
  
public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getPhone_no() {
return phone_no;
}

public void setPhone_no(String phone_no) {
this.phone_no = phone_no;
}
  
  

}

Car Class:

package ForUML;

public class Car {

public String make;
public String model;
public int year;
public Person owner;
private long odometer;

public Car(String make, String model, int year) {
this.make = make;
this.model = model;
this.year = year;
}

public Car() {
}
  
  
public long drive(long odometer){
this.odometer= odometer;
return this.odometer;
}
public long readOdomoter(){
return this.odometer;
}

@Override
public String toString() {
return "Car{" + "make=" + make + ", model=" + model + ", year=" + year + ", odometer=" + odometer + '}';
}
  
  
  
  

}



CarTest Class:


package ForUML;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.*;

public class CarTest {

public CarTest() {
}

@BeforeClass
public static void setUpClass() {
}

@AfterClass
public static void tearDownClass() {
}

@Before
public void setUp() {
}

@After
public void tearDown() {
}

/**
* Test of drive method, of class Car.
*/
@Test
public void testDrive() {
System.out.println("drive");
long odometer = 0L;
Car instance = new Car("", "", 0);
long expResult = 0L;
long result = instance.drive(odometer);
assertEquals(expResult, result);

}

/**
* Test of readOdomoter method, of class Car.
*/
@Test
public void testReadOdomoter() {
System.out.println("readOdomoter");
Car instance = new Car("", "", 0);

long expResult = 0;
long result = instance.readOdomoter();
assertEquals(expResult, result);

}

/**
* Test of toString method, of class Car.
*/
@Test
public void testToString() {
System.out.println("toString");
Car instance = new Car();
// String expResult = null;
String result = instance.toString();
assertTrue(result.contains("model"));

}

}

OUTPUT:
Test Results X ForUML. CarTest x Tests passed: 100.00% All 3 tests passed. (0.359 s) drive toString readodomoter 0 X

Comment down for any query.
Please give a thumbs up!

Add a comment
Know the answer?
Add Answer to:
Hi, the language is Java. Learning Outcomes and Introduction In this lab assignment you will practice:...
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
  • With Java Language: In this assignment, you are to create a class named Payroll. In the...

    With Java Language: In this assignment, you are to create a class named Payroll. In the class, you are to have the following data members: name: String (5 pts) .İd: String (5 pts) hours: int (5 pts) rate: double (5 pts) private members (5 pts) You are to create no-arg and parameterized constructors and the appropriate setters(accessors) and getters (mutators). (20 pts) The class definition should also handle the following exceptions: An employee name should not be empty, otherwise an...

  • In this assignment, you will implement Address and Residence classes. Create a new java project. Part...

    In this assignment, you will implement Address and Residence classes. Create a new java project. Part A Implementation details of Address class: Add and implement a class named Address according to specifications in the UML class diagram. Data fields: street, city, province and zipCode. Constructors: A no-arg constructor that creates a default Address. A constructor that creates an address with the specified street, city, state, and zipCode Getters and setters for all the class fields. toString() to print out all...

  • You are building a system to keep track of matches played by a soccer team. You...

    You are building a system to keep track of matches played by a soccer team. You need to create a class to represent your matches. Call this class Soccer Match. The class will have the following data fields and methods: • A Date data field called startTime to register the date and time for the start of the match. • A Date data field called endTime to register the date and time for the end of the match. A String...

  • java This lab is intended to give you practice creating a class with a constructor method,...

    java This lab is intended to give you practice creating a class with a constructor method, accessor methods, mutator methods, equals method , toString method and a equals method. In this lab you need to create two separate classes, one Student class and other Lab10 class. You need to define your instance variables, accessor methods, mutator methods, constructor, toString method and equals method in Student class. You need to create objects in Lab10 class which will have your main method...

  • Please help me do the java project For this project you will be reading in a...

    Please help me do the java project For this project you will be reading in a text file and evaluating it in order to create a new file that represents the Class that will represent the properties of the text file. For example, consider the following text file: students.txt ID              Name                              Age                    IsMale           GPA 1                Tom Ryan                       22                       True              3.1 2                Jack Peterson                31                       True              2.7 3                Cindy LuWho                12                       False             3.9 When you read in the header line, you...

  • In this lab you will work with abstract classes/interfaces. (Java Program) You will be implementing a...

    In this lab you will work with abstract classes/interfaces. (Java Program) You will be implementing a basic employee schema within a company. The Employee class will be an abstract class that will contain methods applicable to all employees. You will then create 2 classes called SoftwareEngineer and ProductManager. Both are different employee types based on occupation. You will create an interface called Developer which will consist of specific methods that apply to only Developers (e.g. SoftwareEngineer class will implement this,...

  • This is assignment and code from this site but it will not compile....can you help? home...

    This is assignment and code from this site but it will not compile....can you help? home / study / engineering / computer science / computer science questions and answers / c++ this assignment requires several classes which interact with each other. two class aggregations ... Question: C++ This assignment requires several classes which interact with each other. Two class aggregatio... (1 bookmark) C++ This assignment requires several classes which interact with each other. Two class aggregations are formed. The program...

  • Java, can you help me out thanks. CSCI 2120 Introduction For this assignment you will implement...

    Java, can you help me out thanks. CSCI 2120 Introduction For this assignment you will implement two recursive methods and write JUnit tests for each one. You may write all three methods in the same class file. You are required to write Javadoc-style documentation for all of your methods, including the test methods. Procedure 1) Write method!! a recursive method to compare two Strings using alphabetical order as the natural order (case insensitive, DO NOT use the String class built-in...

  • I need help writing my main method**** Computer Science 111 Introduction to Algorithms and Programming: Java...

    I need help writing my main method**** Computer Science 111 Introduction to Algorithms and Programming: Java Programming Project #4 – Classes and Objects (20 Points) You will create 3 new classes for this project, two will be chosen from the list below and one will be an entirely new class you invent.Here is the list: Shirt Shoe Wine Book Song Bicycle VideoGame Plant Car FootBall Boat Computer WebSite Movie Beer Pants TVShow MotorCycle Design First Create three (3) UML diagrams...

  • Amusement Park Programming Project Project Outcomes Use the Java selection constructs (if and if else). Use...

    Amusement Park Programming Project Project Outcomes Use the Java selection constructs (if and if else). Use the Java iteration constructs (while, do, for). Use Boolean variables and expressions to control iterations. Use arrays or ArrayList for storing objects. Proper design techniques. Project Requirements Your job is to implement a simple amusement park information system that keeps track of admission tickets and merchandise in the gift shop. The information system consists of three classes including a class to model tickets, a...

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