You will complete a class called Socks. It simulates loading a series of socks into a sock drawer.. The class will have the following methods: • newsocks( ) : this method will receive a series of socks. Your code will ask the user haw many pairs of socks are being added to drawer (because, after all, socks should ALWAYS come in paris). Then use a loop to obtain the sock color. Users can enter blue, brown, black, or white for sock color. For any other color, they will receive a message that the color is not allowed and to enter a proper color. o How many pairs of socks? (Answer: 3) o For sock #1, what color? (Answer: white) o For sock #2, what color? (Answer: blue) o For sock #3, what color? (Answer: green) o That is not a valid color. Try again. For sock #3, what color? (Answer: black This method will update the attribute to maintain the current and accurate count of socks. • list( ) : this method will print the number of sock pairs for each color, one color per line. For instance, the result might look like this: o There are 12 pairs of blue socks o There are 5 pairs of brown socks o There are 6 pairs of black socks o There are 11 pairs of white socks

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
100%

You will complete a class called Socks. It simulates loading a series of socks into a sock drawer..
The class will have the following methods:
• newsocks( ) : this method will receive a series of socks. Your code will ask the user
haw many pairs of socks are being added to drawer (because, after all, socks should
ALWAYS come in paris). Then use a loop to obtain the sock color. Users can enter
blue, brown, black, or white for sock color. For any other color, they will receive a
message that the color is not allowed and to enter a proper color.
o How many pairs of socks? (Answer: 3)
o For sock #1, what color? (Answer: white)
o For sock #2, what color? (Answer: blue)
o For sock #3, what color? (Answer: green)
o That is not a valid color. Try again. For sock #3, what color? (Answer: black
This method will update the attribute to maintain the current and accurate count of
socks.
• list( ) : this method will print the number of sock pairs for each color, one color per line.
For instance, the result might look like this:
o There are 12 pairs of blue socks
o There are 5 pairs of brown socks
o There are 6 pairs of black socks
o There are 11 pairs of white socks 

import java.util.Scanner;
public class Socks {
//variables to hold sock colors
int blue;
int brown;
int black;
int white;
}
public Socks() {
blue = 0;
}
//Methods are to be placed below this line
public void newsocks() {
//Create Scanner object
//Loop to obtain socks
}
brown = 0;
black = 0;
white = 0;
public void list() {
//write the code to list the number of each color of sock
}
Transcribed Image Text:import java.util.Scanner; public class Socks { //variables to hold sock colors int blue; int brown; int black; int white; } public Socks() { blue = 0; } //Methods are to be placed below this line public void newsocks() { //Create Scanner object //Loop to obtain socks } brown = 0; black = 0; white = 0; public void list() { //write the code to list the number of each color of sock }
Description
You will complete a class called Socks. It simulates loading a series of socks into a sock drawer..
The class will have the following methods:
newsocks(): this method will receive a series of socks. Your code will ask the user
haw many pairs of socks are being added to drawer (because, after all, socks should
ALWAYS come in paris). Then use a loop to obtain the sock color. Users can enter
blue, brown, black, or white for sock color. For any other color, they will receive a
message that the color is not allowed and to enter a proper color.
o How many pairs of socks? (Answer: 3)
o For sock #1, what color? (Answer: white)
o
For sock #2, what color? (Answer: blue)
o For sock #3, what color? (Answer: green)
o
That is not a valid color. Try again. For sock # 3, what color? (Answer: black
This method will update the attribute to maintain the current and accurate count of
socks.
• list(): this method will print the number of sock pairs for each color, one color per line.
For instance, the result might look like this:
o
o
o
o
There are 12 pairs of blue socks
There are 5 pairs of brown socks
There are 6 pairs of black socks
There are 11 pairs of white socks
Transcribed Image Text:Description You will complete a class called Socks. It simulates loading a series of socks into a sock drawer.. The class will have the following methods: newsocks(): this method will receive a series of socks. Your code will ask the user haw many pairs of socks are being added to drawer (because, after all, socks should ALWAYS come in paris). Then use a loop to obtain the sock color. Users can enter blue, brown, black, or white for sock color. For any other color, they will receive a message that the color is not allowed and to enter a proper color. o How many pairs of socks? (Answer: 3) o For sock #1, what color? (Answer: white) o For sock #2, what color? (Answer: blue) o For sock #3, what color? (Answer: green) o That is not a valid color. Try again. For sock # 3, what color? (Answer: black This method will update the attribute to maintain the current and accurate count of socks. • list(): this method will print the number of sock pairs for each color, one color per line. For instance, the result might look like this: o o o o There are 12 pairs of blue socks There are 5 pairs of brown socks There are 6 pairs of black socks There are 11 pairs of white socks
Expert Solution
Overview

In this question we will write a java code for the socks class where we can add new socks and list them.

Let's code and hope this helps, if you find any query on solution, utilize threaded question feature.

trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Similar questions
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY