Question

First you will need to write three classes: Game Shoe Assignment within each class you will...

First you will need to write three classes:

Game
Shoe
Assignment
within each class you will add two fields and a constructor.

For Game you will need to keep track of the name of the game (String) and the number of players (int). The constructor will be in the order (String, int).

For Shoe you will need the shoe size (double) and the brand (String). The constructor will be in the order (double, String).

For Assignment you will need the score (double) and whether or not the assignment has extra credit (boolean). The constructor will be in the order (double, boolean).

Within a main method you will need a Scanner and prompts to allow the user to enter in the data. Use the following prompts:

System.out.println("Enter name of the game:");
System.out.println("Enter the number of players:");
System.out.println("Enter the shoe size:");
System.out.println("Enter the shoe brand:");
System.out.println("Enter the score for the assignment:");
System.out.println("Enter true if the assignment has extra credit or false if it does not:");

After reading in the data for the game, create a game object and print out the name of the game using the game object created.

After reading in the data for the shoe, create a shoe object and print out the shoe brand using the shoe object created.

After reading in the data for the assignment, create an assignment object and print out the score using the assignment object created.

Here is a sample run:
Enter name of the game:
fun fun
Enter the number of players:
3
fun fun
Enter the shoe size:
3.5
Enter the shoe brand:
fun fun
fun fun
Enter the score for the assignment:
300
Enter true if the assignment has extra credit or false if it does not:
true
300.0

Here is another sample run:
Enter name of the game:
Sample Game
Enter the number of players:
4
Sample Game
Enter the shoe size:
4.5
Enter the shoe brand:
Great Brand
Great Brand
Enter the score for the assignment:
100
Enter true if the assignment has extra credit or false if it does not:
false
100.0
Hint: if you user data being entered which is causing other data to be skipped over, you may use:
scanner.nextLine();
on a single line.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
// class Game
public class Game {
    int n_players;    //number of players
    String game_name; //name of the game
    
    // Constructor of class Game
    public Game(int n, String name ){ 
        
        //assigning the data members with input parameters from user.
        n_players=n;           
        game_name= name;
    } 
}
//class Shoe
public class Shoe {
    double shoe_size;    //shoe size
    String brand;        //shoe brand
    
    //constructor of class Shoe
    public Shoe(double n, String b){
        
        //assigning the data members with input parameters from user.
        shoe_size= n;
        brand= b;
    }
}
//class Assignment
public class Assignment {
    double score;            //score for the assignment
    boolean extra_credit;    //extra credit
    
    //constructor of class Assignment
    public Assignment(double s,boolean ec){
        
        //assigning the data members with input parameters from user
        score= s;
        extra_credit= ec;
}
}
import java.util.Scanner;

// the main class which is using all the three classes i.e., Game, Shoe and Assignment.

public class Main{
    
    // main method
    public static void main(String args[]){
       
       Scanner obj= new Scanner(System.in);
       Scanner inp= new Scanner(System.in);
       
       // class Game inputs
       System.out.println("Enter name of the game: "); 
       String gname= obj.nextLine();
       
       System.out.println("Enter the number of players: ");
       int np= obj.nextInt();
       
       Game g= new Game(np, gname);      // Game object created
       System.out.println(g.game_name); //printing name of the game
       
       //class Shoe inputs
       System.out.println("Enter the shoe size: ");
       double sz= obj.nextDouble();
       
       System.out.println("Enter the shoe brand: ");
       String br= inp.nextLine();
       
       Shoe s = new Shoe(sz, br);     // Shoe object created
       System.out.println(s.brand);  //printing brand of the shoe
       
       //class Assignment inputs
       System.out.println("Enter the score for the assignment:");
       double sc= obj.nextDouble();
       
       System.out.println("Enter true if the assignment has extra credit or false if it does not:");
       boolean excred = obj.nextBoolean();
       
       Assignment a= new Assignment(sc, excred);   // Assignment object created
       System.out.println(a.extra_credit);        //printing true if the assignment has extra credit or false if it does not
    }
}
Add a comment
Know the answer?
Add Answer to:
First you will need to write three classes: Game Shoe Assignment within each class you will...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • This java assignment will give you practice with classes, methods, and arrays. Part 1: Player Class...

    This java assignment will give you practice with classes, methods, and arrays. Part 1: Player Class Write a class named Player that stores a player’s name and the player’s high score. A player is described by:  player’s name  player’s high score In your class, include:  instance data variables  two constructors  getters and setters  include appropriate value checks when applicable  a toString method Part 2: PlayersList Class Write a class that manages a list...

  • You will write a class called Shoe.java Shoe.java should have Three instance variables String brand (cannot...

    You will write a class called Shoe.java Shoe.java should have Three instance variables String brand (cannot be blank) double size (from 5 to 12) int color (a number from 1 to 5 representing one of 5 colors) This code is to control the amount of colors. the colors represented are as follows 1. red 2. green 3. blue 4. black 5. grey One constructor, one get method per instance variable, one set method per instance variable. You will need a...

  • Update your Assignment 4 as follows (Assignment 4 codes will be on the bottom) Create a...

    Update your Assignment 4 as follows (Assignment 4 codes will be on the bottom) Create a new method called displayAll, that takes an ArrayList (of your base class) as a parameter, and doesn't return anything [25 pts] The displayAll method will loop through the ArrayList, and call the display (or toString) method on each object   [25 pts] In the main method, create an ArrayList containing objects of both your base class and subclass. (You should have at least 4 objects)  [25...

  • You will need to first create an object class encapsulating a Trivia Game which INHERITS from...

    You will need to first create an object class encapsulating a Trivia Game which INHERITS from Game. Game is the parent class with the following attributes: description - which is a string write the constructor, accessor, mutator and toString methods. Trivia is the subclass of Game with the additional attributes: 1. trivia game id - integer 2. ultimate prize money - double 3. number of questions that must be answered to win - integer. 4. write the accessor, mutator, constructor,...

  • Prompt: In this stepping stone lab assignment, you will build a Recipe class, getting user input...

    Prompt: In this stepping stone lab assignment, you will build a Recipe class, getting user input to collect the recipe name and serving size, using the ingredient entry code from Stepping Stone Lab Four to add ingredients to the recipe, and calculating the calories per serving. Additionally, you will build your first custom method to print the recipe to the screen. Specifically, you will need to create the following:  The instance variables for the class (recipeName, serving size, and...

  • #ifndef STUDENTTESTSCORES_H #define STUDENTTESTSCORES_H #include <string> using namespace std; const double DEFAULT_SCORE = 0.0; class StudentTestScores...

    #ifndef STUDENTTESTSCORES_H #define STUDENTTESTSCORES_H #include <string> using namespace std; const double DEFAULT_SCORE = 0.0; class StudentTestScores { private: string studentName; // The student's name double *testScores; // Points to array of test scores int numTestScores; // Number of test scores // Private member function to create an // array of test scores. void createTestScoresArray(int size) { numTestScores = size; testScores = new double[size]; for (int i = 0; i < size; i++) testScores[i] = DEFAULT_SCORE; } public: // Constructor StudentTestScores(string...

  • You will write a two-class Java program that implements the Game of 21. This is a...

    You will write a two-class Java program that implements the Game of 21. This is a fairly simple game where a player plays against a “dealer”. The player will receive two and optionally three numbers. Each number is randomly generated in the range 1 to 11 inclusive (in notation: [1,11]). The player’s score is the sum of these numbers. The dealer will receive two random numbers, also in [1,11]. The player wins if its score is greater than the dealer’s...

  • Problem Statement: A company intends to offer various versions of roulette game and it wants you...

    Problem Statement: A company intends to offer various versions of roulette game and it wants you to develop a customized object-oriented software solution. This company plans to offer one version 100A now (similar to the simple version in project 2 so refer to it for basic requirements, but it allows multiple players and multiple games) and it is planning to add several more versions in the future. Each game has a minimum and maximum bet and it shall be able...

  • 1. Write a new class, Cat, derived from PetRecord – Add an additional attribute to store...

    1. Write a new class, Cat, derived from PetRecord – Add an additional attribute to store the number of lives remaining: numLives – Write a constructor that initializes numLives to 9 and initializes name, age, & weight based on formal parameter values 2. Write a main method to test your Cat constructor & call the inherited writeOutput() method 3. Write a new writeOutput method in Cat that uses “super” to print the Cat’s name, age, weight & numLives – Does...

  • Assignment 2 – The two player game of Poaka The game of Poaka is a dice...

    Assignment 2 – The two player game of Poaka The game of Poaka is a dice game played by two players. Each player takes turns at rolling the dice. At each turn, the player repeatedly rolls a dice until either the player rolls a 1 (in which case the player scores 0 for their turn) or the player chooses to end their turn (in which case the player scores the total of all their dice rolls). At any time during...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT