import java.util.list;
import java.util.*;
public class PatientRecordSystem
{
private int PATIENTMAX = 100;
private int OBSERVATIONMAX = 50;
private int current = 1;
private int observationcurrent = 1;
// current = patients, observationcurrent = observations count
public PatientRecordSystem()
{
addPatient();
}
public void String addMeasurementObservationType()
{
}
public void String addCategoryObservationType()
{
}
public void String addPatient()
{
String PatientName = "James";
String PatientID = "10122";
}
public void String addMeasurementObservation()
{
// for patient
}
public void String addCategoryObservation()
{
// for patient
}
// no interactive inputs, all static details.
}
}
i'm unsure as to what is causing the error to appear as :
PatientRecordSystem.java:17: error: '(' expected
public void String addMeasurementObservationType()
^ PatientRecordSystem.java:22: error: '(' expected
public void String addCategoryObservationType()
^ PatientRecordSystem.java:27: error: '(' expected
public void String addPatient()
^ PatientRecordSystem.java:34: error: '(' expected
public void String addMeasurementObservation()
^ PatientRecordSystem.java:39: error: '(' expected
public void String addCategoryObservation()
The first issue is in your method declarations, you cannot declare your methods public void String
If your method returns nothing then it should be declared :
public void addMeasurementObservationType(){
// ...
}
If your method returns a String then it should be declared :
public String addMeasurementObservationType(){
return "the string to return";
}
The second one is that you are importing java.util.list;
You should import :
import java.util.List;
The third one is that you have an extra }
public void addCategoryObservation(){
// for patient
} <--- HERE
// no interactive inputs, all static details.
}
My guess is that your code should look like :
class PatientRecordSystem {
private int PATIENTMAX = 100;
private int OBSERVATIONMAX = 50;
private int current = 1;
private int observationcurrent = 1;
public PatientRecordSystem(){
addPatient();
}
public void addMeasurementObservationType(){
}
public void addCategoryObservationType(){
}
public void addPatient(){
String PatientName = "James";
String PatientID = "10122";
}
public void addMeasurementObservation(){
// for patient
}
public void addCategoryObservation(){
// for patient
// no interactive inputs, all static details.
}
}
you have something like this:
public void String addMeasurementObservationType()
{
}
and this is a contradiction/ makes no sense, your method should either return a String or just return nothing at all(void)
fix it by removing the String in the method return type
Example
public void addMeasurementObservationType()
{
}
and this apply for all the methods with the same error...
You can't have multiple return types. If you declare void as your return type you can't return anything... i have modified your code to return type as void. (change accordingly!) hope it helps...
public class PatientRecordSystem {
private int PATIENTMAX = 100;
private int OBSERVATIONMAX = 50;
private int current = 1;
private int observationcurrent = 1;
// current = patients, observationcurrent = observations count
public PatientRecordSystem() {
addPatient();
}
public void addMeasurementObservationType() {
}
public void addCategoryObservationType() {
}
public void addPatient() {
String PatientName = "James";
String PatientID = "10122";
}
public void addMeasurementObservation() {
// for patient
}
public void addCategoryObservation() {
// for patient
}
// no interactive inputs, all static details.
}
Related
I have the following problem. Five classes are interacting with each other. Two of theme are doing fine. But with the creating of an Object of one class (Ticket) in my main class Event (getting user input from another class (UserInput), an processing this in the costructor) i have now problem to display the results.
Main class Event with main methode
import java.util.ArrayList;
public class Event {
private static String artistName;
private static int artistSalary;
private Language language;
private static ArrayList<String> trackList;
private InputReader inputReader;
private Ticket ticket;
private int amountOfTicketCategories;
private static Object[] ticketList;
private static int index;
public Event() {
}
public Event(Artist artist, Ticket ticket) {
artistName = artist.getArtistName();
artistSalary = artist.getArtistSalary();
trackList = artist.getArrayList();
for (index = 0; index < amountOfTicketCategories; index++) {
ticketList[index] = ticket.getTicket();
ticketList[index].toString();
}
}
public void chooseWhatToDefine() {
language = new Language();
language.whatToSpecify();
}
public void setTicketPrice(String ticketCategory, int ticketPrice) {
}
public void displayArtist(String artistName, int artistSalary) {
language = new Language();
language.displayArtistAndSalary(artistName, artistSalary);
}
public void displayTracklist(ArrayList<String> trackList) {
language = new Language();
language.displayTrackList(trackList);
}
public void displayTickets(Object[] ticketList) {
language = new Language();
language.displayTicket(ticketList);
}
public static void main(String[] args) {
Event event1 = new Event(new Artist(), new Ticket());
event1.displayArtist(artistName, artistSalary);
event1.displayTracklist(trackList);
event1.displayTickets(ticketList);
}
}
Ticket class with constructor that initalize the class with the user input comming from the InputReader class, and creates an object of Strings and Integers.
import java.util.Arrays;
public class Ticket {
private static String ticketCategory;
private static int ticketAmount;
private static int ticketPrice;
private InputReader inputReader;
private int amountOfTicketCategories;
private int index;
private Ticket[] ticketList;
public Ticket(String ticketCategory,int ticketAmount,int ticketPrice) {
}
public Ticket() {
inputReader = new InputReader();
inputReader.specifyTicketCategories();
ticketList = new Ticket[amountOfTicketCategories];
for (index = 0; index < amountOfTicketCategories; index++) {
inputReader.specifyTicket(ticketCategory, ticketAmount, ticketPrice);
ticketList[index] = new Ticket(ticketCategory, ticketAmount, ticketPrice);
}
}
public String toString() {
return("TicketCategory: " + ticketCategory + "Amount of Tickets: " + ticketAmount + "Ticket Price: " +ticketPrice);
}
public Object getTicket() {
return ticketList[index];
}
public int getAmountOfTicketCategories() {
amountOfTicketCategories = inputReader.specifyTicketCategories();
return amountOfTicketCategories;
}
}
InptReader class that processes the user input:
import java.util.ArrayList;
import java.util.Scanner;
public class InputReader {
private Scanner sc;
private Language language;
private ArrayList <String> tracks;
public InputReader() {
tracks = new ArrayList<String>();
language = new Language();
sc = new Scanner(System.in);
}
public int specifyTicketCategories() {
language.defineAmountOfTicketCategories();
return sc.nextInt();
}
public void specifyTicket(String ticketCategory, int ticketAmount, int ticketPrice) {
language.specifyTicketCategory();
ticketCategory = sc.next();
language.specifyTicketAmount();
ticketAmount = sc.nextInt();
language.specifyTicketPrice();
ticketPrice = sc.nextInt();
}
public int amountOfTickets() {
return sc.nextInt();
}
public int ticketPrice() {
return sc.nextInt();
}
public String readName() {
language.specifyArtist();
return sc.nextLine();
}
public int readInteger() {
language.specifyArtistSalary();
return sc.nextInt();
}
public void addTitle() {
int anzahlSongs = 3;
int index = 0;
while (index < anzahlSongs) {
language.specifyTrackList();
tracks.add(sc.nextLine());
index++;
}
}
public ArrayList<String> getArray() {
return tracks;
}
}
Language class that consists of the language statements
import java.util.ArrayList;
public class Language {
public Language () {
}
public void whatToSpecify() {
System.out.println("What would you like to specify fist? For Artist press 1, for Ticket press 2");
}
public void specifyArtist() {
System.out.println("Who is the artist? ");
}
public void specifyArtistSalary() {
System.out.println("How much does the artist earn? ");
}
public void displayTicket(Object[] ticketList) {
System.out.println("Ticketlist: " + ticketList);
}
public void displayArtistAndSalary(String artistName, int artistSalary) {
System.out.println("Artist: " + artistName + " " + "Salary: " + artistSalary);
}
public void displayTrackList(ArrayList<String> trackList) {
System.out.println("Tracklist: " + trackList);
}
public void specifyTicketCategory() {
System.out.println("What is the ticket category? ");
}
public void specifyTicketAmount() {
System.out.println("What ist the amount of tickets? ");
}
public void specifyTicketPrice() {
System.out.println("What is the price for your ticket?");
}
public void specifyTrackList() {
System.out.println("Add title: ");
}
public void defineAmountOfTicketCategories() {
System.out.println("How many ticket categories you like to set up?");
}
public void line() {
System.out.println("***********************************");
}
}
Artist class that that has creates an instance of an artist in the main class (same idea as for ticket) but with other variables and parameters.
import java.util.ArrayList;
public class Artist {
private int artistSalary;
private String artistName;
private InputReader inputReader;
ArrayList <String> trackList;
public Artist() {
inputReader = new InputReader();
artistName = inputReader.readName();
artistSalary = inputReader.readInteger();
inputReader.addTitle();
trackList = inputReader.getArray();
trackList.remove(2);
}
public String getArtistName() {
return artistName;
}
public int getArtistSalary() {
return artistSalary;
}
public ArrayList<String> getArrayList(){
return trackList;
}
}
Output in the console:
Add title:
Hello
Add title:
Hello
How many ticket categories you like to set up?
5
Artist: David Salary: 5000
Tracklist: [, Hello]
Ticketlist: null
First of all, in the Ticket class's constructor, you use the other constructor (The one with the 3 arguments), which has an empty body.
ticketList[index] = new Ticket(ticketCategory, ticketAmount, ticketPrice);
public Ticket(String ticketCategory,int ticketAmount,int ticketPrice) {
//this is empty
}
That means you're creating an object with.. nothing in it (null variables).
Try this:
public Ticket(String ticketCategory,int ticketAmount,int ticketPrice) {
this.ticketCategory = ticketCategory;
this.ticketAmount = ticketAmount;
this.ticketPrice = ticketPrice;
}
Then, your getTicket method is wrong. You never define the "index" integer in your Ticket class.
public Object getTicket() {
return ticketList[index];
}
Where "index" is undefined.
The ticketList should not be in the Ticket class => each time you create a Ticket instance, it will probably not be the same as the previous one.
I understand that I do not have anything in my main method yet so nothing will execute, that is the second part to the assignment.
My question is, I'm getting an error in the computeDiscount method where I'm calling the computeNumCases method. The error i'm getting is
variable numCases might not have been initialized
so I need help figuring that error out.
Also, help in the computeCost method would be very helpful as well.
public class Customer {
private String customerLastName;
private String candyType;
private int numCandyBars;
private double costPerBar;
private int NUMBERPERCASE = 12;
public static void main(String[] args) {
}
public Customer() {
}
public Customer(String name, String type, int numCandyBars, double costPerBar) {
//this.name = name;
candyType = type;
this.numCandyBars = numCandyBars;
this.costPerBar = costPerBar;
}
public static double getCostPerBar(double costPerBar) {
return costPerBar;
}
public static int getNumCandyBars(int numCandyBars) {
return numCandyBars;
}
public String getCandyType() {
return candyType;
}
public String GetCustomerLastName() {
return customerLastName;
}
public void setCustomerLastName(String name) {
this.customerLastName = name;
}
public void setNumCandyBars(int num) {
this.numCandyBars = num;
}
public void setCandyType(String candyType) {
this.candyType = candyType;
}
public void setCostPerBar(double cost) {
costPerBar = cost;
}
public int computeNumCases(int numCases) {
numCases = numCandyBars / NUMBERPERCASE;
return numCases;
}
public int computeNumIndividuals(int numIndividuals) {
numIndividuals = numCandyBars % NUMBERPERCASE;
return numIndividuals;
}
public int computeDiscount(int discount) {
int numCases = computeNumCases(numCases);
if (numCases < 20)
discount = 100;
else if (numCases < 50)
discount = 85;
else
discount = 75;
return discount;
}
public double computeCost(double totalCost) {
return computeNumCases(numCases) * getCostPerBar(costPerBar) * (NUMBERPERCASE * discount / 100.00) + computeNumIndividuals(numIndividuals) * getCostPerBar(costPerBar);
}
}
I am still new to Android, I'm primarily an iOS developer.
I don't know why I can't test to see whether or not the ListArray is empty or not. I need to test and use the size of it anyways.
This is declared within the class:
Projects projects = new Projects();
The following code does not like projects.videos.size() being compared nil or 0.
try
{
if (projects != null)
{
int numberOfVideos = projects.videos.size();
if(numberOfVideos==0)
{
// myStringArray = new String[projects.videos.size()];
//
//
//
// for (int i = 0;i < projects.videos.size();i++)
// {
// myStringArray[i] = projects.videos.get(i);
// }
}
else
{
// myStringArray = new String[1];
// myStringArray[0] = "No projects";
}
}
else
{
System.out.println("Sucess");
}
}
catch (Exception e)
{
System.out.println(e);
System.out.println("somethingbad has happened");
System.out.println(projects.videos.size());
}
This is what the projects class looks like:
package com.example.musicvideomaker;
import java.util.ArrayList;
import java.util.UUID;
import java.io.Serializable;
#SuppressWarnings("serial")
public class Projects implements Serializable{
public String projectName;
public String musicStuff;
public String songTitle;
public String guid;
public boolean isBuiltVideo;
public boolean isListOfBuiltVideos;
public int selectedIndex;
public ArrayList<String> videos;
public ArrayList<String> builtVideos;
public ArrayList<Number> tPoints;
public void setProjectName(String projectName)
{
this.projectName = projectName;
}
public void setMusicStuff(String musicStuff)
{
this.musicStuff = musicStuff;
}
public void setSongTitle(String songTitle)
{
this.songTitle = songTitle;
}
public void setGuid()
{
UUID uuid = UUID.randomUUID();
this.guid = uuid.toString();
}
public void isBuiltVideo(boolean isBuiltVideo)
{
this.isBuiltVideo = isBuiltVideo;
}
public void isListOfBuiltVideos(boolean isListOfBuiltVideos)
{
this.isListOfBuiltVideos = isListOfBuiltVideos;
}
public void setSelectedIndex(int selectedIndex)
{
this.selectedIndex = selectedIndex;
}
public void addRecordedVideo(String recordedVideo)
{
this.videos.add(recordedVideo);
}
public void addBuiltVideo(String builtVideo)
{
this.builtVideos.add(builtVideo);
}
public void addTPoint(Number tPoint)
{
this.tPoints.add(tPoint);
}
}
I removed int numberOfVideos = projects.videos.size();
Instead of using if(numberOfVideos==0) I used projects.videos == null
I think it was because my projects are null so it crashes when trying to pull the size of the arrayList.
I am working in an android application I want to sort a List of Objects with an Object Property. I have sorted it successfully but when I sort it all the List with that object changes the value to same as the sorted value
Please look into ma code :
SortedSet<Caseload> removeDuplicateClientName = new TreeSet<Caseload>(
new Comparator<Caseload>() {
#Override
public int compare(Caseload caseload0, Caseload caseload1) {
return caseload0.ClientName.compareTo(caseload1.ClientName);
}
});
// Getting the list of values from web service
mLISTCaseloadsHeads = parsedXML.getCaseLoadValues("get_Caseload_ClientServiceGroupID", param);
List<Caseload> newBackUp=mLISTCaseloadsHeads ;
Iterator<Caseload> iterator = mCaseloadsHeads.iterator();
while (iterator.hasNext()) {
removeDuplicateClientName.add(iterator.next());
}
mCaseloadsHeads.clear();
mCaseloadsHeads.addAll(removeDuplicateClientName);
The List newBackUp also changes the value to the same as sorted List
Caseload class:
public class Caseload implements Comparable<Caseload> {
public int BusClientLogID;
public int ClientID;
public int ClientStatus;
public int ClientServiceGroup_ClientSiteTherapyID;
public String ClientName;
public String TimeArrive;
public String TimeDepart;
public String SignOutTime;
public String SignInTime;
public String ServiceCompletedCount;
public Boolean ShowFooter = false;
public int getBusClientLogID() {
return BusClientLogID;
}
public void setBusClientLogID(int busClientLogID) {
BusClientLogID = busClientLogID;
}
public int getClientID() {
return ClientID;
}
public void setClientID(int clientID) {
ClientID = clientID;
}
public int getClientStatus() {
return ClientStatus;
}
public void setClientStatus(int clientStatus) {
ClientStatus = clientStatus;
}
public int getClientServiceGroup_ClientSiteTherapyID() {
return ClientServiceGroup_ClientSiteTherapyID;
}
public void setClientServiceGroup_ClientSiteTherapyID(
int clientServiceGroup_ClientSiteTherapyID) {
ClientServiceGroup_ClientSiteTherapyID = clientServiceGroup_ClientSiteTherapyID;
}
public String getClientName() {
return ClientName;
}
public void setClientName(String clientName) {
ClientName = clientName;
}
public String getTimeArrive() {
return TimeArrive;
}
public void setTimeArrive(String timeArrive) {
TimeArrive = timeArrive;
}
public String getTimeDepart() {
return TimeDepart;
}
public void setTimeDepart(String timeDepart) {
TimeDepart = timeDepart;
}
public String getSignOutTime() {
return SignOutTime;
}
public void setSignOutTime(String signOutTime) {
SignOutTime = signOutTime;
}
public String getSignInTime() {
return SignInTime;
}
public void setSignInTime(String signInTime) {
SignInTime = signInTime;
}
public String getServiceCompletedCount() {
return ServiceCompletedCount;
}
public void setServiceCompletedCount(String serviceCompletedCount) {
ServiceCompletedCount = serviceCompletedCount;
}
#Override
public int compareTo(Caseload compareCaseload) {
int busClientLogID = ((Caseload) compareCaseload).getBusClientLogID();
return busClientLogID - this.BusClientLogID;
}
}
Please give me a solution.
I doubt the return statement associated with your compare function in the comparator.
You should go by this approach to get the right ordering :
#Override
public int compare(YourClass lhs, YourClass rhs) {
YourClass p1 = (YourClass) lhs;
YourClass p2 = (YourClass) rhs;
int first = p1.ClientName; //use your getter if you want
int second = p2.ClientName;
if (second < first) {
return 1;
}
else if (second > first) {
return -1;
}
else {
return 0;
}
}
If you go by this approach I guess you will get the required ordering after sort.
Edit:
Now I have got the issue, you are using a reference of the original list in newBackup and its not a new list that is why this is happening, use this and you are good to go.
List<Caseload> newBackUp=new ArrayList<Caseload>(mLISTCaseloadsHeads);
I am using following query
String queryString = "select NEW com.h.offering.dto.SellerDetailsDto(p.productId,p.sellerId, p.sellerSku, p.sellPrice, " +
"p.transferPrice, p.sellerMRP,p.aCommission,p.baseShippingFee,p.addnShippingFee, " +
"p.propogationLevel,p.propogationValue,a.warehouseName,a.quantity,a.maxShippingTime,a.minShippingTime) "
+ "from PriceDetails p, AvailabilityDetails a "
+ "where a.productId = p.productId "
+ "and a.sellerSku = p.sellerSku "
+ "and a.sellerId = :sellerId";
while executing i am getting error
org.hibernate.hql.ast.QuerySyntaxException: Unable to locate appropriate constructor on class [com.a.offering.dto.SellerDetailsDto] [select NEW com.s.offering.dto.SellerDetailsDto(p.productId) from com.a.offering.db.domain.PriceDetails p, com.a.offering.db.domain.AvailabilityDetails a where a.productId = p.productId and a.sellerSku = p.sellerSku and a.sellerId = :sellerId]
at org.hibernate.hql.ast.QuerySyntaxException.convert(QuerySyntaxException.java:54)
at org.hibernate.hql.ast.QuerySyntaxException.convert(QuerySyntaxException.java:47)
at org.hibernate.hql.ast.ErrorCounter.throwQueryException(ErrorCounter.java:82)
at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:261)
at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:185)
at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:136)
and so on...
I am unable to figure out the error. Help me out
The code for SellerDetailsDto.java is
package com.a.offering.dto;
public class SellerDetailsDto {
public String productId;
public String sellerId;
public String sellerSku;
public Double sellPrice;
public Double transferPrice;
public Double sellerMRP;
public Double a;
public Double baseShippingFee;
public Double addnShippingFee;
public String propogationLevel;
public String propogationValue;
public String warehouseName;
public int quantity;
public int maxShippingTime;
public int minShippingTime;
public String getProductId() {
return productId;
}
public void setProductId(String productId) {
this.productId = productId;
}
public String getSellerId() {
return sellerId;
}
public void setSellerId(String sellerId) {
this.sellerId = sellerId;
}
public String getSellerSku() {
return sellerSku;
}
public void setSellerSku(String sellerSku) {
this.sellerSku = sellerSku;
}
public String getWarehouseName() {
return warehouseName;
}
public void setWarehouseName(String warehouseName) {
this.warehouseName = warehouseName;
}
public int getQuantity() {
return quantity;
}
public void setQuantity(int quantity) {
this.quantity = quantity;
}
public int getMaxShippingTime() {
return maxShippingTime;
}
public void setMaxShippingTime(int maxShippingTime) {
this.maxShippingTime = maxShippingTime;
}
public int getMinShippingTime() {
return minShippingTime;
}
public void setMinShippingTime(int minShippingTime) {
this.minShippingTime = minShippingTime;
}
public Double getSellPrice() {
return sellPrice;
}
public void setSellPrice(Double sellPrice) {
this.sellPrice = sellPrice;
}
public Double getTransferPrice() {
return transferPrice;
}
public void setTransferPrice(Double transferPrice) {
this.transferPrice = transferPrice;
}
public Double getSellerMRP() {
return sellerMRP;
}
public void setSellerMRP(Double sellerMRP) {
this.sellerMRP = sellerMRP;
}
public Double a() {
return a;
}
public void a(Double aa) {
a }
public Double getBaseShippingFee() {
return baseShippingFee;
}
public void setBaseShippingFee(Double baseShippingFee) {
this.baseShippingFee = baseShippingFee;
}
public Double getAddnShippingFee() {
return addnShippingFee;
}
public void setAddnShippingFee(Double addnShippingFee) {
this.addnShippingFee = addnShippingFee;
}
public String getPropogationLevel() {
return propogationLevel;
}
public void setPropogationLevel(String propogationLevel) {
this.propogationLevel = propogationLevel;
}
public String getPropogationValue() {
return propogationValue;
}
public void setPropogationValue(String propogationValue) {
this.propogationValue = propogationValue;
}
}
Hibernate needs a constructor with at least package private (i. e. default) visibility.
Normally a parameterless constructor is necessary (which you implicitly have), but for your select new ... SellerDetailsDto needs a constructor with the 15 parameters which you give in the select statement. (Thought the error message demands a constructor with only the id as a parameter - it looks like if the error is coming from a different select new statement.) You don't have such a constructor.
The problem is that you don't have a constructor in SellerDetailsDto that accepts the parameters that you are passing in the hql query. Add this constructor to your class:
public SellerDetailsDto(String productId, String sellerId,
String sellerSku, Double sellPrice, Double transferPrice,
Double sellerMRP, Double tradusCommission, Double baseShippingFee,
Double addnShippingFee, String propogationLevel,
String propogationValue, String warehouseName, int quantity,
int maxShippingTime, int minShippingTime) {
this.productId = productId;
this.sellerId = sellerId;
this.sellerSku = sellerSku;
this.sellPrice = sellPrice;
this.transferPrice = transferPrice;
this.sellerMRP = sellerMRP;
this.tradusCommission = tradusCommission;
this.baseShippingFee = baseShippingFee;
this.addnShippingFee = addnShippingFee;
this.propogationLevel = propogationLevel;
this.propogationValue = propogationValue;
this.warehouseName = warehouseName;
this.quantity = quantity;
this.maxShippingTime = maxShippingTime;
this.minShippingTime = minShippingTime;
}
This could make some other code you have to stop working, because now there wont' be a default constructor available. To fix that, add a default constructor too:
public SellerDetailsDto() {}
Actually this is problem on your root pom file. You want install lombok in your IDE & add dependency of lombok in root pom file I hope it will work