Question & Answer: model through a prompt. Also code a method called objectState that returns the formatted output for the fiel…..

Please help me answer these coding questions, I have 45 minutes to answer. Java format please.

31. Car is a class program. Car has a no-args/empty constructor and an overloaded constructor that accepts the year, make, and model and stores each in their respective fields (class-levell variables) of the same name. It has a carsBought method that returns the number purchased for that specific year, make, and model through a prompt. Also code a method called objectState that returns the formatted output for the fields according to the specs below. points) FORMATTED OUTPUT SPECS: Year, Make, & Model: 9999 Xxxxxxxxxx Xxxxxxxxxx
media%2F540%2F540567e5-ecf9-40e9-9147-86

31. Car is a class program. Car has a no-args/empty constructor and an overloaded constructor that accepts the year, make, and model and stores each in their respective fields (class-levell variables) of the same name. It has a carsBought method that returns the number purchased for that specific year, make, and model through a prompt. Also code a method called objectState that returns the formatted output for the fields according to the specs below. points) FORMATTED OUTPUT SPECS: Year, Make, & Model: 9999 Xxxxxxxxxx Xxxxxxxxxx

Don't use plagiarized sources. Get Your Custom Essay on
Question & Answer: model through a prompt. Also code a method called objectState that returns the formatted output for the fiel…..
GET AN ESSAY WRITTEN FOR YOU FROM AS LOW AS $13/PAGE
Order Essay

Expert Answer

 

Explanation::

  • Below both file code are present i.e Car.java and TestCar.java
  • Comments are prsent in codes for better understanding.

Code for Car.java ::

import java.util.*;

public class Car{

/* Following are class instance variables*/

int year;

String make,model;

Car(){

/*This is default constructor*/

}

Car(int newyear,String newMake,String newModel){

/* This is parameterized constructor also called as overloaded constructor*/

year=newyear;

make=newMake;

model=newModel;

}

int carsBought(){

Scanner sc=new Scanner(System.in);

System.out.print(“Enter cars bought for year “+year+” ::”);

return sc.nextInt();

}

String objectStat(){

String s=”Year, Make, & Model: “;

String p=Integer.toString(year);

return s+p+” “+make+” “+model;

}

}

Code for TestCar.java::

import java.util.*;

public class TestCar{

public static void main(String args[]){

/*

* Creating two objects of car named c1 and c2 with given arguments

*/

Car c1=new Car(1955,”Ford”,”Thunderbird”);

Car c2=new Car(1984,”Aston Martin Series 2″,”DB4″);

/*For both objects methods are called from class car.

* carsBought method prompts for user input.

*/

int carType1=c1.carsBought();

String s1=c1.objectStat();

System.out.println(s1);

System.out.println(“Number Purchased: “+carType1);

System.out.println();

System.out.println();

int carType2=c2.carsBought();

String s2=c2.objectStat();

System.out.println(s2);

System.out.println(“Number Purchased: “+carType2);

}

}

Output::

Grand Paper Writers
Order NOW For A 10% Discount!
Pages (550 words)
Approximate price: -

Our Advantages

Plagiarism Free Papers

All papers are written by the best professional writers to ensure 100% originality. We always provide plagiarism reports whenever we deliver completed papers.

Free Revisions

All papers by Grand Paper Writers are completed and submitted on time. This timely delivery of papers gives you time to go through the paper before the official deadline.

Title-page

As an additional service, we will provide a title page that precedes the contents of your paper. Here, you will provide your personal details.

Bibliography

We also ensure that we provide an extra page for the references or bibliographies following referencing rules.

Originality & Security

At Grandpaperwriters.com, we guarantee students for the provision of security and original work. All your personal information is handled with confidentiality and is not shared with third parties. Additionally, we ensure that we provide original content with accompanying plagiarism reports to show originality.

24/7 Customer Support

Our customer support team is always available 24/7 to provide instant responses to any queries raised by students.

Try it now!

Calculate the price of your order

We'll send you the first draft for approval by at
Total price:
$0.00

How it works?

Follow these simple steps to get your paper done

Place your order

Fill in the order form and provide all details of your assignment.

Proceed with the payment

Choose the payment system that suits you most.

Receive the final file

Once your paper is ready, we will email it to you.

Our Services

Grandpaperwriters.com has the best professional essay writers for quality services.

Pricing

Flexible Pricing

Here, a Grandpaperwriters.com, we do not compromise on the time of our clients. We always deliver all completed papers on or before the deadlines.

Communication

Admission Help & Client-Writer Contact

Grandpaperwriters.com provides an interactive portal where students can communicate directly to their writers.

Deadlines

Paper Submission

Here, a Grandpaperwriters.com, we do not compromise on the time of our clients. We always deliver all completed papers on or before the deadlines.

Reviews

Customer Feedback

Grandpaperwriters.com appreciates feedback from our clients to help us improve the delivery of essay writing services. As such, we are constantly changing our policies to ensure maximum customer and writer satisfaction.