Question

In: Computer Science

please , im sorting by name, address, dependent and hours. i got a lot of errors...

please , im sorting by name, address, dependent and hours. i got a lot of errors i need help please. Thanks

package application;

import java.io.BufferedReader;

import java.io.IOException;

import java.io.InputStreamReader;

import java.util.*;

class Emprec {

String name;

String address;

double hours;

double rate;

int dependents;

char gender;

boolean degree;

// This is the classes's constructor !!!!

Emprec(String name, String address, String hours,String dependents) {

try {

this.name = name;

this.address = address;

this.hours = Double.valueOf(hours).doubleValue();

this.dependents = Integer.parseInt(dependents);

} catch (NumberFormatException errmsg) {

System.out.println("Invalid format" + errmsg);

this.name = "";

this.hours = 0.0;

}// catch

}// Emprec constructor !!!!

double calc_fed_tax(double hours, double rate) {

double yearly_income;

yearly_income = hours * rate * 52;

if (yearly_income < 30000.00)

return (hours * rate * .28);

else if (yearly_income < 50000.00)

return (hours * rate * .32);

else

return (hours * rate * .38);

}// calc_fed_tax

double calc_state_tax(double hours, double rate) {

double state_tax;

state_tax = hours * rate * .0561;

return (state_tax);

}// calc_state_tax

public void setName(String name) {

this.name = name;

}

public String getName() {

return name;

}

public String getAddress() {

return address;

}

public double getHours() {

return hours;

}

public int getDependents() {

return dependents;

}

  

public double getRate(){

return rate;

}

  

public char getGender(){

return gender;

}

public String toString() {

return ("\n Name: " + name +

"\n Address: " + address +

"\n Hours: " + hours+

"\n Dependents " + dependents);

}// toString

}// Emprec

public abstract class CompDemo3Sorts_Improved {

public abstract void main(String args[]);{

Scanner sc=new Scanner(System.in);

System.out.println("Enter the fields to sort by");

String s=sc.next();

if(s=="name"){

String str[]=name.split(" ");

List<String> slist= new ArrayList<String>();

str=Arrays.asList(str);

List<String> sortedList=slist.stream().sorted().collect().(collector().toList());

sortedList.forEach(System.out.println());

}

if(s=="address"){

String str1[]=address.split(" ");

List<String> slist1= new ArrayList<String>();

str1=Arrays.asList(str1);

List<String> sortedList=slist1.stream().sorted().collect().(collector().toList());

sortedList.forEach(System.out.println());

}

if(s=="hours"){

String str2[]=hours.split(" ");

List<String> slist2= new ArrayList<String>();

str2=Arrays.asList(str2);

List<String> sortedList=slist2.stream().sorted().collect().(collector().toList());

sortedList.forEach(System.out.println());

}

if(s=="dependent"){

String str[]3=dependent.split(" ");

List<String> slist3= new ArrayList<String>();

str3=Arrays.asList(str3);

List<String> sortedList=slist3.stream().sorted().collect().(collector().toList());

sortedList.forEach(System.out.println());

}

}}

Solutions

Expert Solution

// Modified working code
//Main.java

package application;
import java.util.*;


public abstract class Main {

public static void main(String args[]){

Scanner sc=new Scanner(System.in);

System.out.println("Enter the fields to sort by");

String s=sc.next();

if(s.equals("name")){
 System.out.println("Enter name");  // when the desired sorting is selected . The list of it is taken input .
 sc.nextLine();
 String name=sc.nextLine();
String str[]=name.split(" ");

List<String> slist= new ArrayList<String>();

slist=Arrays.asList(str);

Collections.sort(slist);                     // used  Collection class for sorting
for(int i=0;i<slist.size();i++)
        System.out.println(slist.get(i));   //Printing of sorted list
}

if(s.equals("address")){
        System.out.println("Enter address");
         sc.nextLine();
        String address=sc.nextLine();

String str1[]=address.split(" ");

List<String> slist1= new ArrayList<String>();

slist1=Arrays.asList(str1);

Collections.sort(slist1);
for(int i=0;i<slist1.size();i++)
        System.out.println(slist1.get(i));

}

if(s.equals("hours")){
        System.out.println("Enter hours");
         sc.nextLine();
        String hours=sc.nextLine();
String str2[]=hours.split(" ");

List<String> slist2= new ArrayList<String>();

slist2=Arrays.asList(str2);

Collections.sort(slist2);
for(int i=0;i<slist2.size();i++)
        System.out.println(slist2.get(i));

}

if(s.equals("dependent")){
        System.out.println("Enter dependent");
         sc.nextLine();
        String dependent=sc.nextLine();

String str3[]=dependent.split(" ");

List<String> slist3= new ArrayList<String>();

slist3=Arrays.asList(str3);

Collections.sort(slist3);
for(int i=0;i<slist3.size();i++)
        System.out.println(slist3.get(i));

}

}}

//Emprec.java

package application;



class Emprec {

String name;

String address;

double hours;

double rate;

int dependents;

char gender;

boolean degree;

// This is the classes's constructor !!!!

Emprec(String name, String address, String hours,String dependents) {

try {

this.name = name;

this.address = address;

this.hours = Double.valueOf(hours).doubleValue();

this.dependents = Integer.parseInt(dependents);

} catch (NumberFormatException errmsg) {

System.out.println("Invalid format" + errmsg);

this.name = "";

this.hours = 0.0;

}// catch

}// Emprec constructor !!!!

double calc_fed_tax(double hours, double rate) {

double yearly_income;

yearly_income = hours * rate * 52;

if (yearly_income < 30000.00)

return (hours * rate * .28);

else if (yearly_income < 50000.00)

return (hours * rate * .32);

else

return (hours * rate * .38);

}// calc_fed_tax

double calc_state_tax(double hours, double rate) {

double state_tax;

state_tax = hours * rate * .0561;

return (state_tax);

}// calc_state_tax

public void setName(String name) {

this.name = name;

}

public String getName() {

return name;

}

public String getAddress() {

return address;

}

public double getHours() {

return hours;

}

public int getDependents() {

return dependents;

}

  

public double getRate(){

return rate;

}

  

public char getGender(){

return gender;

}

public String toString() {

return ("\n Name: " + name +

"\n Address: " + address +

"\n Hours: " + hours+

"\n Dependents " + dependents);

}// toString

}// Emprec

Related Solutions

I get errors in my merge method and Im not sure how to fix it to...
I get errors in my merge method and Im not sure how to fix it to make the code work public class OrderedApp1 { public static void main(String[] args) {    int maxSize = 100; // array size int searchKey = 55; OrdArray1 arr, a1, a2, a3; // reference to arrays arr = new OrdArray1(maxSize); // create the arrays a1 = new OrdArray1(maxSize); a2 = new OrdArray1(maxSize); a3 = new OrdArray1(maxSize);    //int a3[] =new int [ a1.length + a2.length];...
sort by the following (name, address, dependent and gender) of these fields and ask the user...
sort by the following (name, address, dependent and gender) of these fields and ask the user which field to sort by !. this mean the following java must sort by address if we need, by name , by dependent , and by gender it depend on the following java it must have an option which we need to sort. please i need your help now, you just add the sorting on the following java. // Use a custom comparator. import...
Im having issues with this project, I keep geting errors and idk why. here are the...
Im having issues with this project, I keep geting errors and idk why. here are the instructions for the project: "Create "simple integer calculator using the MARIE computer. The program should execute as follows: Using the INPUT instruction wait for the user to enter a decimal number. Using the INPUT instruction wait for the user to enter a second decimal number. Using the INPUT instruction wait for the user to enter the character +, - or *. Perform the desired...
Type I and Type II Errors . Please discuss Type I and Type II errors. What...
Type I and Type II Errors . Please discuss Type I and Type II errors. What are they? Discuss their relationship with hypothesis testing. Answer all parts of question!!! Do not plagiarize!! Write out the answer on here, don't post a picture of it! Answer must be long!
I need to add variables such as name, address and phone into a Jpanel in the...
I need to add variables such as name, address and phone into a Jpanel in the constructor called AddressBook. I then need to add that panel into a Jframe and call it in the main method how would i do that in java.
My code does not compile, I am using vim on terminal and got several compiling errors...
My code does not compile, I am using vim on terminal and got several compiling errors this is C++ language I need help fixing my code below is the example expected run and my code. Example run (User inputs are highlighted): Enter your monthly salary: 5000 Enter number of months you worked in the past year: 10 Enter the cost of the car: 36000 Enter number of cars you’ve sold in the past year: 30 Enter number of misconducts observed...
please read the scenario this is all I got that is provided by my professor If...
please read the scenario this is all I got that is provided by my professor If the initial cash in the US economy is $1 Trillion, individuals tend to keep one-sixth of their income as cash and deposit the rest, and banks can lend 90 percent of the deposit and reserve the remaining, then: a) What is the total money supply (M1) in this economy? (5 points) b) If the Federal Reserve wants to expand the money supply by five...
what is meant by Type I and Type II errors. Why are these important? Name one...
what is meant by Type I and Type II errors. Why are these important? Name one thing that can be done to improve internal validity of a study.
Java Searching and Sorting, please I need the Code and the Output. Write a method, remove,...
Java Searching and Sorting, please I need the Code and the Output. Write a method, remove, that takes three parameters: an array of integers, the length of the array, and an integer, say, removeItem. The method should find and delete the first occurrence of removeItem in the array. If the value does not exist or the array is empty, output an appropriate message. (After deleting an element, the number of elements in the array is reduced by 1.) Assume that...
please check my assignment for punctuation and grammatical errors. I really struggle with that. please copy...
please check my assignment for punctuation and grammatical errors. I really struggle with that. please copy and paste it and do the corrections for me. Currently, there are chronic shortages of transplantable human organs. Waiting lists are long, and many of those waiting die before an organ becomes available. Would it be more efficient than current arrangements if we were to allow an open market for buying and selling of human organs to develop? Be sure to consider how scarce...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT