1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Olin [163]
4 years ago
12

Write a Java program to create a class called Cars. The class should include three instance variables: makes (type: String), mod

els (type: String), and years (type: int); and two methods: a constructor() to initialize three variables and a show() to display the information of a car. Write a class called TestCars to test the class Cars. This class should be able to read the makes, models, and years of three cars from screen input, create three-car objects using the constructor() and display each car's make, model, and years using the show(). (5pts)
Computers and Technology
1 answer:
Fiesta28 [93]4 years ago
5 0

Answer:

Explanation:

This code was written in Java. It creates the Cars class with the requested variables and methods. It also creates the TestCars class which asks the user for the necessary inputs and then creates three Cars objects and passes the input values to the constructors. Finally, it uses the show() method on each object to call the information. A test has been created and the output can be seen in the attached image below.

import java.util.Scanner;

class TestCars{

   public static void main(String[] args) {

       Scanner in = new Scanner(System.in);

       System.out.print("Enter Car Make: ");

       String make1 = in.next();

       System.out.print("Enter Car Model: ");

       String model1 = in.next();

       System.out.print("Enter Car Year: ");

       int year1 = in.nextInt();

       System.out.print("Enter Car Make: ");

       String make2 = in.next();

       System.out.print("Enter Car Model: ");

       String model2 = in.next();

       System.out.print("Enter Car Year: ");

       int year2 = in.nextInt();

       System.out.print("Enter Car Make: ");

       String make3 = in.next();

       System.out.print("Enter Car Model: ");

       String model3 = in.next();

       System.out.print("Enter Car Year: ");

       int year3 = in.nextInt();

       Cars car1 = new Cars(make1, model1, year1);

       Cars car2 = new Cars(make2, model2, year2);

       Cars car3 = new Cars(make3, model3, year3);

       car1.show();

       car2.show();

       car3.show();

   }

}

class Cars {

   String makes, models;

   int years;

   public Cars(String makes, String models, int years) {

       this.makes = makes;

       this.models = models;

       this.years = years;

   }

   public void show() {

       System.out.println("Car's make: " + this.makes);

       System.out.println("Car's model: " + this.models);

       System.out.println("Car's year: " + this.years);

   }

}

You might be interested in
In this lab you will write a C program to sort an array of strings. The program will: Create an array of 50 strings; each string
andrezito [222]

Answer:

See explaination

Explanation:

#include <stdio.h>

#include <stdlib.h>

#include <string.h>

void swap(char *arr[], int i, int minIdx)

{

char temp[30];

strcpy(temp, arr[i]);

strcpy(arr[i], arr[minIdx]);

strcpy(arr[minIdx], temp);

}

void sort(char *arr[], int n)

{

for (int i = 0; i < n - 1; i++)

{

int minIdx = i;

int minV = 10000;

char min[30];

strcpy(min, arr[i]);

for (int j = i + 1; j < n; j++)

{

int a = strcmp(min, arr[j]);

if (a < 0)

{

strcpy(min, arr[i]);

minIdx = j;

}

}

swap(arr, i, minIdx);

}

}

void print(char *arr[], int n)

{

for (int i = 0; i < n; i++)

printf("%s", arr[i]);

}

void read(char *arr[], int *n)

{

FILE *file = fopen("strings.dat", "r");

char line[30];

*n = 0;

printf("Reading from file...\n");

while (fgets(line, 30, file))

{

strcpy(arr[(*n)++], line);

}

print(arr, *n);

}

int main(int argc, char const *argv[])

{

char *arr[50];

for (int i = 0; i < 50; i++)

arr[i] = (char *)malloc(sizeof(char) * 30);

int len;

int n = 0;

read(arr, &n);

printf("\n-------------------------\nAfter sorting\n");

sort(arr, n);

print(arr, n);

}

6 0
3 years ago
General description of the problem
Elden [556K]

Explanation:

problem is the misunderstanding misbehaviour etc which harm us and others

4 0
3 years ago
What is the max theoretical throughput of the 802.11ac wireless technology when using wave 1 devices?​?
quester [9]
Answer is 1.3 Gbps

When using wave 1 devices, the physical rate or the maximum theoretical throughput is 1.3 Gbps. Wave 1 products have been used for about two and a half years now. It has however been overtaken by wave 2 devices which builds upon Wave 1 and supports speeds of up to 2.34 Gbps  up from 1.3 Gbps in the 5 Ghz band.




3 0
3 years ago
Which are characteristics of pseudocode? Select all that apply.
jeka94

Answer:

A,B,C

Explanation:

3 0
3 years ago
If you are writing a program that needs to repeat a series of calculations, what programming structure should you use to repeat
elena55 [62]
A loop.

---------------------------------------
7 0
3 years ago
Other questions:
  • Which relationship is possible when two tables share the same primary key?
    9·2 answers
  • Most internet connections use what transmission
    13·2 answers
  • Which of the following statements about cover letters is false?
    14·2 answers
  • Need help asap<br> give the correct answer!!
    15·2 answers
  • Directions: Asba student of Contact Center Service, you already have an experience using different computer programs. Try to rem
    8·2 answers
  • Why did they meet their friend<br><br><br><br><br><br><br><br>​
    8·2 answers
  • Write a function SwapArrayEnds() that swaps the first and last elements of the function's array parameter. Ex: sortArray = {10,
    7·1 answer
  • What is phishing?
    14·1 answer
  • What are the two features of EDIAC ?​
    10·1 answer
  • An optical drive randomly becomes unavailable, and after replacing the drive, the technician now suspects that the drive may not
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!