Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

A CellPhone object has three attributes, a brand (String), a serial number (long

ID: 3682850 • Letter: A

Question

A CellPhone object has three attributes, a brand (String), a serial number (long), and a price (double).

Part 1:
You are required to design and implement the CellPhone class according to the following specifications:
- Upon the creation of a CellPhone object, the object must immediately be initialized with valid values; that is: brand, serial number and price. You may assume that serial numbers do NOT start with 0 (that is, they can only start with digits from 1 to 9).
- Your class should have a copy constructor, so new CellPhone objects can be created as exact copies of existing ones (for simplicity, we assume here that serial numbers can be duplicated).
- The design should allow enough flexibility so that the value of any of these attributes can be modified later on. For example, it should be possible to create a CellPhone object with a given price then change its price later on.
- The design should allow the user of the class to obtain the value of any of the attributes individually (i.e. getPrice()).
- The design should also allow the user to view all CellPhone information at once using the System.out.print() method. That is, a statement such as: System.out.println(c1); would display all information of CellPhone c1.
Hint: Use toString() method.


Part 2:
In this part, you are required to write a public class called CellPhoneSearch, which will utilize the CellPhone class created in part 1. In the main method of this class the following must be done:
- Create an array of 10 cell phones. All these cell phones must be initialized with proper values; that is: brand, price & serial number. You must use the copy constructor to create some of these objects.
- Ask the user to enter three pieces of information: a cell phone brand, a cell phone price, and either Yes or No for a search combination (see details below).
- Read the entered information.
- Depending on whether the user has entered Yes or No for matching combinations, your program will search the array for matching cell phones based on the following rules:
1 If the user enters Yes for matching combinations, then your program will search the array and displays all cell phones that have both the brand and the price entered by the user.
2 If the user enters No (or anything different than Yes, or any of its variations i.e. YES) for matching combinations, then your program will search the array and display all cell phones that have either the brand entered by the user or the price entered by the user.
3 If no matches are found, the program must indicate that to the user. As a general rule, if the display is only for the prices, then it must be formatted using printf.


Guideline: For part 1 and 2, you will need to create one .java file, called CellPhoneSearch.java, which includes the CellPhone class as well as the CellPhoneSearch class (this is the public class), which will have the main() function.

Explanation / Answer

Please find below the programs that can be used to achive your task:

import java.util.Random;

class Cellphone {

private String brand;
private long serialNumber;
private double Price;

public Cellphone (String br, long sN, double Pr)
{
brand= br;
serialNumber = sN;
Price = Pr;
}
public Cellphone(Cellphone aCellphone)
{
this(aCellphone.getbrand(), aCellphone.getserialNumber(), aCellphone.getPrice());
}
public String getbrand()
{
return brand;
}
public long getserialNumber()
{
return serialNumber;
}
public double getPrice()
{
return Price;
}
public void setBrand(String cellphoneBrand)
{

//allows to set the brand of the cellphone
brand = cellphoneBrand;
}
public void setSerialNumber(long SN)
{
// Sets the Serial Number of the cellphone

serialNumber = SN;
}
public void setPrice(double Pr)
{
// Sets the price of the cellphone

Price = Pr;
}
public String toString()
{
return this.brand + ", " + this.serialNumber + " " + this.Price;

}
public boolean equals(Cellphone phone)
{
if (Price == phone.Price && brand.equals(phone))
return true;
else
return false;}
public boolean equals2(Cellphone phone)
{
if (Price == phone.Price)
return true;
else
return false;
}
public boolean equals3(Cellphone phone)
{
if (brand.equals(phone));
return true;
}

}
public class ModifyCellPhone {
public static int ModifyPhonePrices (Cellphone[][] cp, double x, double y)
{
return int r;
}
public static void main (String[] args)
{

Cellphone[][] cellphoneArr = new Cellphone[10] [10];
for (int i=0; i < cellphoneArr.length-1; i++)
{
for (int m=0; m < cellphoneArr[i].length; m++)
{
if (i % 3 == 0)
cellphoneArr[i][m]= new Cellphone("Samsung", 111111111 + (2 * (m+ i) +1), 500.4 + (m+ i));

else if (i % 3 == 1)
cellphoneArr[i][m] = new Cellphone("LG", 111111111 + (2 * (m+ i)), 500.6 + (m+ i));

else if (i % 3 == 2)
cellphoneArr[i][m] = new Cellphone("HTC", 11111111 + 2^(m+ i), 700 + (m+ i));
}

}

for (int y=9; y<cellphoneArr.length; y++)
{
for (int n=0; n<cellphoneArr[y].length; n++)
{
cellphoneArr[y][n] = new Cellphone(cellphoneArr [y-7][n]);
}
}


Random generator = new Random();

for (int i=0; i < cellphoneArr.length ; i++)
{
for (int m=0; m < cellphoneArr[i].length; m++)
{
double pick = generator.nextInt(199) + 100;
cellphoneArr[i][m].setPrice((int)pick);
}
}


for (int p = 0; p < cellphoneArr.length; p++)
{

// Loop and display sub-arrays.
for (int x = 0; x < cellphoneArr[p].length; x++)
{
System.out.print(cellphoneArr[p][x].getPrice() + " ");
}
System.out.println(" ");
}

}
}

import java.util.Scanner;

class Cellphone {

private String brand;
private long serialNumber;
private double Price;

public Cellphone (String br, long sN, double Pr)
{
brand= br;
serialNumber = sN;
Price = Pr;
}
public boolean equals(Cellphone phone)
{
if (Price == phone.Price && brand.equals(phone.brand))
return true;
else
return false;}
public boolean equals2(Cellphone phone)
{ if (Price == phone.Price)
return true;
else
return false;
}
public boolean equals3(Cellphone phone)
{ if (brand.equals(phone));
return true;
}

}
public class CellPhoneSearch {

public static void main(String[] args) {
// TODO Auto-generated method stub
Cellphone[] cellphoneArr = new Cellphone[10];
cellphoneArr [0] = new Cellphone ("Samsung", 123456789, 500.5);
cellphoneArr [1] = new Cellphone ("HTC", 123459876, 850.3);
cellphoneArr [2] = new Cellphone ("Sony", 543216789, 1230.4);
cellphoneArr [3] = new Cellphone ("Acer", 987654321, 600);
cellphoneArr [4] = new Cellphone ("Razr", 543298761, 700);
cellphoneArr [5] = new Cellphone (cellphoneArr [1]);
cellphoneArr [6] = new Cellphone (cellphoneArr [2]);
cellphoneArr [7] = new Cellphone (cellphoneArr [3]);
cellphoneArr [8] = new Cellphone (cellphoneArr [4]);
cellphoneArr [9] = new Cellphone (cellphoneArr [5]);


System.out.println("Please enter the brand");
Scanner userPreference = new Scanner(System.in);
String userBrand = userPreference.nextLine();

System.out.println("Please enter the serial number");
Scanner userSN = new Scanner(System.in);
long userSerialNumber = userSN.nextLong();

System.out.println("Please enter the Price");
Scanner userPr = new Scanner(System.in);
Double userPrice = userPr.nextDouble();


Cellphone cell_1 = new Cellphone( userBrand, userSerialNumber, userPrice );

Scanner input = new Scanner(System.in);
System.out.println("Please enter true or false if you'd like to conduct a search to see whether or not two or more cellphones are similar");
boolean enteredValue = input.nextBoolean();

if (enteredValue == true)
{
for(int i=0; i<=cellphoneArr.length-1; i++)
{ System.out.println("hello");
if (cell_1.equals(cellphoneArr[i]))
System.out.println(cellphoneArr[i].toString());
}


}
else
for(int i=0; i<=cellphoneArr.length; i++)
{if (cell_1.equals2(cellphoneArr[i]))
System.out.println(cellphoneArr[i]);

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote