Question

In: Computer Science

Hello, I’m having some trouble making changes to the Cellphone and the associated tester class; Any...

Hello,

I’m having some trouble making changes to the Cellphone and the associated tester class;

Any help is appreciated !

  1. Cellphone class;

-Implement both get and set methods for all 3 attributes or fields of the class

- Fields/Attributes are all initialized using the setter methods and there’s no need to initialize them using the contractor.

2) Tester Class;

-Create the objects using the default constructor. This is the constructor with no parameter

-Call the set methods of all 3 fields/attributes to set their initial values.

-No changes to the other functionalities of the tester class.

IDE; drjava

CellPhone.java

-------------------------------------------------------------------------------

/*
* This is CellPhone class with variables
* Manufacturer Name, Retail Price and Model name.
* It has its getter and setter methods along with the
* methods to calculate the increment and decrement of price.
*/
public class CellPhone {
   private String manufact_name;
   private double retail_price;
   private String model;
   public CellPhone(String name, double price, String model) {
       this.manufact_name = name;
       this.retail_price = price;
       this.model = model;  
   }

   /**
   * @return the manufact_name
   */
   public String getManufact_name() {
       return manufact_name;
   }
  
   /**
   * @return the retail_price
   */
   public double getRetail_price() {
       return retail_price;
   }
   /**
   * @param retail_price the retail_price to set
   */
   public void setRetail_price(double retail_price) {
       this.retail_price = retail_price;
   }
   /**
   * @return the model
   */
   public String getModel() {
       return model;
   }
   /**
   * @param model the model to set
   */
   public void setModel(String model) {
       this.model = model;
   }
  
   public double increase_price(double inc) {
       retail_price = retail_price + inc;
       return retail_price;  
   }
  
   public double decrease_price(double dec) {
       retail_price = retail_price - dec;
       return retail_price;
   }

}

CPTester.java

-------------------------------------------------------------------------------

/*
* This class tests the CellPhone.java class. It creates two objects for CellPhone class
* Gets the input from User through Scanner class. Increase/Decrease the price of CellPhone
* and display the CellPhone object information.
*/
import java.util.Scanner;

public class CPTester {
  
   public static void main(String[]args) {
       Scanner in = new Scanner(System.in);             

       System.out.print("Please enter the CellPhone1 Manufacturer Name:");
       String manufact_name1 = in.next();
       System.out.print("Please enter the CellPhone1 Retail Price :");
       double price1 = in.nextDouble();
       System.out.print("Please enter the CellPhone1 Model Name :");
       String model1 = in.next();
      
       CellPhone cp1 = new CellPhone(manufact_name1,price1, model1);
       System.out.println("CellPhone1 Manufacturer Name :"+cp1.getManufact_name());
       System.out.println("CellPhone1 Retail price :"+cp1.getRetail_price());
       System.out.println("CellPhone1 Model :"+cp1.getModel());
       //Increased price
       System.out.print("Please enter the CellPhone1 price increment :");
       double inc=in.nextDouble();
       //Price after increase
       System.out.println("CellPhone1 Retail price After increase :"+cp1.increase_price(inc));
      
      
       System.out.print("Please enter the CellPhone2 Manufacturer Name:");
       String manufact_name2 = in.next();
       System.out.print("Please enter the CellPhone2 Retail Price :");
       double price2 = in.nextDouble();
       System.out.print("Please enter the CellPhone2 Model Name :");
       String model2 = in.next();
       CellPhone cp2 = new CellPhone(manufact_name2,price2, model2);
       System.out.println("CellPhone2 Manufacturer Name :"+cp2.getManufact_name());
       System.out.println("CellPhone2 Retail price :"+cp2.getRetail_price());
       System.out.println("CellPhone2 Model :"+cp2.getModel());
       //Decreased price
       System.out.print("Please enter the CellPhone2 price Decrease :");
       double dec=in.nextDouble();
       //Price after decrease
       System.out.println("CellPhone2 Retail price After decrease :"+cp2.decrease_price(dec));      
              
   }

}

Solutions

Expert Solution

Hey! here my answer is given below...to appreciate my work please give a positive rating......

CellPhone.java setManufact_name() set function is added .......

