I'm getting these errors on the following code that wasanswered. I also included the instructions from theassignment
Question:
I'm getting these errors on the following code that wasanswered. I also included the instructions from theassignment at the very bottom. Any help would be muchappreciated.
ERRORS:
Car.java:18: error: array required, but String found
carMakes[i][1]=" ";
^
Car.java:28: error: array required, but String found
if(carMakes[i][0].equals(car))
^
Car.java:37: error: array required, but String found
System.out.println(carMakes[i][0]);
^
Car.java:49: error: array required, but String found
System.out.println(carMakes[i][0]);
^
Car.java:52: error: incompatible types: int cannot be converted toString
return index;
^
Car.java:57: error: array required, but String found
System.out.println(carMakes[i][0]);
^
Car.java:121: error: non-static method getCar() cannot bereferenced from a static context
String theCar = getCar();
^
Car.java:126: error: method findCar in class Car cannot be appliedto given types;
int rowNumber = findCar();
^
required: String,String[]
found: no arguments
reason: actual and formal argument lists differ inlength
Car.java:131: error: variable rowNumber is already defined inmethod main(String[])
int rowNumber = printCarMakes();
^
Car.java:131: error: method printCarMakes in class Car cannot beapplied to given types;
int rowNumber = printCarMakes();
^
required: String[]
found: no arguments
reason: actual and formal argument lists differ inlength
10 errors
----jGRASP wedge2: exit code for process is 1.
----jGRASP: operation complete.
CODE:
import java.util.Scanner;
public class Car {
String getCar(){
Scanner scanner = newScanner(System.in);
String car =scanner.nextLine();
if(car.isEmpty()){
System.out.println("Input is empty");
}
System.out.println(car);
return car;
}
String findCar(String car, String[] carMakes){
for(inti=0;i//second column of the array to six spaces
carMakes[i][1]="";
}
// ask to enter a car name
System.out.print("Enter car make tosearch: ");
// read car make
// initialize index to -1
int index = -1;
// iterate through each car in array
for (int i = 0; i // set index to i if found at index i
if(carMakes[i][0].equals(car))
index = i;
}
// if index is -1
if (index == -1) {
// then car is not found
System.out.println(car + " is not found!");
//display the contents of the first column of the array in acolumn
for (int i = 0;i < carMakes.length; i++) {
System.out.println(carMakes[i][0]);
}
}
// if index is not -1
else {
// print the index where car is found
System.out.println(car + " is found at index " + index);
System.out.println();
// print other cars in array
System.out.println("Other cars are");
for (int i = 0;i < carMakes.length; i++) {
if (index != i)
System.out.println(carMakes[i][0]);
}
}
return index;
}
public void printCarMakes(String[] carMakes){
for (int i = 0; i System.out.println(carMakes[i][0]);
}
}
public static void main(String[] args) {
// create an array of 8 Strings
Scanner scanner = newScanner(System.in);
//declare 2D array
String[][] carMakes = newString[8][2];
//initialize values
carMakes[0][0] = "GMC";
carMakes[1][0] = "Audi";
carMakes[2][0] = "Honda";
carMakes[3][0] = "Chevy";
carMakes[4][0] = "Ford";
carMakes[5][0] = "Nissan";
carMakes[6][0] = "Kia";
carMakes[7][0] = "MG";
for(inti=0;i//second column of the array to six spaces
carMakes[i][1]="";
}
// ask to enter a car name
System.out.print("Enter car make tosearch: ");
// read car make
String car =scanner.nextLine();
// initialize index to -1
int index = -1;
// iterate through each car in array
for (int i = 0; i // set index to i if found at index i
if(carMakes[i][0].equals(car))
index = i;
}
// if index is -1
if (index == -1) {
// then car is not found
System.out.println(car + " is not found!");
//display the contents of the first column of the array in acolumn
for (int i = 0;i < carMakes.length; i++) {
System.out.println(carMakes[i][0]);
}
}
// if index is not -1
else {
// print the index where car is found
System.out.println(car + " is found at index " + index);
System.out.println();
// print other cars in array
System.out.println("Other cars are");
for (int i = 0;i < carMakes.length; i++) {
if (index != i)
System.out.println(carMakes[i][0]);
// Input: Make of Car
// Process: Validation of user input
// Output: Array content and if car is found or not
// Jennifer Stone
// JS
}
}
// Input: Make of Car
// Process: Validation of userinput
// Output: Make of Car
String theCar = getCar();
// Input: Make of Car, list ofcar makes
// Process: search the list to findcar make
// Output: Make of Car
int rowNumber = findCar();
// Input: List of carMakes
// Process: print the list of allcars
// Output: List of all cars
int rowNumber =printCarMakes();
}
}
ORIGINAL QUESTION:
This chapter is about modules, so you will be creating modulesin your existing program from last week and movingcode you have alreadywritten in to the appropriate module.
1. Create a module that contains this code:
- asks the user what make of car they want to buy
- does input validation that the user didn't just pressenter
- every right curly brace has a comment stating what it isending
- choose a name for the module that starts with a verb
- input parameters are either none or the Scanner, youchoose.
- this module returns the make of the car
- call the module from main()
- add a comment with Process, Input, and Output for themodule
2. Create a module that contains this code:
- searches the first column of the array to see of there is amatch of the car make
- every right curly brace has a comment stating what it isending
- remember the module name should start with a verb
- input parameters are the car make from the user and thearray
- returns the row number if the make name is found, or a sentinelif the make is not found
- call the module from main()
- add a comment with Process, Input, and Output for themodule
3. Create a module that contains this code:
- displays the entire content of the 8 X 2 array
- every right curly brace has a comment stating what it isending
- module name starts with a verb
- input parameter is the array
- return void
- call the module from main()
- is called for each user
- add a comment with Process, Input, and Output for themodule
4. In main() should be:
- initialization of the array
- loop asking three users what make of car they want to buy
- variables in which to store the return values from calling themodules
- calls to the three modules
- if the make is found, display that the make is found and therow and name of the make.
- if the make is not found, display the contents of column 1 ofthe array
- update your IPO comments in main()
5. Your program should function the same after implementing themodules, and be sure and test it to make sure it still functionscorrectly.
Income Tax Fundamentals 2013
ISBN: 9781285586618
31st Edition
Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill