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
Tatiana [17]
4 years ago
7

Define a class Person that represents a person. People have a name, an age, and a phone number. Since people always have a name

and an age, your class should have a constructor that has those as parameters.
Computers and Technology
2 answers:
katrin2010 [14]4 years ago
8 0

Answer:

public class Person {

   String name;

   int age;

   String phoneNumber;

   public Person(String name, int age, String phoneNumber){

          this.name = name;

          this.age = age;

          this.phoneNumber = phoneNumber;

   }

}

Explanation:

The code above is written in Java.

The following should be noted;

(i) To define a class, we begin with the keywords:

<em> public class</em>

This is then followed by the name of the class. In this case, the name is Person. Therefore, we have.

<em>public class Person</em>

<em />

(ii) The content of the class definition is contained within the block specified by the curly bracket.

(iii) The class contains instance variables name, age and phoneNumber which are properties specified by the Person class.

The name and phoneNumber are of type String. The age is of type int. We therefore have;

<em> String name;</em>

<em>int age;</em>

<em>String phoneNumber;</em>

(iv) A constructor which initializes the instance variables is also added. The constructor takes in three parameters which are used to respectively initialize the instance variables name, age and phoneNumber.

We therefore have;

<em>public Person(String name, int age, String phoneNumber){</em>

<em>           this.name = name;</em>

<em>           this.age = age;</em>

<em>           this.phoneNumber = phoneNumber;</em>

<em>    }</em>

(v) Notice also that a constructor has the same name as the name of the class. In this case, the constructor's name is Person.

marysya [2.9K]4 years ago
6 0

Answer:

The class and constructor in C++ is as follows:

class Person {

 public:

   string name;     int age;     int phone;

   Person (string x, int y) {  

     name = x;       age = y;  

   }

};

Explanation:

This defines the class

class Person {

The specifies the access specifier

 public:

This declares the attributes; name, age and phone number

   string name;      int age;      int phone;

This defines the constructor for the name and age

   Person (string x, int y) {  

This gets the name and age into the constructor

<em>      name = x;       age = y;  </em>

   }

};

You might be interested in
Write a program that accepts a file name from the command line, then initializes an array with test data using that text file as
postnew [5]

Answer:

Complete code is given below:

Explanation:

import java.io.BufferedReader;

import java.io.FileNotFoundException;

import java.io.FileReader;

import java.io.IOException;

import java.util.Arrays;

import java.util.Scanner;

public class ArrayCalcs {

private int size;

String [] parts =null;

// based on number of elements in file, array will create.

double[] arr=null;

public void readFile(String file){

try{

FileReader fr = new FileReader(file+".txt");

BufferedReader br = new BufferedReader(fr);

String line = br.readLine();

int count = 0;

while (line != null) {

parts = line.split(" ");

for( String w : parts)

{

count++;

}

line = br.readLine();

}

size=count;

arr=new double[size];

for(int i=0;i<size;i++){

arr[i]=Double.parseDouble(parts[i]);

}

// System.out.println(count);

// System.out.println(Arrays.toString(parts));

System.out.println(Arrays.toString(arr));

} catch (FileNotFoundException ex){

System.out.println("This file does not exist");

} catch (IndexOutOfBoundsException e){

System.out.println("Thie file has more than 7 lines");}

catch (IOException e) {

System.out.println(e.getMessage());

}

}

public double getTotal(){

double sum=0.0;

for(double d:arr){

sum=sum+d;

}

return sum;

}

public double getAverage(){

double avg=getTotal()/arr.length;

return avg;

}

public double getHighest(){

double high=arr[0];

for(int i=0;i<arr.length-1;i++){

if(arr[i] > high)

high = arr[i];

}

return high;

}

public double getLowest(){

double low=arr[0];

for(int i=0;i<arr.length-1;i++){

if(arr[i] < low)

low= arr[i];

}

return low;

}

public static void main(String[] args) {

Scanner s = new Scanner(System.in);

System.out.println("Enter file name:");

String file=s.next();

ArrayCalcs ac=new ArrayCalcs();

ac.readFile(file);

System.out.println(" Highest Element: "+ac.getHighest());

System.out.println("Lowest Element: "+ac.getLowest());

System.out.println("Total: "+ac.getTotal());

System.out.println("Average: "+ac.getAverage());

}

}

4 0
3 years ago
Why do you think fax machines use RLE?
Mashutka [201]

Answer:

Fax machines still use RLE for compressing the faxed documents, since they only need to represent black and white letters. JPEG images do use RLE during a final stage of compression, but they first use a more complex algorithm to compress the photographic details

8 0
3 years ago
The good example of pivoting is changing thedimensions along the axis.? True? False
ollegr [7]

Answer:

False

Explanation:

The good example of pivoting is NOT changing the dimensions along the axis.

5 0
3 years ago
What does "FDDI" stand for in Technology?
Komok [63]
Pretty sure it's Fiber Distributed Data Interface
6 0
4 years ago
Read 2 more answers
Which of the following is NOT one of the MOST common uses of Twitter?
I am Lyosha [343]
Which of the following is NOT one of the MOST common uses of Twitter? b . Making a business contact.
5 0
3 years ago
Other questions:
  • Consider an application that transmits data at a steady rate (for example, the sender generates an N-bit unit of data every k ti
    8·1 answer
  • The merge process involves which two types of files?
    9·2 answers
  • When should students practice netiquette in an online course? Check all that apply.
    14·2 answers
  • Explain why implementing synchronization primitives by disabling interrupts is not appropriate in a single-processor system if t
    14·2 answers
  • You are assigned to modify an existing Webpage by adding several tables that contain precise wording. The Webpage has had severa
    14·1 answer
  • You have a folder on your Windows desktop system that you would like to share with members of your development team. Users need
    15·1 answer
  • A(n) ________ is a web application that allows users to easily add and edit content on a web page.
    15·1 answer
  • Match the metric units with these measurements
    8·1 answer
  • Linux distributions automatically come with a native software firewall.TrueFalse
    13·1 answer
  • Will this website ever get itself together to stop people from sending links?
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!