/*
* This is CellPhone class with variables
* Manufacturer Name, Retail Price and Model name.
* It has its getter and setter methods along with the
* methods to calculate the increment and decrement of price.
*/
public class CellPhone {
    private String manufact_name;
    private double retail_price;
    private String model;
    
    /**
    * @return the manufact_name
    */
    public String getManufact_name() {
        return manufact_name;
    }

    /**
    * @param manufact_name the manufact_name to set
    */
    public void setManufact_name(String manufact_name) {
        this.manufact_name = manufact_name;
    }

   
    /**
    * @return the retail_price
    */
    public double getRetail_price() {
        return retail_price;
    }
    /**
    * @param retail_price the retail_price to set
    */
    public void setRetail_price(double retail_price) {
        this.retail_price = retail_price;
    }
    /**
    * @return the model
    */
    public String getModel() {
        return model;
    }
    /**
    * @param model the model to set
    */
    public void setModel(String model) {
        this.model = model;
    }

   
   
    public double increase_price(double inc) {
        retail_price = retail_price + inc;
        return retail_price;  
    }
   
    public double decrease_price(double dec) {
        retail_price = retail_price - dec;
        return retail_price;
    }
 
 }

CPTester.java , updated code with explanation.....

/*
* This class tests the CellPhone.java class. It creates two objects for CellPhone class
* Gets the input from User through Scanner class. Increase/Decrease the price of CellPhone
* and display the CellPhone object information.
*/
import java.util.Scanner;

public class CPTester {
  
   public static void main(String[]args) {
       Scanner in = new Scanner(System.in);             
        
       /* take input from user for object cp1*/
       System.out.print("Please enter the CellPhone1 Manufacturer Name:");
       String manufact_name1 = in.next();
       System.out.print("Please enter the CellPhone1 Retail Price :");
       double price1 = in.nextDouble();
       System.out.print("Please enter the CellPhone1 Model Name :");
       String model1 = in.next();
      
       /*create cp1 object of CellPhone class
       call setter method of 3 variables to set the value of user*/
       CellPhone cp1 = new CellPhone();
       cp1.setManufact_name(manufact_name1);
       cp1.setRetail_price(price1);
       cp1.setModel(model1);

        /* call getter method of 3 variables to extract the stored data of cp1 */
       System.out.println("CellPhone1 Manufacturer Name :"+cp1.getManufact_name());
       System.out.println("CellPhone1 Retail price :"+cp1.getRetail_price());
       System.out.println("CellPhone1 Model :"+cp1.getModel());

       //Increased price
       System.out.print("Please enter the CellPhone1 price increment :");
       double inc=in.nextDouble();
       //Price after increase
       System.out.println("CellPhone1 Retail price After increase :"+cp1.increase_price(inc));
      
      /* take input from user for object cp2*/
       System.out.print("Please enter the CellPhone2 Manufacturer Name:");
       String manufact_name2 = in.next();
       System.out.print("Please enter the CellPhone2 Retail Price :");
       double price2 = in.nextDouble();
       System.out.print("Please enter the CellPhone2 Model Name :");
       String model2 = in.next();

       
        /*create cp2 object of CellPhone class
        call setter method of 3 variables to set the value of user*/
       CellPhone cp2 = new CellPhone();
       cp2.setManufact_name(manufact_name2);
       cp2.setModel(model2);
       cp2.setRetail_price(price2);

        /* call getter method of 3 variables to extract the stored data of cp1 */
       System.out.println("CellPhone2 Manufacturer Name :"+cp2.getManufact_name());
       System.out.println("CellPhone2 Retail price :"+cp2.getRetail_price());
       System.out.println("CellPhone2 Model :"+cp2.getModel());
       //Decreased price
       System.out.print("Please enter the CellPhone2 price Decrease :");
       double dec=in.nextDouble();
       //Price after decrease
       System.out.println("CellPhone2 Retail price After decrease :"+cp2.decrease_price(dec));      
              
   }

}

this updated code works fine and fulfills all the requirements...........

thanks for any query please comment in the comment section.......


Related Solutions

