Question

In: Computer Science

Java Programming (8th Edition) Joyce Farrell p.530, Chapter 10 Problem 1E with user input with scanner...

Java Programming (8th Edition) Joyce Farrell p.530, Chapter 10 Problem 1E with user input with scanner and the following results:

Enter name of horse: ABC
Enter color of horse: Red
Enter year: 2000
Enter name of horse: DEF
Enter color of horse: Blue
Enter year: 2010
Enter number of races: 6
ABC is red and born in 2000.
DEF is blue and born in 2010.
DEF completed 6 races..

Solutions

Expert Solution

import java.util.*;

public class Main
{
   public static void main(String[] args)
   {
   //string array declaration
   String name[] = new String[10];
   String color[] = new String[10];
   int year[] = new int[10];
   int races[] = new int[10];
  
   //intput name, color, year and number of races
   for(int i=0; i<2; i++)
   {
   Scanner sc = new Scanner(System.in);
       System.out.print("Enter name of horse: ");
       name[i] = sc.nextLine();
       System.out.print("Enter color of horse: ");
       color[i] = sc.nextLine();
       System.out.print("Enter year: ");
       year[i] = sc.nextInt();
       System.out.print("Enter number of races: ");
       races[i] = sc.nextInt();
   }
  
   //display info on the computer screen
   System.out.println("");
   for(int i=0; i<2; i++)
   {
   System.out.println(name[i] + " is "+color[i]+" and born in "+year[i]+".");
   if(races[i]>0)
   System.out.println(name[i] + " completed "+ races[i] + " races..");
   }
   }
}

OUTPUT:


Related Solutions

Engineering Mechanics (8th Edition) Chapter 3, Problem 212P
Engineering Mechanics (8th Edition) Chapter 3, Problem 212P  
User the Scanner class for your input Write a java program to calculate the area of...
User the Scanner class for your input Write a java program to calculate the area of a rectangle. Rectangle Area is calculated by multiplying the length by the width   display the output as follow: Length =   Width = Area = Load: 1. Design (Pseudocode ) 2. Source file (Java file, make sure to include comments) 3. Output file (word or pdf or jpig file)
Java Programming 5th edition Chapter 10 Inheritance Programs Part 1 Number 3 on page 719 which...
Java Programming 5th edition Chapter 10 Inheritance Programs Part 1 Number 3 on page 719 which creates a Point class with 2 instance variables; the xCoordinate and yCoordinate. It should have a default constructor and a values constructor. Also include a set method that sets both attributes, a get method for each attribute, and a method that redefines toString() to print the attributes as follows. point: (x, y) Part 2 Do number 4 on page 719 which creates a Circle...
(Java 8th Person edition) Exercise 13.9, p. 536 (Enable Circle comparable). Override the following methods: compareTo...
(Java 8th Person edition) Exercise 13.9, p. 536 (Enable Circle comparable). Override the following methods: compareTo (interface Comparable), toString (class GeometricObject) and equals (class Object).Create an array of comparable circles, sort them and display the result of a sorting procedure. Then create one more circle, which is equal to one of the existing circles and demonstrate the work of the method equals(). I added the code that the question references, but I'm not even quite too sure what it's asking...
Java Programming I need an application that collects the user input numbers into an array and...
Java Programming I need an application that collects the user input numbers into an array and after that calls a method that sums all the elements of this array. and display the array elements and the total to the user. The user decides when to stop inputting the numbers. Thanks for your help!
JAVA PROGRAMMING Is there a way I can use a method to place a user input...
JAVA PROGRAMMING Is there a way I can use a method to place a user input variable into an array? Then call the same method to print the array? I'm new to Java programming I'm not sure how to continue. For example: import java.util.Scanner; public class PartayScanner { public static void main(String[] args) { Scanner scan = new Scanner(System.in); System.out.println("Enter pokemon 1:"); String pokemon1 = scan.nextLine(); System.out.println("Enter pokemon 2:"); String pokemon2 = scan.nextLine(); System.out.println("Enter pokemon 3:"); String pokemon3 = scan.nextLine();...
JAVA CODE --- from the book, java programming (7th edition) chapter 7 carly's question I am...
JAVA CODE --- from the book, java programming (7th edition) chapter 7 carly's question I am getting a illegal expression error and don't know how to fix it, also may be a few other error please help CODE BELOW import java.util.Scanner; public class Event { public static double pricePerGuestHigh = 35.00; public static double pricePerGuestLow = 32.00; public static final int LARGE_EVENT_MAX = 50; public String phnum=""; public String eventNumber=""; private int guests; private double pricePerEvent; public void setPhoneNumber() {...
Cost Management: A Strategic Emphasis (8th Edition) Chapter 19, Problem 49 Transfer Pricing; Decision Making Phoenix...
Cost Management: A Strategic Emphasis (8th Edition) Chapter 19, Problem 49 Transfer Pricing; Decision Making Phoenix Inc., a cellular communication company, has multiple business units, organized as divisions. Each division’s management is compensated based on the division’s operating income. Division A currently purchases cellular equipment from outside markets and uses it to produce communication systems. Division B produces similar cellular equipment that it sells to outside customers—but not to division A at this time. Division A’s manager approaches division B’s...
Instructions JAVA PROGRAMMING 1. Ask the user for a year input (positive integer - should be...
Instructions JAVA PROGRAMMING 1. Ask the user for a year input (positive integer - should be between 1500 and 2019, inclusive). 2. If the year input is not between 1500 and 2019, do not check for leap year, rather print that this year cannot be checked. 3. Take a year input from the user (should be between 1500 and 2019) 4. If the input year is a leap year, print that year is a leap year; otherwise, print that the...
java from control structures through objects 6th edition, programming challenge 5 on chapter 16 Write a...
java from control structures through objects 6th edition, programming challenge 5 on chapter 16 Write a boolean method that uses recursion to determine whether a string argument is a palindrome. the method should return true if the argument reads the same forward amd backword. Demonstrate the method in a program, use comments in the code for better understanding. there must be a demo class and method class also .. generate javadocs through eclipse compiler. And make a UML diagram with...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT