Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I'm using Java language. this is my coding for class Person and class Customer: 1) import java.util.Scanner; public class Person { private String name =

I'm using Java language. this is my coding for class Person and class Customer:

1)

import java.util.Scanner; public class Person { private String name = "none"; private int id = 0;

public Person() { } public static void person(String[] args) { Person p = new Person(); } public Person(String name, int id) { this.name = name; this.id = id; }

public String getName() { return name; } public int getID() { return id; } // setters here public void setName(String newName) { this.name = newName; } public void setId (int newId) { this.id = newId; } public String toString() { return("name: " + name + ", id: " + id); } }

2)

import java.util.Scanner; public class Customer extends Person { private int cID = 0; public Customer() { super(); } public Customer(String name, int id, int cID){ super(name, id); this.cID = cID; } public int getID() { return cID; } @Override public String toString(){ return(super.toString() +", Customer ID: " + cID); } }

NOTE (These are additional notes I got from my teacher):

1. All LE1-LE5 codes must be done with inputs from the terminal to the Test driver (with the main method) class and not using the BlueJ object bench.

2. Input can be read using Scanner class.

3. For faster input, I suggest for you to use to read each object data (all its attributes) in one line, and then split the attributes using the split() method.

4. Print the output using the Person / Customer classes methods, & not from the variables read.

WHY? Because we want to test the correctness of the classes codes that we wrote.

MY QUESTIONS ARE:

#1.

Write a test class called Test1 which will do the following which will read data from the terminal

a. Create a Person object called p with a given name and id from input

b. Create a Customer object called cust with a given name, id and customer id from input

c. print both objects

#2.

Write a test class called Test2 which will do the following which will read data from the terminal

a. Create a Person object called p with a given name and id from input

b. Assign that Person object p to a Customer object cust.

c. print both objects

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Professional IPhone And IPad Database Application Programming

Authors: Patrick Alessi

1st Edition

0470636173, 978-0470636176

More Books

Students also viewed these Databases questions