Hello, having some trouble with my case studies. Case Study 3 Acute Care Mrs Fox Case...
Hello, having some trouble with my case studies. Case Study 3 Acute Care Mrs Fox Case Scenario: Acute Care Mrs. Fox, a 40-year-old wife and mother of 2, was involved in a massive motor vehicle accident on the Sawmill Parkway in which her car struck the center divider and flipped twice. A good Samaritan immediately dialed 911. First responders found the patient unconscious with severe injuries but were able to safely transport her to St. John’s Riverside Hospital. Upon arrival...
Hello! I am having trouble starting this program in Java. the objective is as follows: "...
Hello! I am having trouble starting this program in Java. the objective is as follows: " I will include a text file with this assignment. It is a text version of this assignment. Write a program that will read the file line by line, and break each line into an array of words using the tokenize method in the String class. Count how many words are in the file and print out that number. " my question is, how do...
Hello, Im having trouble understanding the graphing/chart section of this lesson. Is there anyone who can...
Hello, Im having trouble understanding the graphing/chart section of this lesson. Is there anyone who can help me understand? Goods A B C D E F Capital 5 4 3 2 1 0 Consumer 0 5 9 12 14 15 (presentation as a table rather than as a graph) 1. Using the above PPTable, if the economy is producing at alternative D, the opportunity cost of producing one more unit of capital is A. 1 unit of consumer goods. B....
Hello, I am having trouble getting started on my project and building these functions. How do...
Hello, I am having trouble getting started on my project and building these functions. How do I build a function that continuously adds new "slices" to the list if they are below/above the size limit? I didn't copy the entire problem, but just for reference, when the code is run it will take user input for size limit (L), time cost for a random slice(R), and time cost for an accurate slice(A). Question: In real life, a steak is a...
hello, I'm having trouble understanding how to do these two problems could you show me a...
hello, I'm having trouble understanding how to do these two problems could you show me a step by step. 1)Eight sprinters have made it to the Olympic finals in the 100-meter race. In how many different ways can the gold, silver, and bronze medals be awarded? 2)Suppose that 34% of people own dogs. If you pick two people at random, what is the probability that they both own a dog? Give your answer as a decimal (to at least 3...
Hello, I was having trouble combining two stock data sets into excel. If you could please...
Hello, I was having trouble combining two stock data sets into excel. If you could please select a random stock and S&P 500 and conduct the following A.1) From Yahoo Finance’s Historical Data feature, download 5 years of daily data. The measures include Date, Open, High, Low, Close, Adj Close, and Volume. You should download this data for both your stock as well as for the S&P500. A.2) Combine the data in one Excel sheet. Add a prefix to each...
Directional and non-directional Hello! I'm having som trouble understanding the meaning of directional and non-directional hypothesis....
Directional and non-directional Hello! I'm having som trouble understanding the meaning of directional and non-directional hypothesis. What does it mean, and how do this affect the p-value? I also heard about "negative directional alternative" but could not find any information about this Thank you!
Hello, I am having trouble with my Advanced Accounting Ch 18 homework. Accounting for nonprofts. Here...
Hello, I am having trouble with my Advanced Accounting Ch 18 homework. Accounting for nonprofts. Here are a few questions: At the beginning of the year, Nutrition Now, a health and welfare not-for-profit entity, had the following equity balances: Net assets without donor restriction $400,000 Net assets with donor restriction $290,000 1. Unrestricted contributions (pledges) of $250,000, to be collected in cash in thirty days, before the end of the year, are received. 2. Salaries of $27,000 are paid with...
​​​​​​This is an assignment that I'm having trouble figuring out in python: Modify Node class so...
​​​​​​This is an assignment that I'm having trouble figuring out in python: Modify Node class so it has a field called frequency and initialize it as one. Add a search function. If a number is in the list, return its frequency. Modify Insert function. Remove push, append, and insertAfter as one function called insert(self, data). If you insert a data that is already in the list, simply increase this node’s frequency. If the number is not in the list, add...
Having some trouble with this Java Lab (Array.java) Objective: This lab is designed to create an...
Having some trouble with this Java Lab (Array.java) Objective: This lab is designed to create an array of variable length and insert unique numbers into it. The tasks in this lab include: Create and Initialize an integer array Create an add method to insert a unique number into the list Use the break command to exit a loop Create a toString method to display the elements of the array Task 1: Create a class called Array, which contains an integer...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT