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

You operate several news paper stands distributed throughout town. Define a clas

ID: 3673915 • Letter: Y

Question


You operate several news paper stands distributed throughout town. Define a class named News Paper Stand that has a member variable for the news paper stand's ID number and a member variable for how many news papers the stand sold that day. Create a constructer that allows a user of the class to initialize both values. Also create a function named CreSold that increments the number of news capers the stand has sold by one. This function will be invoked each time the stand sells a news paper so that you can track the total number of news papers sold by the stand. Add another function that return the number of news papers sold Finally, add a static variable that traces the total number of news papers sold by all news paper stands and a static function that returns the value in this variable. Write a main function to test your class with at least three news paper stands that each sell a variety of news papers.

Explanation / Answer

/********************************* NewsPaperStand.java ********************/

import java.util.*;
import java.io.*;

public class NewsPaperStand
{
   int news_paper_Stand_ID;          // news paper in particular stand
   int news_paper_sold;              // news paper from particular stand sold
   static int total_paper_sold;     // total papers sold

   NewsPaperStand( int news_paper_Stand_ID, int news_paper_sold)
   {
       this.news_paper_Stand_ID = news_paper_Stand_ID;
       this.news_paper_sold = news_paper_sold;
   }

   void oneSold (int news_paper_sold)
   {
       news_paper_sold++;
       total_paper_sold++;
   }

   int paper_sold()
   {
       return news_paper_sold;
   }

   static int total()
   {
       return total_paper_sold;
   }

   public static void main(String[] args)
   {
       int paper_in_Stand1;
       int paper_in_Stand2;
       int paper_in_Stand3;
       int total;
       System.out.println(" ");
       NewsPaperStand Stand1 = new NewsPaperStand(1,10);
       paper_in_Stand1 = 10;
       System.out.println("Stand 1 contain "+ paper_in_Stand1+" NewsPapers");
       System.out.println("1 news paper from Stand 1 sold");
       Stand1.oneSold(paper_in_Stand1);
       System.out.println("NewsPaper in Stand 1 left are 9 ");


       NewsPaperStand Stand2 = new NewsPaperStand(2,20);
       paper_in_Stand2 = 20;
       System.out.println("Stand 2 contain "+ paper_in_Stand2+" NewsPapers");
       System.out.println("1 news paper from Stand 2 sold");
       Stand2.oneSold(paper_in_Stand2);
       System.out.println("NewsPaper in Stand 2 left are 19 ");

       NewsPaperStand Stand3 = new NewsPaperStand(3,30);
       paper_in_Stand3 = 30;
       System.out.println("Stand 3 contain "+ paper_in_Stand3+" NewsPapers");
       System.out.println("1 news paper from Stand 3 sold");
       Stand3.oneSold(paper_in_Stand3);
       System.out.println("NewsPaper in Stand 3 left are 29 ");

       System.out.println("total papers sold are "+ NewsPaperStand.total());


}  
}

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