Question

In: Computer Science

You are going to create a console based program to keep track of a small business...

You are going to create a console based program to keep track of a small business that sells Doodads.

First you will need to create a class Doodad that keeps track of two integers and two Strings.

Next, create a constructor for the Doodad.

Next, add getters and setters for each of the fields (two integers and two Strings).

You need to use Doodad.java (see the starter code)

Inside your main method ask the user to read in the two integers and two Strings. Create a Doodad object and add it to an array of 100 Doodad objects. Allow the user to keep entering in Doodad objects until the user wishes to quit.

Once the user is done entering Doodad objects, show the information about the Doodads they entered.

You will show the first number, followed by a space, followed by the first word.

Solutions

Expert Solution

Answer: Hey dear student finds the solution of your query, if you have any doubt feel free to ask. Thanks!!

C++ Code: this code had Doodad class has two integer type data members ,two String type data members. Class has a parametrized constructor. In Main, read values for integers and strings and create array of object Doodad class and passing the values to set data members of the class , ask from user if he wants to exit from input and print all entered values.

Any query asks in the comment box.

import java.io.*;
import java.util.*;
class Doodad//Doodad class
{
   int a;//members of the class
   int b;
   String str1;
   String str2;
   //constructor of the class with parameters
   public Doodad(int x,String s1,int y,String s2)
   {
       a = x;//initialization of members
       b = y;
       str1 = s1;
       str2 = s2;
   }
   public void setInt1(int x)//setter to set data member of the class
   {
       a = x;
   }
   public void setInt2(int y)//setter to set data member of the class
   {
       b = y;
   }
   public void setStr1(String str)//setter to set data member of the class
   {
       str1 = str;
   }
   public void setStr2(String strr)//setter to set data member of the class
   {
       str2 = strr;
   }
   //getters to get value of data members
   public int getInt1()
   {
       return a;
   }
   public int getInt2()
   {
       return b;
   }
   public String getStr1()
   {
       return str1;
   }
   public String getStr2()
   {
       return str2;
   }
}
//Main class
class Main
{
   public static void main(String args[])//Main method
   {
       int a1 = 0,b1,c=0,ans =1;
       String st1,st2;//needed variables
       Scanner in = new Scanner(System.in);//Scanner object
       Scanner sc = new Scanner(System.in);
      
       Doodad []dd = new Doodad[100];//create object of the class
      
   while(ans>0)
   {
   //input statements to take integers and strings
       System.out.println("Enter an integer: ");
           a1 = in.nextInt();
           System.out.println("Enter an integer: ");
           b1 = in.nextInt();
           System.out.println("Enter a string: ");
           st1 = sc.nextLine();
           System.out.println("Enter a string: ");
           st2 = sc.nextLine();
           //call constructors with passing parameters
           dd[c] = new Doodad(a1,st1,b1,st2);
           c =c+1;
           System.out.println("Enter -1 to exit");
           ans = in.nextInt();//sentinel value ask
       }
       for(int i = 0;i<c;i++)//loop to print information that user has entered
       {
           System.out.print(dd[i].getInt1()+" ");//call all getters
           System.out.print(dd[i].getStr1()+" ");
           System.out.print(dd[i].getInt2()+" ");
           System.out.println(dd[i].getStr2()+" ");
       }
   }
   }
          

Screenshots of the output:


Related Solutions

You will design a program to keep track of a restaurants waitlist using a queue implemented...
You will design a program to keep track of a restaurants waitlist using a queue implemented with a linked list. Make sure to read pages 1215-1217 and 1227-1251 1. Create a class named waitList that can store a name and number of guests. Use constructors to automatically initialize the member variables. 2. Add the following operations to your program: a. Return the first person in the queue b. Return the last person in the queue c. Add a person to...
Problem statement: You are tasked with writing a simple program that will keep track of items...
Problem statement: You are tasked with writing a simple program that will keep track of items sold by a retail store. We need to keep track of the stock (or number of specific products available for sale). Requirements: The program will now be broken up into methods and store all the inventory in an ArrayList object. The program will be able to run a report for all inventory details as well as a report for items that are low in...
Problem statement: You are tasked with writing a simple program that will keep track of items...
Problem statement: You are tasked with writing a simple program that will keep track of items sold by a retail store. We need to keep track of the stock (or number of specific products available for sale). Requirements: The Food and Book items should inherit all the properties of the Product item in the previous assignment. Foods cannot be added to the inventory without an expiration date. Implement a toString method for Product, Food, and Book. Grading details: Correct usage...
In this assignment, the program will keep track of the amount of rainfall for a 12-month...
In this assignment, the program will keep track of the amount of rainfall for a 12-month period. The data must be stored in an array of 12 doubles, each element of the array corresponds to one of the months. The program should make use of a second array of 12 strings, which will have the names of the months. These two arrays will be working in parallel. The array holding the month names will be initialized when the array is...
Write a c++ program for the Sales Department to keep track of the monthly sales of...
Write a c++ program for the Sales Department to keep track of the monthly sales of its salespersons. The program shall perform the following tasks: Create a base class “Employees” with a protected variable “phone_no” Create a derived class “Sales” from the base class “Employees” with two public variables “emp_no” and “emp_name” Create a second level of derived class “Salesperson” from the derived class “Sales” with two public variables “location” and “monthly_sales” Create a function “employee_details” under the class “Salesperson”...
ASSIGNMENT: Write a program to keep track of the total number of bugs collected in a...
ASSIGNMENT: Write a program to keep track of the total number of bugs collected in a 7 day period. Ask the user for the number of bugs collected on each day, and using an accumulator, keep a running total of the number of bugs collected. Display the total number of bugs collected, the count of the number of days, and the average number of bugs collected every day. Create a constant for the number of days the bugs are being...
1. A cosmetic product retailer needs to create a database to keep track of the information...
1. A cosmetic product retailer needs to create a database to keep track of the information for its business operations. The company has a web site that posts all its products. The product information includes product ID, product name, description, and unit price. The company also needs to keep track of customers’ information, including customer names, their shipping addresses, and the email address. The company creates an account for each customer for identification and tracking purpose. A customer can purchase...
1. Create a console program in C#, * Create a class: "Student.cs" * Add 3 variables:...
1. Create a console program in C#, * Create a class: "Student.cs" * Add 3 variables: StudentName (string), SchoolYear (int), YearsUntilGraduation(int) * Method YTK() = 12 - SchoolYear; 2. Main *Enter name *Enter age *You will attend school:____ years before graduating.
A retailer, Continental Palms Retail (CPR), plans to create a database system to keep track of...
A retailer, Continental Palms Retail (CPR), plans to create a database system to keep track of the information about its inventory. CPR has several warehouses across the country. Each warehouse is uniquely named. CPR also wants to record the location, city, state, zip, and space (in cubic meters) of each warehouse. There are several warehouses in any single city. CPR stores its products in the warehouses. A product may be stored in multiple warehouses. A warehouse may store multiple products....
A small company is expanding into new offices spread across three buildings. To keep track of...
A small company is expanding into new offices spread across three buildings. To keep track of office furniture, computers, and printers, the company would like a database to keep track of everything. Each piece of office furniture, computer, or printer is given an identification number. Each item (which is either a piece of furniture, a computer, or a printer) is placed in a room of one of three buildings. The building manager is responsible for the items in their building....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT